PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/alaxos/controllers/components/alaxos_calendar.php

https://github.com/zpartakov/pmCake
PHP | 784 lines | 581 code | 140 blank | 63 comment | 98 complexity | e71be2c5762e0f13dd4dfc958a9b6cff MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /**
  3. *
  4. * @author Nicolas Rod <nico@alaxos.com>
  5. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  6. * @link http://www.alaxos.ch
  7. */
  8. class AlaxosCalendarComponent extends Object
  9. {
  10. var $components = array('Session');
  11. const DISPLAY_MODE_MONTH = 'month';
  12. const DISPLAY_MODE_WEEK = 'week';
  13. const DISPLAY_MODE_WEEK_HOUR = 'week_with_hours';
  14. const DISPLAY_MODE_DAY = 'day';
  15. const DISPLAY_MODE_DAY_HOUR = 'day_with_hours';
  16. const NAVIG_MODE_AJAX = 'ajax';
  17. const NAVIG_MODE_URL = 'url';
  18. const NAVIG_DATE_LINK = false;
  19. const PARAM_CURRENT_DATE = 'date_to_show';
  20. const PARAM_CURRENT_DATE_FORMAT = 'Y-m-d';
  21. private $display_mode;
  22. private $navigation_mode;
  23. private $date_link;
  24. private $hide_other_months_dates = false;
  25. private $display_day_names = true;
  26. private $week_day_header_format = '%A %d %B';
  27. private $month_day_header_format = '%A';
  28. private $day_day_header_format = '%A %d %B';
  29. private $next_event_info;
  30. private $previous_event_info;
  31. private $hour_start;
  32. private $hour_end;
  33. /**
  34. * The step of the time to display in the view in hour (eg: 0.5 -> 30 minutes)
  35. * @var decimal
  36. */
  37. private $hour_interval;
  38. /**
  39. * Name of the calendar instance.
  40. * Used to store the last selected date in session in order to differentiate different calendars
  41. *
  42. * @var string
  43. */
  44. private $calendar_instance_name = 'alaxos_calendar';
  45. private $controller = null;
  46. private $dates = null;
  47. private $locale = null;
  48. private $event_model_name = 'Event';
  49. private $event_start_date_field = null;
  50. private $event_end_date_field = null;
  51. private $first_date_to_show;
  52. private $first_date_of_month;
  53. private $first_date_of_week;
  54. private $last_date_to_show;
  55. private $last_date_of_month;
  56. private $last_date_of_week;
  57. public function initialize(&$controller)
  58. {
  59. $this->controller = $controller;
  60. $this->navigation_mode = self :: NAVIG_MODE_URL;
  61. $this->display_mode = self :: DISPLAY_MODE_MONTH;
  62. $this->date_link = self :: NAVIG_DATE_LINK;
  63. $this->hour_start = 8;
  64. $this->hour_end = 17;
  65. $this->set_hour_interval(0.5);
  66. //$this->display_mode = self :: DISPLAY_MODE_WEEK;
  67. //debug('initialize');
  68. //debug($this->get_calendar_data());
  69. }
  70. public function startup(&$controller)
  71. {
  72. $this->initialize_dates_for_view();
  73. if(isset($controller->params['named']['display_mode']))
  74. {
  75. $this->set_display_mode($controller->params['named']['display_mode']);
  76. }
  77. }
  78. public function initialize_dates_for_view()
  79. {
  80. switch ($this->display_mode)
  81. {
  82. case self :: DISPLAY_MODE_DAY:
  83. case self :: DISPLAY_MODE_DAY_HOUR:
  84. $this->initialize_dates_for_day();
  85. break;
  86. case self :: DISPLAY_MODE_WEEK:
  87. case self :: DISPLAY_MODE_WEEK_HOUR:
  88. $this->initialize_dates_for_week();
  89. break;
  90. case self :: DISPLAY_MODE_MONTH:
  91. $this->initialize_dates_for_month();
  92. break;
  93. }
  94. }
  95. private function get_include_date()
  96. {
  97. if(isset($this->controller->passedArgs[self :: PARAM_CURRENT_DATE]))
  98. {
  99. $include_date = date(self :: PARAM_CURRENT_DATE_FORMAT, strtotime($this->controller->passedArgs[self :: PARAM_CURRENT_DATE]));
  100. }
  101. if(!isset($include_date) || $include_date == '1970-01-01')
  102. {
  103. if($this->Session->check('AlaxosCalendar.'. $this->calendar_instance_name . '.selected_date'))
  104. {
  105. $include_date = $this->Session->read('AlaxosCalendar.'. $this->calendar_instance_name . '.selected_date');
  106. }
  107. else
  108. {
  109. $include_date = date('Y-m-d');
  110. }
  111. }
  112. $this->Session->write('AlaxosCalendar.'. $this->calendar_instance_name . '.selected_date', $include_date);
  113. return $include_date;
  114. }
  115. private function do_not_cache_webpage()
  116. {
  117. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  118. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  119. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  120. header("Cache-Control: post-check=0, pre-check=0", false);
  121. header("Pragma: no-cache"); // HTTP/1.0
  122. }
  123. private function initialize_dates_for_day()
  124. {
  125. $include_date = $this->get_include_date();
  126. $week_day_number = date('N', strtotime($include_date));
  127. $this->first_date_to_show = date('Y-m-d', strtotime($include_date));
  128. $this->last_date_to_show = date('Y-m-d', strtotime($this->first_date_to_show));
  129. $this->unique_date_to_show = date('Y-m-d', strtotime($include_date));
  130. $this->dates = array();
  131. $date_cursor = $this->unique_date_to_show;
  132. $date_info = array();
  133. $day = date('d', strtotime($date_cursor));
  134. $day_of_week = date('w', strtotime($date_cursor));
  135. $date_info['cell_options']['class'] = 'event_cell_day';
  136. if($date_cursor == date('Y-m-d'))
  137. {
  138. $date_info['cell_options']['class'] = $date_info['cell_options']['class'] . ' today';
  139. }
  140. if($day_of_week == 6 || $day_of_week == 0)
  141. {
  142. $date_info['cell_options']['class'] .= ' wweekend';
  143. }
  144. $date_info['display_date'] = null;
  145. $this->dates[$date_cursor] = $date_info;
  146. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  147. }
  148. private function initialize_dates_for_week()
  149. {
  150. $include_date = $this->get_include_date();
  151. $week_day_number = date('N', strtotime($include_date));
  152. $this->first_date_to_show = date('Y-m-d', strtotime($include_date . ' -' . ($week_day_number - 1) . ' day'));
  153. $this->last_date_to_show = date('Y-m-d', strtotime($this->first_date_to_show . ' +6 day'));
  154. $this->dates = array();
  155. $date_cursor = $this->first_date_to_show;
  156. while($date_cursor <= $this->last_date_to_show)
  157. {
  158. $date_info = array();
  159. $day = date('d', strtotime($date_cursor));
  160. $day_of_week = date('w', strtotime($date_cursor));
  161. $date_info['cell_options']['class'] = 'event_cell_week';
  162. if($date_cursor == date('Y-m-d'))
  163. {
  164. //$date_info['cell_css_class'] = $date_info['cell_css_class'] . ' today';
  165. $date_info['cell_options']['class'] = $date_info['cell_options']['class'] . ' today';
  166. }
  167. if($day_of_week == 6 || $day_of_week == 0)
  168. {
  169. $date_info['cell_options']['class'] .= ' wweekend';
  170. }
  171. $date_info['display_date'] = null;
  172. $this->dates[$date_cursor] = $date_info;
  173. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  174. }
  175. }
  176. private function initialize_dates_for_month()
  177. {
  178. $include_date = $this->get_include_date();
  179. /*
  180. * Find the first day to show
  181. */
  182. $this->first_date_of_month = date('Y-m-01', strtotime($include_date));
  183. $first_day_week_day_number = date('N', strtotime($this->first_date_of_month));
  184. $this->first_date_to_show = date('Y-m-d', strtotime($this->first_date_of_month . ' -' . ($first_day_week_day_number - 1) . ' day'));
  185. $year = date('Y', strtotime($include_date));
  186. $month = date('m', strtotime($include_date));
  187. $next_month = $month + 1;
  188. if($next_month > 12)
  189. {
  190. $next_month = 1;
  191. $year = $year + 1;
  192. }
  193. /*
  194. * Find the last day to show
  195. */
  196. $this->last_date_of_month = date('Y-m-d', strtotime(date('Y-m-d', mktime(0, 0, 0, $next_month, 1, $year)) . '-1 day'));
  197. $last_day_week_day_number = date('N', strtotime($this->last_date_of_month));
  198. $this->last_date_to_show = date('Y-m-d', strtotime($this->last_date_of_month . ' +' . (7 - $last_day_week_day_number) . ' day'));
  199. /*
  200. * Fill dates to display
  201. */
  202. $this->dates = array();
  203. $date_cursor = $this->first_date_to_show;
  204. while($date_cursor <= $this->last_date_to_show)
  205. {
  206. $day = date('d', strtotime($date_cursor));
  207. $day_of_week = date('w', strtotime($date_cursor));
  208. $date_info = array();
  209. if($date_cursor < $this->first_date_of_month || $date_cursor > $this->last_date_of_month)
  210. {
  211. //$date_info['cell_css_class'] = 'event_cell_other_month';
  212. $date_info['cell_options']['class'] = 'event_cell_other_month';
  213. }
  214. else
  215. {
  216. //$date_info['cell_css_class'] = 'event_cell_current_month';
  217. $date_info['cell_options']['class'] = 'event_cell_current_month';
  218. }
  219. if($date_cursor == date('Y-m-d'))
  220. {
  221. //$date_info['cell_css_class'] = $date_info['cell_css_class'] . ' today';
  222. $date_info['cell_options']['class'] = $date_info['cell_options']['class'] . ' today';
  223. }
  224. if($day_of_week == 6 || $day_of_week == 0)
  225. {
  226. if($this->hide_other_months_dates)
  227. {
  228. if($date_cursor >= $this->first_date_of_month && $date_cursor <= $this->last_date_of_month)
  229. {
  230. $date_info['cell_options']['class'] .= ' weekend';
  231. }
  232. }
  233. else
  234. {
  235. $date_info['cell_options']['class'] .= ' weekend';
  236. }
  237. }
  238. if($day == 1)
  239. {
  240. DateTool :: set_current_locale($this->locale);
  241. if($this->hide_other_months_dates && ($date_cursor < $this->first_date_of_month || $date_cursor > $this->last_date_of_month))
  242. {
  243. $date_info['display_date'] = '';
  244. }
  245. else
  246. {
  247. $date_info['display_date'] = strftime('%d %B %Y', strtotime($date_cursor));
  248. }
  249. }
  250. else
  251. {
  252. if($this->hide_other_months_dates && ($date_cursor < $this->first_date_of_month || $date_cursor > $this->last_date_of_month))
  253. {
  254. $date_info['display_date'] = '';
  255. }
  256. else
  257. {
  258. $date_info['display_date'] = $day;
  259. }
  260. }
  261. $date_info['link_date'] = date('Y-m-d', strtotime($date_cursor));
  262. //$date_info['event_model_name'] = $this->event_model_name;
  263. $this->dates[$date_cursor] = $date_info;
  264. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  265. }
  266. //debug($this->dates);
  267. }
  268. public function get_dates()
  269. {
  270. return $this->dates;
  271. }
  272. public function set_locale($locale)
  273. {
  274. $this->locale = $locale;
  275. }
  276. public function set_navigation_mode($navigation_mode)
  277. {
  278. $this->navigation_mode = $navigation_mode;
  279. }
  280. public function set_date_link($date_link)
  281. {
  282. $this->date_link = $date_link;
  283. }
  284. public function set_display_mode($display_mode)
  285. {
  286. if($display_mode == self :: DISPLAY_MODE_MONTH
  287. || $display_mode == self :: DISPLAY_MODE_WEEK
  288. || $display_mode == self :: DISPLAY_MODE_WEEK_HOUR
  289. || $display_mode == self :: DISPLAY_MODE_DAY
  290. || $display_mode == self :: DISPLAY_MODE_DAY_HOUR)
  291. {
  292. $this->display_mode = $display_mode;
  293. $this->initialize_dates_for_view();
  294. }
  295. }
  296. public function set_hide_other_months_dates($hide)
  297. {
  298. $this->hide_other_months_dates = $hide;
  299. $this->remove_other_month_dates();
  300. }
  301. public function set_display_day_names($enabled)
  302. {
  303. $this->display_day_names = $enabled;
  304. }
  305. public function set_week_day_header_format($format)
  306. {
  307. $this->week_day_header_format = $format;
  308. }
  309. public function set_month_day_header_format($format)
  310. {
  311. $this->month_day_header_format = $format;
  312. }
  313. public function set_calendar_instance_name($name)
  314. {
  315. $this->calendar_instance_name = $name;
  316. }
  317. public function set_first_hour_displayed($hour)
  318. {
  319. $this->hour_start = $hour;
  320. }
  321. public function set_last_hour_displayed($hour)
  322. {
  323. $this->hour_end = $hour;
  324. }
  325. /**
  326. * The time interval to display if the hours are shown in the view
  327. *
  328. * @param float $interval Interval given in hours (e.g. 0.5 -> 30 min)
  329. * @return unknown_type
  330. */
  331. public function set_hour_interval($interval)
  332. {
  333. if(is_numeric($interval))
  334. {
  335. $this->hour_interval = $interval;
  336. }
  337. }
  338. public function add_events($events, $options = null)
  339. {
  340. //debug($events);
  341. $options['model_name'] = isset($options['model_name']) ? $options['model_name'] : 'Event';
  342. $options['link_controller'] = isset($options['link_controller']) ? $options['link_controller'] : strtolower($options['model_name'] . 's');
  343. $options['link_action'] = isset($options['link_action']) ? $options['link_action'] : 'view';
  344. $options['model_name'] = isset($options['model_name']) ? $options['model_name'] : 'Event';
  345. $options['start_field'] = isset($options['start_field']) ? $options['start_field'] : 'startDate';
  346. $options['end_field'] = isset($options['end_field']) ? $options['end_field'] : 'endDate';
  347. $options['title_field'] = isset($options['title_field']) ? $options['title_field'] : 'title';
  348. $options['id_field'] = isset($options['id_field']) ? $options['id_field'] : 'id';
  349. $options['title_template'] = isset($options['title_template']) ? $options['title_template'] : '';
  350. $options['css_class'] = isset($options['css_class']) ? $options['css_class'] : 'event';
  351. foreach ($events as $event)
  352. {
  353. //debug($event);
  354. //debug($options);
  355. $event_start_date = date('Y-m-d', strtotime($event[$options['model_name']][$options['start_field']]));
  356. $event_end_date = date('Y-m-d', strtotime($event[$options['model_name']][$options['end_field']]));
  357. $date_cursor = $event_start_date;
  358. while($date_cursor <= $event_end_date)
  359. {
  360. if(array_key_exists($date_cursor, $this->dates))
  361. {
  362. if(strlen($options['title_template']) > 0)
  363. {
  364. $options['processed_title_template'] = $this->process_template($options['title_template'], $event);
  365. }
  366. $this->dates[$date_cursor]['events'][] = array('model' => $event, 'options' => $options);
  367. }
  368. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  369. }
  370. }
  371. //debug($this->dates);
  372. }
  373. public function set_next_event($event, $model_name, $start_date_fieldname)
  374. {
  375. if(isset($event) && is_array($event))
  376. {
  377. $event_info = array('start_date_fieldname' => $start_date_fieldname, 'model_name' => $model_name, 'event' => $event);
  378. if($this->display_mode == self::DISPLAY_MODE_MONTH)
  379. {
  380. $next_period_date = $this->get_next_month_date();
  381. }
  382. elseif($this->display_mode == self::DISPLAY_MODE_WEEK || $this->display_mode == self::DISPLAY_MODE_WEEK_HOUR)
  383. {
  384. $next_period_date = $this->get_next_week_date();
  385. }
  386. elseif($this->display_mode == self::DISPLAY_MODE_DAY || $this->display_mode == self::DISPLAY_MODE_DAY_HOUR)
  387. {
  388. //throw new Exception('next event not implemented for day');
  389. $next_period_date = $this->get_next_day_date();
  390. }
  391. if(isset($this->next_event_info))
  392. {
  393. if( ($event[$model_name][$start_date_fieldname] >= $next_period_date)
  394. &&
  395. ($this->next_event_info['event'][ $this->next_event_info['model_name'] ][ $this->next_event_info['start_date_fieldname'] ] > $event[$model_name][$start_date_fieldname]))
  396. {
  397. $this->next_event_info = $event_info;
  398. }
  399. }
  400. else
  401. {
  402. $this->next_event_info = $event_info;
  403. }
  404. }
  405. }
  406. public function set_previous_event($event, $model_name, $start_date_fieldname)
  407. {
  408. if(isset($event) && is_array($event))
  409. {
  410. $event_info = array('start_date_fieldname' => $start_date_fieldname, 'model_name' => $model_name, 'event' => $event);
  411. $first_displayed_date = $this->get_first_displayed_date();
  412. if(isset($this->previous_event_info))
  413. {
  414. if( ($event[$model_name][$start_date_fieldname] <= $first_displayed_date)
  415. &&
  416. ($this->previous_event_info['event'][ $this->previous_event_info['model_name'] ][ $this->previous_event_info['start_date_fieldname'] ] < $event[$model_name][$start_date_fieldname]))
  417. {
  418. $this->previous_event_info = $event_info;
  419. }
  420. }
  421. else
  422. {
  423. $this->previous_event_info = $event_info;
  424. }
  425. }
  426. }
  427. public function clear_events()
  428. {
  429. foreach ($this->dates as $index => $date)
  430. {
  431. if(isset($date['event']))
  432. {
  433. unset($this->dates[$index]['event']);
  434. }
  435. }
  436. }
  437. public function get_next_month_date()
  438. {
  439. return date('Y-m-d', strtotime($this->first_date_of_month . '+ 1 month'));
  440. }
  441. public function get_previous_month_date()
  442. {
  443. return date('Y-m-d', strtotime($this->first_date_of_month . '- 1 day'));
  444. }
  445. public function get_first_displayed_date()
  446. {
  447. //debug( $this->first_date_to_show);
  448. return $this->first_date_to_show;
  449. }
  450. public function get_last_displayed_date()
  451. {
  452. //debug( $this->last_date_to_show);
  453. return $this->last_date_to_show;
  454. }
  455. public function get_next_displayed_date()
  456. {
  457. return date('Y-m-d', strtotime($this->last_date_to_show . '+ 1 day'));
  458. }
  459. private function remove_other_month_dates()
  460. {
  461. if(isset($this->dates) && is_array($this->dates))
  462. {
  463. foreach ($this->dates as $date_value => $options)
  464. {
  465. if($date_value < $this->first_date_of_month || $date_value > $this->last_date_of_month)
  466. {
  467. $options['display_date'] = null;
  468. $this->dates[$date_value] = $options;
  469. }
  470. }
  471. }
  472. }
  473. private function get_previous_day_date()
  474. {
  475. return date('Y-m-d', strtotime($this->first_date_to_show . '- 1 day'));
  476. }
  477. private function get_previous_week_date()
  478. {
  479. return date('Y-m-d', strtotime($this->first_date_to_show . '- 7 day'));
  480. }
  481. private function get_next_week_date()
  482. {
  483. return date('Y-m-d', strtotime($this->first_date_to_show . '+ 7 day'));
  484. }
  485. private function get_next_day_date()
  486. {
  487. return date('Y-m-d', strtotime($this->first_date_to_show . '+ 1 day'));
  488. }
  489. private function get_previous_event_date()
  490. {
  491. if(isset($this->previous_event_info['event'][$this->previous_event_info['model_name']][$this->previous_event_info['start_date_fieldname']]))
  492. {
  493. return date('Y-m-d', strtotime($this->previous_event_info['event'][$this->previous_event_info['model_name']][$this->previous_event_info['start_date_fieldname']]));
  494. }
  495. }
  496. private function get_next_event_date()
  497. {
  498. //debug($this->next_event_info);
  499. if(isset($this->next_event_info['event'][$this->next_event_info['model_name']][$this->next_event_info['start_date_fieldname']]))
  500. {
  501. return date('Y-m-d', strtotime($this->next_event_info['event'][$this->next_event_info['model_name']][$this->next_event_info['start_date_fieldname']]));
  502. }
  503. }
  504. private function get_calendar_title()
  505. {
  506. //debug($this);
  507. //debug($this->unique_date_to_show);
  508. //debug($this->param->named->date_to_show);
  509. //debug($this->components);
  510. //debug($this->day_names);
  511. //debug($this->get_dates());
  512. switch ($this->display_mode)
  513. {
  514. case self :: DISPLAY_MODE_DAY:
  515. case self :: DISPLAY_MODE_DAY_HOUR:
  516. DateTool :: set_current_locale($this->locale);
  517. return strftime('%A %d %B %Y', strtotime($this->unique_date_to_show));
  518. break;
  519. case self :: DISPLAY_MODE_WEEK:
  520. case self :: DISPLAY_MODE_WEEK_HOUR:
  521. DateTool :: set_current_locale($this->locale);
  522. return "Semaine ".strftime('%U', strtotime($this->first_date_to_show));
  523. break;
  524. case self :: DISPLAY_MODE_MONTH:
  525. DateTool :: set_current_locale($this->locale);
  526. return strftime('%B %Y', strtotime($this->first_date_of_month));
  527. break;
  528. }
  529. }
  530. public function get_calendar_data()
  531. {
  532. $data = array();
  533. switch ($this->display_mode)
  534. {
  535. case self :: DISPLAY_MODE_DAY:
  536. case self :: DISPLAY_MODE_DAY_HOUR:
  537. $data['previous_date'] = $this->get_previous_day_date();
  538. $data['next_date'] = $this->get_next_day_date();
  539. $data['hour_start'] = $this->hour_start;
  540. $data['hour_end'] = $this->hour_end;
  541. $data['hour_interval'] = $this->hour_interval;
  542. break;
  543. case self :: DISPLAY_MODE_WEEK:
  544. $data['previous_date'] = $this->get_previous_week_date();
  545. $data['next_date'] = $this->get_next_week_date();
  546. break;
  547. case self :: DISPLAY_MODE_WEEK_HOUR:
  548. $data['previous_date'] = $this->get_previous_week_date();
  549. $data['next_date'] = $this->get_next_week_date();
  550. $data['hour_start'] = $this->hour_start;
  551. $data['hour_end'] = $this->hour_end;
  552. $data['hour_interval'] = $this->hour_interval;
  553. break;
  554. case self :: DISPLAY_MODE_MONTH:
  555. $data['previous_date'] = $this->get_previous_month_date();
  556. $data['next_date'] = $this->get_next_month_date();
  557. break;
  558. }
  559. $data['previous_event_date'] = $this->get_previous_event_date();
  560. $data['next_event_date'] = $this->get_next_event_date();
  561. $data['title'] = $this->get_calendar_title();
  562. //debug($data['title']);
  563. $data['navigation_mode'] = $this->navigation_mode;
  564. $data['date_link'] = $this->date_link;
  565. $data['display_mode'] = $this->display_mode;
  566. $data['dates'] = $this->get_dates();
  567. if($this->display_day_names)
  568. {
  569. $data['day_names'] = $this->get_day_header_values();
  570. }
  571. if($this->navigation_mode == self :: NAVIG_MODE_AJAX)
  572. {
  573. /*
  574. * Do not cache the page including the calendar to allow correct comportment
  575. * when the back button is clicked to come back on the page
  576. * -> the calendar is rebuild with the last selected date stored in session
  577. */
  578. $this->do_not_cache_webpage();
  579. }
  580. return $data;
  581. }
  582. private function get_day_header_values()
  583. {
  584. DateTool :: set_current_locale($this->locale);
  585. $format = '';
  586. switch($this->display_mode)
  587. {
  588. case self :: DISPLAY_MODE_MONTH:
  589. $format = $this->month_day_header_format;;
  590. break;
  591. case self :: DISPLAY_MODE_DAY:
  592. case self :: DISPLAY_MODE_DAY_HOUR:
  593. $format = $this->day_day_header_format;;
  594. break;
  595. case self :: DISPLAY_MODE_WEEK:
  596. case self :: DISPLAY_MODE_WEEK_HOUR:
  597. $format = $this->week_day_header_format;
  598. break;
  599. }
  600. if($this->display_day_names || $this->display_mode == self :: DISPLAY_MODE_WEEK || $this->display_mode == self :: DISPLAY_MODE_WEEK_HOUR || $this->display_mode == self :: DISPLAY_MODE_MONTH || $this->display_mode == self :: DISPLAY_MODE_DAY || $this->display_mode == self :: DISPLAY_MODE_DAY_HOUR)
  601. {
  602. $day_names = array();
  603. $date_cursor = $this->first_date_to_show;
  604. if($this->display_mode == self :: DISPLAY_MODE_DAY || $this->display_mode == self :: DISPLAY_MODE_DAY_HOUR)
  605. {
  606. $day_names[1] = strftime($format, strtotime($date_cursor));
  607. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  608. }
  609. else{
  610. for($i = 1;$i <= 7; $i++)
  611. {
  612. $day_names[$i] = strftime($format, strtotime($date_cursor));
  613. $date_cursor = date('Y-m-d', strtotime($date_cursor . ' +1 day'));
  614. }
  615. }
  616. }
  617. return $day_names;
  618. }
  619. private function process_template($template, $models)
  620. {
  621. //debug($models);
  622. $loop = true;
  623. foreach ($models as $model_name => $properties)
  624. {
  625. if(!$loop)
  626. {
  627. break;
  628. }
  629. foreach ($properties as $property_name => $property_value)
  630. {
  631. //stop to loop if no more properties to replace in template
  632. if(!strpos($template, '{'))
  633. {
  634. $loop = false;
  635. break;
  636. }
  637. $template = str_ireplace('{' . $model_name . '.' . $property_name . '}', $property_value, $template);
  638. }
  639. }
  640. //debug($template);
  641. return $template;
  642. }
  643. }
  644. ?>