1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15:
16: class Horde_Date_Repeater_MonthName extends Horde_Date_Repeater
17: {
18: public $currentMonthStart;
19: public $type;
20:
21: public function __construct($type)
22: {
23: $this->type = $type;
24: }
25:
26: public function next($pointer = 'future')
27: {
28: parent::next($pointer);
29:
30: if (!$this->currentMonthStart) {
31: $targetMonth = $this->_monthNumber($this->type);
32: switch ($pointer) {
33: case 'future':
34: if ($this->now->month < $targetMonth) {
35: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
36: } else {
37: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
38: }
39: break;
40:
41: case 'none':
42: if ($this->now->month <= $targetMonth) {
43: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
44: } else {
45: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year + 1, 'month' => $targetMonth, 'day' => 1));
46: }
47: break;
48:
49: case 'past':
50: if ($this->now->month > $targetMonth) {
51: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year, 'month' => $targetMonth, 'day' => 1));
52: } else {
53: $this->currentMonthStart = new Horde_Date(array('year' => $this->now->year - 1, 'month' => $targetMonth, 'day' => 1));
54: }
55: break;
56: }
57: } else {
58: switch ($pointer) {
59: case 'future':
60: $this->currentMonthStart->year++;
61: break;
62:
63: case 'past':
64: $this->currentMonthStart->year--;
65: break;
66: }
67: }
68:
69: return new Horde_Date_Span($this->currentMonthStart, $this->currentMonthStart->add(array('month' => 1)));
70: }
71:
72: public function this($pointer = 'future')
73: {
74: parent::this($pointer);
75:
76: switch ($pointer) {
77: case 'past':
78: return $this->next($pointer);
79:
80: case 'future':
81: case 'none':
82: return $this->next('none');
83: }
84: }
85:
86: public function width()
87: {
88: return Horde_Date_Repeater_Month::MONTH_SECONDS;
89: }
90:
91: public function index()
92: {
93: return $this->_monthNumber($this->type);
94: }
95:
96: public function __toString()
97: {
98: return parent::__toString() . '-monthname-' . $this->type;
99: }
100:
101: protected function _monthNumber($monthName)
102: {
103: $months = array(
104: 'january' => 1,
105: 'february' => 2,
106: 'march' => 3,
107: 'april' => 4,
108: 'may' => 5,
109: 'june' => 6,
110: 'july' => 7,
111: 'august' => 8,
112: 'september' => 9,
113: 'october' => 10,
114: 'november' => 11,
115: 'december' => 12,
116: );
117: if (!isset($months[$monthName])) {
118: throw new InvalidArgumentException('Invalid month name "' . $monthName . '"');
119: }
120: return $months[$monthName];
121: }
122:
123: }