Cheetah
ChWsbCalendar.php
Go to the documentation of this file.
1 <?php
2 
49 {
52 
54  {
55  $aMonths = array (
56  1 => '_January',
57  2 => '_February',
58  3 => '_March',
59  4 => '_April',
60  5 => '_May',
61  6 => '_June',
62  7 => '_July',
63  8 => '_August',
64  9 => '_September',
65  10 => '_October',
66  11 => '_November',
67  12 => '_December',
68  );
69 
70  // input values
71  $this->iYear = (int)$iYear ? (int)$iYear : date('Y');
72  $this->iMonth = (int)$iMonth ? (int)$iMonth : date('m');
73  $this->iDay = date('d');
74 
75  $this->sMonthName = _t($aMonths[(int)$this->iMonth]);
76 
77  $this->iNumDaysInMonth = date('t', mktime(0, 0, 0, $this->iMonth+1, $iDay, $this->iYear));
78  $this->iFirstWeekDay = (int)date('w', mktime(0, 0, 0, $this->iMonth, 1, $this->iYear));
79 
80  // previous month year, month
81  $this->iPrevYear = $this->iYear;
82  $this->iPrevMonth = $this->iMonth - 1;
83  if ( $this->iPrevMonth <= 0 ) {
84  $this->iPrevMonth = 12;
85  $this->iPrevYear--;
86  }
87  // next month year, month
88  $this->iNextYear = $this->iYear;
89  $this->iNextMonth = $this->iMonth + 1;
90  if ( $this->iNextMonth > 12 ) {
91  $this->iNextMonth = 1;
92  $this->iNextYear++;
93  }
94 
95  // week config
96  list ($this->iWeekStart, $this->iWeekEnd) = (getParam('sys_calendar_starts_sunday') == 'on') ? array (0, 7) : array (1, 8);
97  if ($this->iFirstWeekDay < $this->iWeekStart)
98  $this->iFirstWeekDay = $this->iWeekEnd-1;
99  }
100 
101  function _getWeekNames ($isMiniMode = false)
102  {
103  $sPostfix = '';
104  if ($isMiniMode)
105  $sPostfix = '_mini';
106  if(0 == $this->iWeekStart)
107  $aWeek[] = array('name' => _t('_week_sun' . $sPostfix));
108  $aWeek[] = array('name' => _t('_week_mon' . $sPostfix));
109  $aWeek[] = array('name' => _t('_week_tue' . $sPostfix));
110  $aWeek[] = array('name' => _t('_week_wed' . $sPostfix));
111  $aWeek[] = array('name' => _t('_week_thu' . $sPostfix));
112  $aWeek[] = array('name' => _t('_week_fri' . $sPostfix));
113  $aWeek[] = array('name' => _t('_week_sat' . $sPostfix));
114  if(8 == $this->iWeekEnd)
115  $aWeek[] = array('name' => _t('_week_sun' . $sPostfix));
116  return $aWeek;
117  }
118 
119  function _getCalendarGrid (&$aCalendarGrid)
120  {
121  // fill calendar with events
122  $aEvents = $this->getData();
123  $aCalendar = array ();
124 
125  foreach ($aEvents as $a) {
126  $aCalendar[$a['Day']] += 1;//array('unit' => $this->getUnit($a));
127  }
128 
129  // make calendar grid
130  $aCalendarGrid = array ();
131  $iCurrentDay = 0;
132  for ($i = 0; $i < 6; $i++) {
133  for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
134  if ($this->iFirstWeekDay == $j || $i > 0 || $iCurrentDay > 0) {
135  ++$iCurrentDay;
136  if ($iCurrentDay > $this->iNumDaysInMonth) break 2;
137  $aCalendarGrid[$i][$j]['day'] = $iCurrentDay;
138  $aCalendarGrid[$i][$j]['today'] = ($this->iYear == date('Y') && $this->iMonth == date('m') && $iCurrentDay == $this->iDay);
139  $aCalendarGrid[$i][$j]['num'] = isset($aCalendar[$iCurrentDay]) && $aCalendar[$iCurrentDay] > 0 ? $aCalendar[$iCurrentDay] : '';
140  }
141  }
142  }
143  }
144 
145  function _getCalendar ()
146  {
147  $sBrowseUri = $this->getBrowseUri();
148  list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames ();
149 
150  $this->_getCalendarGrid($aCalendarGrid);
151  $aRet = array ();
152  for ($i = 0; $i < 6; $i++) {
153 
154  $aRow = array ('ch_repeat:cell');
155  $isRowEmpty = true;
156 
157  for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
158 
159  $aCell = array ();
160 
161  if ($aCalendarGrid[$i][$j]['today']) {
162  $aCell['class'] = 'sys_cal_cell sys_cal_today';
163  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
164  $aCell['ch_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
165  'num' => $aCalendarGrid[$i][$j]['num'],
166  'href' => $sBrowseUri . $this->iYear . '/' . $this->iMonth . '/' . $aCell['day'],
167  'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
168  ));
169  $isRowEmpty = false;
170  } elseif (isset($aCalendarGrid[$i][$j]['day'])) {
171  $aCell['class'] = 'sys_cal_cell';
172  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
173  $aCell['ch_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
174  'num' => $aCalendarGrid[$i][$j]['num'],
175  'href' => $sBrowseUri . $this->iYear . '/' . $this->iMonth . '/' . $aCell['day'],
176  'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
177  ));
178  $isRowEmpty = false;
179  } else {
180  $aCell['class'] = 'sys_cal_cell_blank';
181  $aCell['day'] = '';
182  $aCell['ch_if:num'] = array ('condition' => false, 'content' => array(
183  'num' => '',
184  'href' => '',
185  'entries' => '',
186  ));
187  }
188 
189  if ($aCell)
190  $aRow['ch_repeat:cell'][] = $aCell;
191  }
192 
193  if ($aRow['ch_repeat:cell'] && !$isRowEmpty) {
194  $aRet[] = $aRow;
195  }
196  }
197  return $aRet;
198  }
199 
200  function getTitle ()
201  {
202  return $this->sMonthName . ', ' . $this->iYear;
203  }
204 
205 
206  // override function below to implement your own calendar
207 
221  function getData ()
222  {
223  // override this func
224  return array();
225  }
226 
234  function getUnit (&$aData)
235  {
236  // override this func
237  return '';
238  }
239 
246  function getBaseUri ()
247  {
248  // override this func
249  return CH_WSB_URL_ROOT;
250  }
251 
258  function getBrowseUri ()
259  {
260  // override this func
261  return '';
262  }
263 
268  function getEntriesNames ()
269  {
270  // override this func
271  return array(_t('_item'), _t('_items'));
272  }
273 
277  function getMonthUrl ($isNextMoths, $isMiniMode = false)
278  {
279  return $this->getBaseUri () . ($isNextMoths ? "{$this->iNextYear}/{$this->iNextMonth}" : "{$this->iPrevYear}/{$this->iPrevMonth}");
280  }
281 }
ChWsbCalendar\$iNumDaysInMonth
$iNumDaysInMonth
Definition: ChWsbCalendar.php:51
ChWsbCalendar\$sMonthName
$sMonthName
Definition: ChWsbCalendar.php:51
ChWsbCalendar\$iWeekStart
$iWeekStart
Definition: ChWsbCalendar.php:51
ChWsbCalendar\$iMonth
$iMonth
Definition: ChWsbCalendar.php:50
ChWsbCalendar\$iNextMonth
$iNextMonth
Definition: ChWsbCalendar.php:50
ChWsbCalendar\$iPrevYear
$iPrevYear
Definition: ChWsbCalendar.php:50
ChWsbCalendar\_getWeekNames
_getWeekNames($isMiniMode=false)
Definition: ChWsbCalendar.php:101
ChWsbCalendar\_getCalendarGrid
_getCalendarGrid(&$aCalendarGrid)
Definition: ChWsbCalendar.php:119
php
ChWsbCalendar\_getCalendar
_getCalendar()
Definition: ChWsbCalendar.php:145
ChWsbCalendar\getData
getData()
Definition: ChWsbCalendar.php:221
ChWsbCalendar\$iPrevMonth
$iPrevMonth
Definition: ChWsbCalendar.php:50
ChWsbCalendar\getTitle
getTitle()
Definition: ChWsbCalendar.php:200
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbCalendar\$iNextYear
$iNextYear
Definition: ChWsbCalendar.php:50
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbCalendar\$iFirstWeekDay
$iFirstWeekDay
Definition: ChWsbCalendar.php:51
ChWsbCalendar\getMonthUrl
getMonthUrl($isNextMoths, $isMiniMode=false)
Definition: ChWsbCalendar.php:277
ChWsbCalendar\__construct
__construct($iYear, $iMonth)
Definition: ChWsbCalendar.php:53
ChWsbCalendar
Definition: ChWsbCalendar.php:49
ChWsbCalendar\getBaseUri
getBaseUri()
Definition: ChWsbCalendar.php:246
ChWsbCalendar\$iWeekEnd
$iWeekEnd
Definition: ChWsbCalendar.php:51
ChWsbCalendar\getBrowseUri
getBrowseUri()
Definition: ChWsbCalendar.php:258
ChWsbCalendar\getUnit
getUnit(&$aData)
Definition: ChWsbCalendar.php:234
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbCalendar\$iYear
$iYear
Definition: ChWsbCalendar.php:50
ChWsbCalendar\getEntriesNames
getEntriesNames()
Definition: ChWsbCalendar.php:268