listEvents() 공개 정적인 메소드

Returns all the events that happen each day within a time period
사용 중단:
public static listEvents ( Horde_Date $startDate, Horde_Date $endDate, array $calendars = null, array $options = [] ) : array
$startDate Horde_Date The start of the time range.
$endDate Horde_Date The end of the time range.
$calendars array The calendars to check for events.
$options array Additional options: - show_recurrence: (boolean) Return every instance of a recurring event? DEFAULT: false (Only return recurring events once inside $startDate - $endDate range) - has_alarm: (boolean) Only return events with alarms. DEFAULT: false (Return all events) - json: (boolean) Store the results of the event's toJson() method? DEFAULT: false - cover_dates: (boolean) Add the events to all days that they cover? DEFAULT: true - hide_exceptions: (boolean) Hide events that represent exceptions to a recurring event. DEFAULT: false (Do not hide exception events) - fetch_tags: (boolean) Fetch tags for all events. DEFAULT: false (Do not fetch event tags)
리턴 array The events happening in this time period.
예제 #1
0
파일: Day.php 프로젝트: DSNS-LAB/Dmail
 /**
  *
  * @param Horde_Date $date  The day for this view
  * @param array $events     An array of Kronolith_Event objects
  *
  * @return Kronolith_View_Day
  */
 public function __construct(Horde_Date $date, array $events = null)
 {
     parent::__construct($date->month, $date->mday, $date->year);
     $this->sidebyside = $GLOBALS['prefs']->getValue('show_shared_side_by_side');
     if ($this->sidebyside) {
         $allCalendars = Kronolith::listInternalCalendars();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $cid) {
             $this->_currentCalendars[$cid] = $allCalendars[$cid];
             $this->all_day_events[$cid] = array();
         }
     } else {
         $this->_currentCalendars = array(0);
     }
     if ($events === null) {
         try {
             $events = Kronolith::listEvents($this, new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->mday)));
             $this->events = array_shift($events);
         } catch (Exception $e) {
             $GLOBALS['notification']->push($e, 'horde.error');
             $this->events = array();
         }
     } else {
         $this->events = $events;
     }
     if (!is_array($this->events)) {
         $this->events = array();
     }
 }
예제 #2
0
파일: Year.php 프로젝트: DSNS-LAB/Dmail
 /**
  *
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Year
  */
 public function __construct(Horde_Date $date)
 {
     $this->year = $date->year;
     $startDate = new Horde_Date(array('year' => $this->year, 'month' => 1, 'mday' => 1));
     $endDate = new Horde_Date(array('year' => $this->year, 'month' => 12, 'mday' => 31));
     try {
         $this->_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS));
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }
예제 #3
0
파일: Week.php 프로젝트: DSNS-LAB/Dmail
 public function __construct(Horde_Date $date)
 {
     $week = $date->weekOfYear();
     $year = $date->year;
     if (!$GLOBALS['prefs']->getValue('week_start_monday') && $date->dayOfWeek() == Horde_Date::DATE_SUNDAY) {
         ++$week;
     }
     if ($week > 51 && $date->month == 1) {
         --$year;
     } elseif ($week == 1 && $date->month == 12) {
         ++$year;
     }
     $this->year = $year;
     $this->week = $week;
     $day = Horde_Date_Utils::firstDayOfWeek($week, $year);
     if (!isset($this->startDay)) {
         if ($GLOBALS['prefs']->getValue('week_start_monday')) {
             $this->startDay = Horde_Date::DATE_MONDAY;
             $this->endDay = Horde_Date::DATE_SUNDAY + 7;
         } else {
             $day->mday--;
             $this->startDay = Horde_Date::DATE_SUNDAY;
             $this->endDay = Horde_Date::DATE_SATURDAY;
         }
     }
     $this->startDate = new Horde_Date($day);
     for ($i = $this->startDay; $i <= $this->endDay; ++$i) {
         $this->days[$i] = new Kronolith_View_Day($day, array());
         $day->mday++;
     }
     $endDate = new Horde_Date($day);
     try {
         $allevents = Kronolith::listEvents($this->startDate, $endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $allevents = array();
     }
     for ($i = $this->startDay; $i <= $this->endDay; ++$i) {
         $date_stamp = $this->days[$i]->dateString();
         $this->days[$i]->events = isset($allevents[$date_stamp]) ? $allevents[$date_stamp] : array();
     }
     $this->sidebyside = $this->days[$this->startDay]->sidebyside;
     $this->_currentCalendars = $this->days[$this->startDay]->currentCalendars;
     $this->slotsPerHour = $this->days[$this->startDay]->slotsPerHour;
     $this->slotsPerDay = $this->days[$this->startDay]->slotsPerDay;
     $this->slotLength = $this->days[$this->startDay]->slotLength;
 }
예제 #4
0
파일: Month.php 프로젝트: horde/horde
 /**
  *
  * @global Horde_Prefs $prefs
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Month
  */
 public function __construct(Horde_Date $date)
 {
     global $prefs;
     $this->month = $date->month;
     $this->year = $date->year;
     // Need to calculate the start and length of the view.
     $this->date = new Horde_Date($date);
     $this->date->mday = 1;
     $this->_startday = $this->date->dayOfWeek();
     if (!$prefs->getValue('week_start_monday')) {
         $this->_startOfView = 1 - $this->_startday;
     } else {
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_startOfView = -5;
         } else {
             $this->_startOfView = 2 - $this->_startday;
         }
     }
     $startDate = new Horde_Date($this->year, $this->month, $this->_startOfView);
     $this->_endDate = new Horde_Date($this->year, $this->month, Horde_Date_Utils::daysInMonth($this->month, $this->year) + 1);
     $this->_endDate->mday += (7 - ($this->_endDate->format('w') - $prefs->getValue('week_start_monday'))) % 7;
     if ($prefs->getValue('show_shared_side_by_side')) {
         $allCalendars = Kronolith::listInternalCalendars();
         $this->_currentCalendars = array();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $id) {
             $this->_currentCalendars[$id] = $allCalendars[$id];
         }
     } else {
         $this->_currentCalendars = array('internal_0' => true);
     }
     try {
         $this->_events = Kronolith::listEvents($startDate, $this->_endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }
예제 #5
0
파일: index.php 프로젝트: jubinpatel/horde
            }
        }
        if (!isset($user) || !$auth->authenticate($user, array('password' => $pass))) {
            header('WWW-Authenticate: Basic realm="' . $registry->get('name') . ' Feeds"');
            _no_access(401, 'Unauthorized', sprintf(_("Login required for the requested feed (%s)."), htmlspecialchars($calendar)));
        }
    }
}
$feed_type = basename(Horde_Util::getFormData('type'));
if (empty($feed_type)) {
    // If not specified, default to Atom.
    $feed_type = 'atom';
}
$startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
try {
    $events = Kronolith::listEvents($startDate, new Horde_Date($startDate), array($calendar));
} catch (Exception $e) {
    Horde::log($e, 'ERR');
    $events = array();
}
if (isset($conf['urls']['pretty']) && $conf['urls']['pretty'] == 'rewrite') {
    $self_url = Horde::url('feed/' . $calendar, true, -1);
} else {
    $self_url = Horde::url('feed/index.php', true, -1)->add('c', $calendar);
}
$owner = $share->get('owner');
$identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($owner);
$history = $injector->getInstance('Horde_History');
$now = new Horde_Date(time());
$template = $injector->createInstance('Horde_Template');
$template->set('updated', $now->format(DATE_ATOM));
예제 #6
0
파일: Api.php 프로젝트: horde/horde
 /**
  * Lists events for a given time period.
  *
  * @param integer $startstamp      The start of the time period to
  *                                 retrieve.
  * @param integer $endstamp        The end of the time period to retrieve.
  * @param array   $calendars       The calendars to view events from.
  *                                 Defaults to the user's default calendar.
  * @param boolean $showRecurrence  Return every instance of a recurring
  *                                 event?  If false, will only return
  *                                 recurring events once inside the
  *                                 $startDate - $endDate range.
  * @param boolean $alarmsOnly      Filter results for events with alarms.
  *                                 Defaults to false.
  * @param boolean $showRemote      Return events from remote calendars and
  *                                 listTimeObject API as well?
  *
  * @param boolean $hideExceptions  Hide events that represent exceptions to
  *                                 a recurring event (events with baseid
  *                                 set)?
  * @param boolean $coverDates      Add multi-day events to all dates?
  *
  * @return array  A list of event hashes.
  * @throws Kronolith_Exception
  */
 public function listEvents($startstamp = null, $endstamp = null, $calendars = null, $showRecurrence = true, $alarmsOnly = false, $showRemote = true, $hideExceptions = false, $coverDates = true, $fetchTags = false)
 {
     if (!isset($calendars)) {
         $calendars = array($GLOBALS['prefs']->getValue('default_share'));
     } elseif (!is_array($calendars)) {
         $calendars = array($calendars);
     }
     foreach ($calendars as &$calendar) {
         $calendar = str_replace('internal_', '', $calendar);
         if (!Kronolith::hasPermission($calendar, Horde_Perms::READ)) {
             throw new Horde_Exception_PermissionDenied();
         }
     }
     return Kronolith::listEvents(new Horde_Date($startstamp), new Horde_Date($endstamp), $calendars, array('show_recurrence' => $showRecurrence, 'has_alarm' => $alarmsOnly, 'show_remote' => $showRemote, 'hide_exceptions' => $hideExceptions, 'cover_dates' => $coverDates, 'fetch_tags' => $fetchTags));
 }
예제 #7
0
파일: Summary.php 프로젝트: DSNS-LAB/Dmail
 /**
  */
 protected function _content()
 {
     $GLOBALS['page_output']->addScriptFile('tooltips.js', 'horde');
     $now = new Horde_Date($_SERVER['REQUEST_TIME']);
     $today = date('j');
     $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
     $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j') + $this->_params['days']));
     try {
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             $calendars = Kronolith::listCalendars();
             if (!isset($calendars[$this->_params['calendar']])) {
                 return _("Calendar not found");
             }
             if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
                 return _("Permission Denied");
             }
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = Kronolith::sortEvents($driver->listEvents($startDate, $endDate, array('show_recurrence' => true)));
         } else {
             $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS));
         }
     } catch (Exception $e) {
         return '<em>' . $e->getMessage() . '</em>';
     }
     $html = '';
     $iMax = $today + $this->_params['days'];
     $firstday = true;
     $totalevents = 0;
     for ($i = $today; $i < $iMax; ++$i) {
         $day = new Kronolith_Day(date('n'), $i);
         $date_stamp = $day->dateString();
         if (empty($all_events[$date_stamp])) {
             continue;
         }
         $firstevent = true;
         $tomorrow = $day->getTomorrow();
         foreach ($all_events[$date_stamp] as $event) {
             if (!empty($this->_params['maxevents']) && $totalevents >= $this->_params['maxevents']) {
                 break 2;
             }
             if ($event->start->compareDate($day) < 0) {
                 $event->start = $day;
             }
             if ($event->end->compareDate($tomorrow) >= 0) {
                 $event->end = $tomorrow;
             }
             if ($event->end->compareDateTime($now) < 0) {
                 continue;
             }
             if (!empty($this->_params['alarms']) && !$event->alarm) {
                 continue;
             }
             $event_active = $event->start->compareDateTime($now) < 0 && $event->end->compareDateTime($now) > 0;
             if ($firstevent) {
                 $html .= '<tr><td colspan="3" class="control"><strong>';
                 if ($day->isToday()) {
                     $dayname = _("Today");
                 } elseif ($day->isTomorrow()) {
                     $dayname = _("Tomorrow");
                 } elseif ($day->diff() < 7) {
                     $dayname = $day->strftime('%A');
                 } else {
                     $dayname = $day->strftime($GLOBALS['prefs']->getValue('date_format'));
                 }
                 $url = Horde::url('day.php', true)->setRaw(false)->add('date', $day->dateString());
                 if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
                     $url->add('display_cal', $this->_params['calendar']);
                 }
                 $html .= $url->link(array('title' => sprintf(_("Goto %s"), $dayname))) . $dayname . '</a></strong></td></tr>';
                 $firstevent = false;
                 $firstday = false;
             }
             $html .= '<tr class="linedRow"><td class="text nowrap" valign="top">';
             if ($event_active) {
                 $html .= '<strong>';
             }
             if ($event->isAllDay()) {
                 $time = _("All day");
             } else {
                 $time = $event->start->format($GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:ia') . '-' . $event->end->format($GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:ia');
             }
             $html .= $time;
             if ($event_active) {
                 $html .= '</strong>';
             }
             $html .= '&nbsp;</td>';
             $html .= '<td class="text" valign="top"' . $event->getCSSColors() . '>';
             if ($event_active) {
                 $html .= '<strong>';
             }
             $html .= ' ' . $event->getLink(null, true, null, true, true);
             if ($event_active) {
                 $html .= '</strong>';
             }
             $html .= '</td></tr>';
             $totalevents++;
         }
     }
     if (empty($html)) {
         return '<em>' . _("No events to display") . '</em>';
     }
     return '<table cellspacing="0" width="100%">' . $html . '</table>';
 }
예제 #8
0
 /**
  */
 protected function _content()
 {
     global $page_output;
     $page_output->addScriptFile('tooltips.js', 'horde');
     $now = new Horde_Date($_SERVER['REQUEST_TIME']);
     $today = date('j');
     $current_month = '';
     $startDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n'), 'mday' => date('j')));
     $endDate = new Horde_Date(array('year' => date('Y'), 'month' => date('n') + $this->_params['months'], 'mday' => date('j') - 1));
     try {
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             $calendars = Kronolith::listCalendars();
             if (!isset($calendars[$this->_params['calendar']])) {
                 return _("Calendar not found");
             }
             if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
                 return _("Permission Denied");
             }
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true, 'has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
         } else {
             $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS), array('has_alarm' => !empty($this->_params['alarms']), 'cover_dates' => false));
         }
     } catch (Exception $e) {
         return '<em>' . $e->getMessage() . '</em>';
     }
     /* How many days do we need to check. */
     $days = Date_Calc::dateDiff($startDate->mday, $startDate->month, $startDate->year, $endDate->mday, $endDate->month, $endDate->year);
     /* Loop through the days. */
     $totalevents = 0;
     $html = '';
     for ($i = 0; $i < $days; ++$i) {
         $day = new Kronolith_Day($startDate->month, $today + $i);
         $date_stamp = $day->dateString();
         if (empty($all_events[$date_stamp])) {
             continue;
         }
         if (!empty($this->_params['maxevents']) && $totalevents >= $this->_params['maxevents']) {
             break;
         }
         /* Output month header. */
         if ($current_month != $day->month) {
             $html .= '<tr><td colspan="4" class="control"><strong>' . $day->strftime('%B') . '</strong></td></tr>';
         }
         $firstevent = true;
         $tomorrow = $day->getTomorrow();
         foreach ($all_events[$date_stamp] as $event) {
             $isMultiDay = false;
             if ($event->start->compareDate($day) < 0) {
                 $event->start = new Horde_Date($day);
             }
             if ($event->end->compareDate($tomorrow) >= 1) {
                 $isMultiDay = true;
             }
             if ($event->end->compareDate($now) < 0 && !$event->isAllDay() || !empty($this->_params['alarms']) && !$event->alarm) {
                 continue;
             }
             if ($firstevent || $isMultiDay) {
                 $html .= '<tr';
                 if ($current_month == $day->month) {
                     $html .= ' class="upcomingday"';
                 }
                 $html .= '><td class="text" valign="top" align="right"><strong>';
                 if ($day->isToday()) {
                     $html .= _("Today");
                 } elseif ($day->isTomorrow()) {
                     $html .= _("Tomorrow");
                 } else {
                     $html .= $day->mday;
                 }
                 if ($isMultiDay) {
                     $endDay = new Kronolith_Day($event->end->month, $event->end->mday);
                     $html .= ' - ';
                     if ($endDay->isTomorrow()) {
                         $html .= _("Tomorrow");
                     } else {
                         $html .= $event->end->mday;
                     }
                 }
                 $html .= '</strong>&nbsp;</td>';
                 $firstevent = $isMultiDay;
             } else {
                 $html .= '<tr><td class="text">&nbsp;</td>';
             }
             $html .= '<td class="text" nowrap="nowrap" valign="top">';
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '<strong>' . htmlspecialchars($event->getLocation()) . '</strong>';
             } else {
                 $html .= htmlspecialchars($event->getLocation());
             }
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '<strong>';
             }
             $html .= $event->getLink(null, true, null, true);
             if ($event->start->compareDate($now) < 0 && $event->end->compareDate($now) > 0) {
                 $html .= '</strong>';
             }
             $html .= '</td></tr>';
             $totalevents++;
         }
         $current_month = $day->strftime('%m');
     }
     if (empty($html)) {
         return '<em>' . _("No events to display") . '</em>';
     }
     return '<table cellspacing="0" width="100%">' . $html . '</table>';
 }
예제 #9
0
파일: Month.php 프로젝트: horde/horde
 /**
  */
 protected function _content()
 {
     global $prefs;
     if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
         $calendars = Kronolith::listCalendars();
         if (!isset($calendars[$this->_params['calendar']])) {
             return _("Calendar not found");
         }
         if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
             return _("Permission Denied");
         }
     }
     $year = date('Y');
     $month = date('m');
     $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $year));
     $startday = $startday->dayOfWeek();
     if (!$prefs->getValue('week_start_monday')) {
         $startOfView = 1 - $startday;
         $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $year), 'month' => $month, 'year' => $year));
     } else {
         if ($startday == Horde_Date::DATE_SUNDAY) {
             $startOfView = -5;
         } else {
             $startOfView = 2 - $startday;
         }
     }
     $startDate = new Horde_Date($year, $month, $startOfView);
     $endDate = new Horde_Date($year, $month, Horde_Date_Utils::daysInMonth($month, $year) + 1);
     $endDate->mday += (7 - ($endDate->format('w') - $prefs->getValue('week_start_monday'))) % 7;
     /* Table start. and current month indicator. */
     $html = '<table cellspacing="1" class="monthgrid" width="100%"><tr>';
     /* Set up the weekdays. */
     $weekdays = array(_("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa"));
     if (!$prefs->getValue('week_start_monday')) {
         array_unshift($weekdays, _("Su"));
     } else {
         $weekdays[] = _("Su");
     }
     foreach ($weekdays as $weekday) {
         $html .= '<th class="item">' . $weekday . '</th>';
     }
     try {
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true));
         } else {
             $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS));
         }
     } catch (Exception $e) {
         return '<em>' . $e->getMessage() . '</em>';
     }
     $weekday = 0;
     $week = -1;
     $weekStart = $prefs->getValue('week_start_monday');
     for ($date_ob = new Kronolith_Day($month, $startOfView, $year); $date_ob->compareDate($endDate) < 0; $date_ob->mday++) {
         if ($weekday == 7) {
             $weekday = 0;
         }
         if ($weekday == 0) {
             ++$week;
             $html .= '</tr><tr>';
         }
         if ($date_ob->isToday()) {
             $td_class = 'kronolith-today';
         } elseif ($date_ob->month != $month) {
             $td_class = 'kronolith-othermonth';
         } elseif ($date_ob->dayOfWeek() == 0 || $date_ob->dayOfWeek() == 6) {
             $td_class = 'kronolith-weekend';
         } else {
             $td_class = '';
         }
         $html .= '<td align="center" class="' . $td_class . '">';
         /* Set up the link to the day view. */
         $url = Horde::url('day.php', true)->add('date', $date_ob->dateString());
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             $url->add('display_cal', $this->_params['calendar']);
         }
         $date_stamp = $date_ob->dateString();
         if (empty($all_events[$date_stamp])) {
             /* No events, plain link to the day. */
             $cell = Horde::linkTooltip($url, _("View Day")) . $date_ob->mday . '</a>';
         } else {
             /* There are events; create a cell with tooltip to
              * list them. */
             $day_events = '';
             foreach ($all_events[$date_stamp] as $event) {
                 if ($event->isAllDay()) {
                     $day_events .= _("All day");
                 } else {
                     $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p');
                 }
                 $location = $event->getLocation();
                 $day_events .= ':' . ($location ? ' (' . htmlspecialchars($location) . ')' : '') . ' ' . $event->getTitle() . "\n";
             }
             $cell = Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date_ob->mday . '</a>';
         }
         /* Bold the cell if there are events. */
         if (!empty($all_events[$date_stamp])) {
             $cell = '<strong>' . $cell . '</strong>';
         }
         $html .= $cell . '</td>';
         ++$weekday;
     }
     return $html . '</tr></table>';
 }
예제 #10
0
파일: Month.php 프로젝트: DSNS-LAB/Dmail
 /**
  *
  * @global Horde_Prefs $prefs
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Month
  */
 public function __construct(Horde_Date $date)
 {
     global $prefs;
     $this->month = $date->month;
     $this->year = $date->year;
     // Need to calculate the start and length of the view.
     $this->date = new Horde_Date($date);
     $this->date->mday = 1;
     $this->_startday = $this->date->dayOfWeek();
     $this->_daysInView = Date_Calc::weeksInMonth($this->month, $this->year) * 7;
     if (!$prefs->getValue('week_start_monday')) {
         $this->_startOfView = 1 - $this->_startday;
         // We may need to adjust the number of days in the view if
         // we're starting weeks on Sunday.
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView -= 7;
         }
         $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($this->month, $this->year), 'month' => $this->month, 'year' => $this->year));
         $endday = $endday->dayOfWeek();
         if ($endday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView += 7;
         }
     } else {
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_startOfView = -5;
         } else {
             $this->_startOfView = 2 - $this->_startday;
         }
     }
     $startDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView));
     $endDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView + $this->_daysInView));
     if ($prefs->getValue('show_shared_side_by_side')) {
         $allCalendars = Kronolith::listInternalCalendars();
         $this->_currentCalendars = array();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $id) {
             $this->_currentCalendars[$id] = $allCalendars[$id];
         }
     } else {
         $this->_currentCalendars = array('internal_0' => true);
     }
     try {
         $this->_events = Kronolith::listEvents($startDate, $endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }