[kronolith] Alternate views
Chuck Hagenbuch
chuck at horde.org
Tue Jul 15 03:19:25 UTC 2008
Quoting Elliot Anders <elliot at marlboro.edu>:
> I have need of an alternate view of a kronolith calendar. I need an
> academic year view that lists all event titles, a group of month
> views would probably suffice.
>
> Is there documentation anywhere for developing new views?
> Has anyone done this yet?
> How hard is it to build a new view?
There isn't really documentation, but it's pretty easy. Here's most of
the code to do one for generating the event list for a given week. You
can just modify the dates passed to Kronolith::listEvents(): (this
particular one builds a CSV)
@define('KRONOLITH_BASE', dirname(__FILE__));
require_once KRONOLITH_BASE . '/lib/base.php';
require_once 'Horde/Data.php';
$calendars = array(...); // list the calendar ids you want to include
$month = Util::getFormData('month', date('n'));
$mday = Util::getFormData('mday', date('j'));
$year = Util::getFormData('year', date('Y'));
$date = new Horde_Date(array('month' => $month, 'year' => $year,
'mday' => $mday));
$date->correct();
$week = $date->weekOfYear();
if ($date->dayOfWeek() == HORDE_DATE_SUNDAY) {
++$week;
}
if ($week == 1 && $month == 12) {
++$year;
}
$firstDay = Horde_Date::firstDayOfWeek($week, $year) +
Date_Calc::dateToDays(1, 1, $year) - 1;
list($sday, $smonth, $syear) = explode('/',
Date_Calc::daysToDate($firstDay, '%d/%m/%Y'));
list($eday, $emonth, $eyear) = explode('/',
Date_Calc::daysToDate($firstDay + 7, '%d/%m/%Y'));
$startDate = new Horde_Date(array('year' => $syear, 'month' =>
$smonth, 'mday' => $sday));
$endDate = new Horde_Date(array('year' => $eyear, 'month' => $emonth,
'mday' => $eday,
'hour' => 23, 'min' => 59, 'sec' => 59));
$endDate->correct();
if (Util::getFormData('download')) {
$events = Kronolith::listEvents($startDate, $endDate, $calendars);
$rows = array();
$days = array();
for ($i = 0; $i <= 7; $i++) {
list($mday, $month, $year) = explode('/',
Date_Calc::daysToDate($firstDay + $i, '%d/%m/%Y'));
$day = new Horde_Date(array('month' => $month, 'year' =>
$year, 'mday' => $mday));
$rows[] = array(date('l n/j/y', $day->timestamp()), '',
'Category', '', '');
if (isset($events[$day->timestamp()])) {
foreach ($events[$day->timestamp()] as $devent) {
$rows[] = array(
date('g:i A', $devent->start->timestamp()),
'',
$devent->category,
'',
$devent->title . ($devent->location ? ' (' .
$devent->location . ')' : ''),
);
}
}
$rows[] = array('', '', '', '', '');
}
array_pop($rows);
$csv = Horde_Data::factory('csv');
$csv->exportFile(_("week.csv"), $rows);
exit;
}
-chuck
More information about the kronolith
mailing list