Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phortune / control / PhortuneMonthYearExpiryControl.php
blob73f26bc26d89571840cdef0ad4daf69ca9540ea8
1 <?php
3 final class PhortuneMonthYearExpiryControl extends AphrontFormControl {
4 private $monthValue;
5 private $yearValue;
7 public function setMonthInputValue($value) {
8 $this->monthValue = $value;
9 return $this;
11 private function getMonthInputValue() {
12 return $this->monthValue;
14 private function getCurrentMonth() {
15 return phabricator_format_local_time(
16 time(),
17 $this->getUser(),
18 'm');
21 public function setYearInputValue($value) {
22 $this->yearValue = $value;
23 return $this;
25 private function getYearInputValue() {
26 return $this->yearValue;
28 private function getCurrentYear() {
29 return phabricator_format_local_time(
30 time(),
31 $this->getUser(),
32 'Y');
35 protected function getCustomControlClass() {
36 return 'aphront-form-control-text';
39 protected function renderInput() {
40 if (!$this->getUser()) {
41 throw new PhutilInvalidStateException('setUser');
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',
60 $current_year = $this->getCurrentYear();
61 $years = range($current_year, $current_year + 20);
62 $years = array_fuse($years);
64 if ($this->getMonthInputValue()) {
65 $selected_month = $this->getMonthInputValue();
66 } else {
67 $selected_month = $this->getCurrentMonth();
69 $months_sel = AphrontFormSelectControl::renderSelectTag(
70 $selected_month,
71 $months,
72 array(
73 'sigil' => 'month-input',
74 ));
76 $years_sel = AphrontFormSelectControl::renderSelectTag(
77 $this->getYearInputValue(),
78 $years,
79 array(
80 'sigil' => 'year-input',
81 ));
83 return hsprintf('%s%s', $months_sel, $years_sel);