Kronolith::addCoverDates PHP Method

addCoverDates() public static method

Adds an event to all the days it covers.
public static addCoverDates ( &$results, Kronolith_Event $event, Horde_Date $eventStart, Horde_Date $eventEnd, boolean $json, Horde_Date $originalStart = null, Horde_Date $originalEnd = null, Horde_Date $endDate = null )
$event Kronolith_Event An event object.
$eventStart Horde_Date The event's start of the actual recurrence.
$eventEnd Horde_Date The event's end of the actual recurrence.
$json boolean Store the results of the events' toJson() method?
$originalStart Horde_Date The actual starting time of a single event spanning multiple days.
$originalEnd Horde_Date The actual ending time of a single event spanning multiple days.
$endDate Horde_Date
    public static function addCoverDates(&$results, $event, $eventStart, $eventEnd, $json, $originalStart = null, $originalEnd = null, Horde_Date $endDate = null)
    {
        $loopDate = new Horde_Date(array('month' => $eventStart->month, 'mday' => $eventStart->mday, 'year' => $eventStart->year));
        $allDay = $event->isAllDay();
        while ($loopDate->compareDateTime($eventEnd) <= 0 && $loopDate->compareDateTime($endDate) <= 0) {
            if (!$allDay || $loopDate->compareDateTime($eventEnd) != 0) {
                $addEvent = clone $event;
                if ($originalStart) {
                    $addEvent->originalStart = $originalStart;
                }
                if ($originalEnd) {
                    $addEvent->originalEnd = $originalEnd;
                }
                /* If this is the start day, set the start time to
                 * the real start time, otherwise set it to
                 * 00:00 */
                if ($loopDate->compareDate($eventStart) != 0) {
                    $addEvent->start = clone $loopDate;
                    $addEvent->start->hour = $addEvent->start->min = $addEvent->start->sec = 0;
                    $addEvent->first = false;
                } else {
                    $addEvent->start = $eventStart;
                }
                /* If this is the end day, set the end time to the
                 * real event end, otherwise set it to 23:59. */
                if ($loopDate->compareDate($eventEnd) != 0) {
                    $addEvent->end = clone $loopDate;
                    $addEvent->end->hour = 23;
                    $addEvent->end->min = $addEvent->end->sec = 59;
                    $addEvent->last = false;
                } else {
                    $addEvent->end = $eventEnd;
                }
                if ($addEvent->recurs() && $addEvent->recurrence->hasCompletion($loopDate->year, $loopDate->month, $loopDate->mday)) {
                    $addEvent->status = Kronolith::STATUS_CANCELLED;
                }
                $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson(array('all_day' => $allDay)) : $addEvent;
            }
            $loopDate->mday++;
        }
    }