3 class Calendar_Item extends DatabaseTable {
5 public function __construct($id=false)
7 $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS);
9 parent::__construct('calendar_item', $id, $db, 'dav_id');
12 public static function pgTimestamp($timestamp)
14 if (is_string($timestamp))
16 elseif (is_int($timestamp))
17 return date('Y-m-d H:i:s', $timestamp);
18 elseif (is_object($timestamp) && is_a($timestamp, 'DateTime'))
19 return $timestamp->format('Y-m-d H:i:s');
24 public static function formatTimespan($dtstart, $dtend=false)
26 $start = new DateTime($dtstart);
28 if ($dtend !== false) {
29 $end = new DateTime($dtend);
31 if ($start->format('Y-m-d') == $end->format('Y-m-d')) {
32 if ($start->format('i') == '00' && $end->format('i') == '00')
33 return $start->format('d.m. H') . '-' . $end->format('H') . ' Uhr';
35 return $start->format('d.m. H:i') . '-' . $end->format('H:i');
38 if ($start->format('H:i:s') == '00:00:00' && $end->format('H:i:s') == '00:00:00') {
39 $end->sub(new DateInterval('P1D'));
40 if ($start->format('Y-m-d') == $end->format('Y-m-d'))
41 return $start->format('d.m.');
43 return $start->format('d.m.') . '-' . $end->format('d.m.');
46 if ($start->format('Y-m-') == $end->format('Y-m-')) {
47 return $start->format('d.m. H:i') . '-' . $end->format('d.m. H:i');
54 public function getYears()
56 $sql = sprintf("SELECT DISTINCT extract(year from dtstart) AS year FROM calendar_item WHERE user_no = %d ORDER BY year",
58 return $this->db->fetchObjectList($sql);
61 public function getItems($from=false, $to=false)
63 $sql = sprintf("SELECT dav_id,dtstart,dtend,EXTRACT(WEEK FROM dtstart) AS kw,summary,location,description FROM calendar_item WHERE user_no = %d",
66 $sql .= sprintf(" AND dtstart >= %s", $this->db->quote(self::pgTimestamp($from)));
68 $sql .= sprintf(" AND dtstart <= %s", $this->db->quote(self::pgTimestamp($to)));
70 $sql .= " ORDER BY dtstart";
72 return $this->db->fetchObjectList($sql);