Пример #1
0
 /**
  * Fill the response array with the events of the given calendar between 
  * the start and end time
  * 
  * @param array $response
  * @param \GO\Calendar\Model\Calendar $calendar
  * @param string $startTime
  * @param string $endTime
  * @return array 
  */
 private function _getEventResponseForPeriod($response, $calendar, $startTime, $endTime)
 {
     $resultCount = 0;
     // Get all the localEvent models between the given time period
     $events = $calendar->getEventsForPeriod(strtotime($startTime), strtotime($endTime));
     //		$this->_uuidEvents = array();
     // Loop through each event and prepare the view for it.
     foreach ($events as $event) {
         // Check for a double event, and merge them if they are double
         $key = $event->getUuid() . $event->getAlternateStartTime();
         //$event->getEvent()->location = $key;
         if (isset($this->_uuidEvents[$key])) {
             if (!empty(\GO::config()->calendar_disable_merge) || $event->getEvent()->calendar_id == $this->_uuidEvents[$key]->getEvent()->calendar_id) {
                 //this is an erroneous situation. events with the same start time and the same uuid may not appear in the same calendar.
                 //if we merge it then the user can't edit the events anymore.
                 $key .= $event->getEvent()->id;
                 $this->_uuidEvents[$key] = $event;
             } else {
                 $this->_uuidEvents[$key]->mergeWithEvent($event);
             }
         } else {
             //echo $event->getEvent()->name.' '.$key.', ';
             $this->_uuidEvents[$key] = $event;
         }
         //			$this->_uuidEvents[]=$event;
         // If you are showing more than one calendar, then change the display
         // color of the current event to the color of the calendar it belongs to.
         if ($response['calendar_count'] > 1) {
             $background = $calendar->getColor(\GO::user()->id);
             if (empty($background)) {
                 $background = $calendar->displayColor;
             }
             $event->setBackgroundColor($background);
         }
         // Set the id of the event, this is a count of the displayed events
         // in the view.
         //			$event->displayId = $response['count']++;
         $resultCount++;
         // Add one to the global result count;
     }
     //		foreach($this->_uuidEvents as $uuidEvent) { // Add the event to the results array
     //			$index = $this->_getIndex($response['results'],$uuidEvent->getAlternateStartTime(),$uuidEvent->getName());
     //			$response['results'][$index]=$uuidEvent->getResponseData();
     //			if ($uuidEvent->getEvent()->isResource())
     //				$response['results'][$index]['resourced_calendar_name'] = $uuidEvent->getEvent()->resourceGetEventCalendarName();
     //		}
     $response['count_events_only'] = $resultCount;
     // Set the count of the events
     return $response;
 }