* @author Jan Schneider * @package Kronolith */ class Kronolith_View_Year { public $year; protected $_events = array(); /** * * @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(); } } public function html() { global $prefs; $html = ''; for ($month = 1; $month <= 12; ++$month) { $html .= ''; if ($month % 3 == 0 && $month != 12) { $html .= ''; } } echo $html . '
'; // Heading for each month. $date = new Horde_Date(sprintf('%04d%02d01010101', $this->year, $month)); $html .= ''; if (!$prefs->getValue('week_start_monday')) { $html .= ''; } $html .= '' . '' . '' . '' . '' . ''; if ($prefs->getValue('week_start_monday')) { $html .= ''; } $html .= '\n'; } if ($date->month != $month) { $style = 'kronolith-other-month'; } else { $style = ''; } /* Set up the link to the day view. */ $url = Horde::url('day.php', true) ->add('date', $date->dateString()); if ($date->month == $month && !empty($this->_events[$date->dateString()])) { /* There are events; create a cell with tooltip to list * them. */ $day_events = ''; foreach ($this->_events[$date->dateString()] as $event) { if ($event->status == Kronolith::STATUS_CONFIRMED) { /* Set the background color to distinguish the * day */ $style = 'year-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'); } $day_events .= ':' . ($event->getLocation() ? ' (' . $event->getLocation() . ')' : '') . ' ' . $event->getTitle() . "\n"; } /* Bold the cell if there are events. */ $cellday = '' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date->mday . ''; } else { /* No events, plain link to the day. */ $cellday = Horde::linkTooltip($url, _("View Day")) . $date->mday . ''; } if ($date->isToday() && $date->month == $month) { $style .= ' kronolith-today'; } $html .= ''; ++$cell; } } $html .= '
' . Horde::url('month.php')->add('date', $date->dateString())->link() . $date->strftime('%B') . '
 ' . _("Su"). '' . _("Mo") . '' . _("Tu") . '' . _("We") . '' . _("Th") . '' . _("Fr") . '' . _("Sa") . '' . _("Su") . '
'; $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $this->year)); $startday = $startday->dayOfWeek(); $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7; if (!$prefs->getValue('week_start_monday')) { $startOfView = 1 - $startday; // We may need to adjust the number of days in the // view if we're starting weeks on Sunday. if ($startday == Horde_Date::DATE_SUNDAY) { $daysInView -= 7; } $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $this->year), 'month' => $month, 'year' => $this->year)); $endday = $endday->dayOfWeek(); if ($endday == Horde_Date::DATE_SUNDAY) { $daysInView += 7; } } else { if ($startday == Horde_Date::DATE_SUNDAY) { $startOfView = -5; } else { $startOfView = 2 - $startday; } } $currentCalendars = array(true); foreach ($currentCalendars as $id => $cal) { $cell = 0; for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) { $date = new Kronolith_Day($month, $day, $this->year); $date->hour = $prefs->getValue('twentyFour') ? 12 : 6; $week = $date->weekOfYear(); if ($cell % 7 == 0) { if ($cell != 0) { $html .= "
"; } $html .= (int)$date->weekOfYear() . '' . $cellday . '
'; } public function link($offset = 0, $full = false) { return Horde::url('year.php', $full) ->add('date', ($this->year + $offset) . '0101'); } public function getName() { return 'Year'; } }