private function get_calendar_cells_with_hours($calendar_data)
 {
     $dates = $calendar_data['dates'];
     //debug($calendar_data);
     $date_keys = array_keys($dates);
     //debug($date_keys);
     $cells = array(array('cell_options' => array('class' => 'dayname')));
     $days_names = $this->get_day_names_cells($calendar_data);
     $cells = array_merge($cells, $days_names);
     $hours = DateTool::get_time_array($calendar_data['hour_start'], $calendar_data['hour_end'], $calendar_data['hour_interval']);
     /*
      * Hour cell content
      */
     $hour_string = '';
     $total_height = 0;
     $css_class = 'hour_zone';
     foreach ($hours as $index => $hour) {
         if ($index == count($hours) - 1) {
             $css_class = 'last_hour_zone';
         }
         $hour_string .= '<div class="' . $css_class . '" style="height:' . $this->time_display_height . 'px;">' . $hour . '</div>';
         $total_height += $this->time_display_height;
     }
     $hour_display_height = $this->time_display_height / $calendar_data['hour_interval'];
     $cell_content = array();
     $cell_content['content'] = $hour_string;
     $cell_content['cell_options'] = array('class' => 'hour_column');
     $cells[] = $cell_content;
     //debug(count($date_keys));
     for ($i = 0; $i < count($date_keys); $i++) {
         $cell_content = array();
         $current_date = $date_keys[$i];
         $calendar_start_datetime = '';
         $calendar_end_datetime = '';
         $event_start_date = '';
         $event_end_date = '';
         //	        debug($dates);
         //	        debug($date_keys[$i]);
         if (isset($dates[$date_keys[$i]]['events'])) {
             $cell_content['content'] = '';
             foreach ($dates[$date_keys[$i]]['events'] as $event) {
                 $event_start_date = new Datetime($event['model'][$event['options']['model_name']][$event['options']['start_field']]);
                 $event_end_date = new Datetime($event['model'][$event['options']['model_name']][$event['options']['end_field']]);
                 $calendar_start_datetime = new Datetime($current_date . ' ' . DateTool::get_time_from_hour($calendar_data['hour_start']));
                 $calendar_end_datetime = new Datetime($current_date . ' ' . DateTool::get_time_from_hour($calendar_data['hour_end']));
                 if ($event_start_date <= $calendar_start_datetime && $event_end_date > $calendar_start_datetime || $event_start_date < $calendar_end_datetime && $event_end_date >= $calendar_end_datetime || $event_start_date >= $calendar_start_datetime && $event_end_date <= $calendar_end_datetime) {
                     /*
                      * Event must be displayed
                      */
                     $top_margin = 2;
                     $id = $event['model'][$event['options']['model_name']][$event['options']['id_field']];
                     $controller = $event['options']['link_controller'];
                     $action = $event['options']['link_action'];
                     $event_start_timestamp = strtotime($event['model'][$event['options']['model_name']][$event['options']['start_field']]);
                     $event_end_timestamp = strtotime($event['model'][$event['options']['model_name']][$event['options']['end_field']]);
                     $calendar_start_timestamp = strtotime($current_date . ' ' . $calendar_data['hour_start'] . ':00:00');
                     $calendar_end_timestamp = strtotime($current_date . ' ' . $calendar_data['hour_end'] . ':00:00');
                     //debug($event_start_timestamp);
                     //debug($event_end_timestamp);
                     //debug($calendar_start_timestamp);
                     //debug($calendar_end_timestamp);
                     if ($event_start_date > $calendar_start_datetime) {
                         /*
                          * Calculate top-margin if event doesn't start at the top of the calendar
                          */
                         $hour_difference = ($event_start_timestamp - $calendar_start_timestamp) / 3600;
                         $border_height_compensation = $hour_difference / $calendar_data['hour_interval'];
                         $top_margin = $hour_difference * $hour_display_height + 0.75 * $border_height_compensation;
                     }
                     /*
                      * Check if event has to start at the top of the calendar
                      */
                     $display_start_before = false;
                     if ($event_start_timestamp < $calendar_start_timestamp) {
                         $event_start_timestamp = $calendar_start_timestamp;
                         $event_start_date = $calendar_start_datetime;
                         $display_start_before = true;
                     }
                     /*
                      * Check if event has to end at the bottom of the calendar
                      */
                     $display_end_after = false;
                     if ($event_end_timestamp > $calendar_end_timestamp) {
                         $event_end_timestamp = $calendar_end_timestamp;
                         $event_end_date = $calendar_end_datetime;
                         $display_end_after = true;
                     }
                     /*
                      * Event height
                      */
                     $hour_difference = ($event_end_timestamp - $event_start_timestamp) / 3600;
                     $border_height_compensation = $hour_difference / $calendar_data['hour_interval'];
                     $event_height = $hour_difference * $hour_display_height + 0.75 * $border_height_compensation;
                     /*
                      * Infos to display for the event
                      */
                     $event_title = $event['model'][$event['options']['model_name']][$event['options']['title_field']];
                     if ($display_start_before) {
                         $display_start_time = '...';
                     } else {
                         $display_start_time = $event_start_date->format('H:i');
                     }
                     if ($display_end_after) {
                         $display_end_time = '...';
                     } else {
                         $display_end_time = $event_end_date->format('H:i');
                     }
                     $event_html = '<div id="event_' . $id . '" class="' . $event['options']['css_class'] . ' event_hour" style="margin-top:' . $top_margin . 'px;height:' . $event_height . 'px"><div class="event_display_time">' . $display_start_time . '</div><div style="height:' . ($event_height - 30) . 'px;">' . $event_title . '</div><div class="event_display_time">' . $display_end_time . '</div></div>';
                     $event_html = $this->AlaxosHtml->link($event_html, array('controller' => $controller, 'action' => $action, $id), array('escape' => false));
                     //debug($event_height);
                     if ($event_height < 80) {
                         /*
                          * If the event display is not high enough, better to make the event nowrap
                          * to have place in width to put the title
                          */
                         $cell_content['content'] .= '<td nowrap="nowrap">' . $event_html . '</td>';
                     } else {
                         $cell_content['content'] .= '<td>' . $event_html . '</td>';
                     }
                 }
             }
         }
         //debug($current_date);
         $cell_content['cell_options'] = array('class' => $dates[$current_date]['cell_options']['class']);
         if (isset($cell_content['content'])) {
             $cell_content['content'] = '<table class="event_aligner" border="0" cellspacing="0" cellpadding="1"><tr>' . $cell_content['content'] . '</tr></table>';
         }
         $cells[] = $cell_content;
     }
     return $cells;
 }
Exemple #2
0
 /**
  *
  * @param float $start_hour
  * @param float $end_hour
  * @param float $step_hour
  * @return array
  */
 public static function get_time_array($start_hour, $end_hour, $step_hour, $minimum_hour = null, $maximum_hour = null, $locale = null)
 {
     if (!is_numeric($start_hour) && !is_numeric($end_hour) && $step_hour > 0) {
         $sql_date1 = DateTool::datetime_to_sql($start_hour, $locale);
         $sql_date2 = DateTool::datetime_to_sql($end_hour, $locale);
         //			debug($sql_date1);
         //			debug($sql_date2);
         $timestamp1 = strtotime($sql_date1);
         $timestamp2 = strtotime($sql_date2);
         $hour_difference = ($timestamp2 - $timestamp1) / 3600;
         //debug($hour_difference);
         $start_hour = DateTool::get_hour_as_float($start_hour);
     } elseif (is_numeric($start_hour) && is_numeric($end_hour) && $start_hour < $end_hour && $step_hour > 0) {
         $hour_difference = $end_hour - $start_hour;
         //debug($hour_difference);
     }
     if (isset($hour_difference)) {
         //debug($hour_difference);
         $times = array();
         $current_time = $start_hour;
         $end_hour = $start_hour + $hour_difference;
         //debug($end_hour);
         while ($current_time < $end_hour) {
             if (isset($minimum_hour) && isset($maximum_hour)) {
                 if ($minimum_hour <= $current_time && $current_time < $maximum_hour) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 }
             } elseif (!isset($minimum_hour) && isset($maximum_hour)) {
                 if ($current_time < $maximum_hour) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 } else {
                     /*
                      * Max time has been overcome
                      */
                     break;
                 }
             } elseif (isset($minimum_hour) && !isset($maximum_hour)) {
                 if ($minimum_hour <= $current_time) {
                     $times[] = DateTool::get_time_from_hour($current_time);
                 }
             } else {
                 $times[] = DateTool::get_time_from_hour($current_time);
             }
             $current_time += $step_hour;
         }
         //debug($times);
         return $times;
     }
 }