[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhortuneMonthYearExpiryControl extends AphrontFormControl { 4 private $monthValue; 5 private $yearValue; 6 7 public function setMonthInputValue($value) { 8 $this->monthValue = $value; 9 return $this; 10 } 11 private function getMonthInputValue() { 12 return $this->monthValue; 13 } 14 private function getCurrentMonth() { 15 return phabricator_format_local_time( 16 time(), 17 $this->getUser(), 18 'm'); 19 } 20 21 public function setYearInputValue($value) { 22 $this->yearValue = $value; 23 return $this; 24 } 25 private function getYearInputValue() { 26 return $this->yearValue; 27 } 28 private function getCurrentYear() { 29 return phabricator_format_local_time( 30 time(), 31 $this->getUser(), 32 'Y'); 33 } 34 35 protected function getCustomControlClass() { 36 return 'aphront-form-control-text'; 37 } 38 39 protected function renderInput() { 40 if (!$this->getUser()) { 41 throw new Exception('You must setUser() before render()!'); 42 } 43 44 // represent months like a credit card does 45 $months = array( 46 '01' => '01', 47 '02' => '02', 48 '03' => '03', 49 '04' => '04', 50 '05' => '05', 51 '06' => '06', 52 '07' => '07', 53 '08' => '08', 54 '09' => '09', 55 '10' => '10', 56 '11' => '11', 57 '12' => '12', 58 ); 59 60 $current_year = $this->getCurrentYear(); 61 $years = range($current_year, $current_year + 20); 62 $years = array_fuse($years); 63 64 if ($this->getMonthInputValue()) { 65 $selected_month = $this->getMonthInputValue(); 66 } else { 67 $selected_month = $this->getCurrentMonth(); 68 } 69 $months_sel = AphrontFormSelectControl::renderSelectTag( 70 $selected_month, 71 $months, 72 array( 73 'sigil' => 'month-input', 74 )); 75 76 $years_sel = AphrontFormSelectControl::renderSelectTag( 77 $this->getYearInputValue(), 78 $years, 79 array( 80 'sigil' => 'year-input', 81 )); 82 83 return hsprintf('%s%s', $months_sel, $years_sel); 84 } 85 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |