PageRenderTime 48ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/common/libraries/php/calendar/mini_day_calendar.class.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 147 lines | 102 code | 21 blank | 24 comment | 10 complexity | a2db46f53dccc4bd7dc3ab2ebbfb80ae MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. namespace common\libraries;
  3. use HTML_Table;
  4. /**
  5. * $Id: mini_day_calendar.class.php
  6. * @package application.common
  7. */
  8. require_once ('day_calendar.class.php');
  9. /**
  10. * A tabular representation of a day calendar
  11. */
  12. class MiniDayCalendar extends DayCalendar
  13. {
  14. function __construct($display_time, $hour_step = '1')
  15. {
  16. parent :: __construct($display_time, $hour_step);
  17. $this->updateAttributes('class="calendar_table mini_calendar"');
  18. }
  19. function get_start_hour()
  20. {
  21. $working_start = LocalSetting :: get('working_hours_start');
  22. $hide = LocalSetting :: get('hide_none_working_hours');
  23. $start_hour = 0;
  24. if ($hide)
  25. {
  26. $start_hour = $working_start;
  27. }
  28. return $start_hour;
  29. }
  30. function get_end_hour()
  31. {
  32. $working_end = LocalSetting :: get('working_hours_end');
  33. $hide = LocalSetting :: get('hide_none_working_hours');
  34. $end_hour = 24;
  35. if ($hide)
  36. {
  37. $end_hour = $working_end;
  38. }
  39. return $end_hour;
  40. }
  41. /**
  42. * Gets the first date which will be displayed by this calendar.
  43. * @return int
  44. */
  45. public function get_start_time()
  46. {
  47. return strtotime(date('Y-m-d ' . $this->get_start_hour() . ':00:00', $this->get_display_time()));
  48. }
  49. /**
  50. * Gets the end date which will be displayed by this calendar.
  51. * @return int
  52. */
  53. public function get_end_time()
  54. {
  55. return strtotime(date('Y-m-d ' . ($this->get_end_hour() - 1) . ':59:59', $this->get_display_time()));
  56. }
  57. protected function build_table()
  58. {
  59. $year_day = date('z', $this->get_display_time()) + 1;
  60. $year_week = date('W', $this->get_display_time());
  61. $header = $this->getHeader();
  62. $header->addRow(array(
  63. Translation :: get('Day') . ' ' . $year_day . ', ' . Translation :: get('Week') . ' ' . $year_week));
  64. $header->setRowType(0, 'th');
  65. $start_hour = $this->get_start_hour();
  66. $end_hour = $this->get_end_hour();
  67. for($hour = $start_hour; $hour < $end_hour; $hour += $this->get_hour_step())
  68. {
  69. $row_id = ($hour / $this->get_hour_step()) - $start_hour;
  70. $table_start_date = mktime($hour, 0, 0, date('m', $this->get_display_time()), date('d', $this->get_display_time()), date('Y', $this->get_display_time()));
  71. $table_end_date = strtotime('+' . $this->get_hour_step() . ' hours', $table_start_date);
  72. $cell_contents = $hour . 'u - ' . ($hour + $this->get_hour_step()) . 'u <br />';
  73. $this->setCellContents($row_id, 0, $cell_contents);
  74. // Highlight current hour
  75. if (date('Y-m-d') == date('Y-m-d', $this->get_display_time()))
  76. {
  77. if (date('H') >= $hour && date('H') < $hour + $this->get_hour_step())
  78. {
  79. $this->updateCellAttributes($row_id, 0, 'class="highlight"');
  80. }
  81. }
  82. // Is current table hour during working hours?
  83. if ($hour < 8 || $hour > 18)
  84. {
  85. $this->updateCellAttributes($row_id, 0, 'class="disabled_month"');
  86. }
  87. }
  88. }
  89. /**
  90. * Returns a html-representation of this minidaycalendar
  91. * @return string
  92. */
  93. public function toHtml()
  94. {
  95. $html = parent :: toHtml();
  96. $html = str_replace('class="calendar_navigation"', 'class="calendar_navigation mini_calendar"', $html);
  97. return $html;
  98. }
  99. /**
  100. * Adds the events to the calendar
  101. */
  102. private function add_events()
  103. {
  104. $events = $this->get_events_to_show();
  105. foreach ($events as $time => $items)
  106. {
  107. if ($time >= $this->get_end_time())
  108. {
  109. continue;
  110. }
  111. $row = (date('H', $time) / $this->get_hour_step()) - ($this->get_start_hour() / $this->get_hour_step());
  112. foreach ($items as $index => $item)
  113. {
  114. $cell_content = $this->getCellContents($row, 0);
  115. $cell_content .= $item;
  116. $this->setCellContents($row, 0, $cell_content);
  117. }
  118. }
  119. }
  120. public function render()
  121. {
  122. $this->add_events();
  123. return $this->toHtml();
  124. }
  125. }
  126. ?>