Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
calendar.php
Go to the documentation of this file.
1 <?php
3  function handle(&$params){
5  $query =& $app->getQuery();
6 
7  $nav = array(
8  'prev'=>array('label'=>null, 'url'=>null),
9  'next'=>array('label'=>null, 'url'=>null),
10  'current'=>array('label'=>null)
11  );
12 
13  import('Dataface/Ontology.php');
14 
15  Dataface_Ontology::registerType('Event', 'Dataface/Ontology/Event.php', 'Dataface_Ontology_Event');
16  $ontology =& Dataface_Ontology::newOntology('Event', $query['-table']);
17 
18  $dateAtt = $ontology->getFieldname('date');
19  if ( PEAR::isError($dateAtt) ) die($dateAtt->getMessage());
20  if ( !isset($query[$dateAtt]) or !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\.\.[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $query[$dateAtt]) ){
21  $query[$dateAtt] = date('Y-m-01').'..'.date('Y-m-32');
22 
23  }
24 
25  list($startDate) = explode('..',$query[$dateAtt]);
26  $startTime = strtotime($startDate);
27  $prevMonth = (intval(date('m', $startTime)) -1 );
28  $nextMonth = (intval(date('m', $startTime)) +1 );
29 
30  $prevTime = mktime(0,0,0,$prevMonth,1,date('Y', $startTime));
31  $nextTime = mktime(0,0,0,$nextMonth,1,date('Y', $startTime));
32 
33  $nav['prev']['label'] = date('F Y', $prevTime);
34  $nav['prev']['url'] = $app->url('-action=calendar&'.$dateAtt.'='.urlencode(date('Y-m-01',$prevTime).'..'.date('Y-m-31', $prevTime)), true, true);
35 
36  $nav['next']['label'] = date('F Y', $nextTime);
37  $nav['next']['url'] = $app->url('-action=calendar&'.$dateAtt.'='.urlencode(date('Y-m-01',$nextTime).'..'.date('Y-m-31', $nextTime)), true, true);
38 
39  $nav['current']['label'] = date('F Y', $startTime);
40 
41  $query['-limit'] = 500;
42 
43  $records =& df_get_records_array($query['-table'], $query);
44 
45  $events = array();
46  foreach ( $records as $record){
47  $event = $ontology->newIndividual($record);
48  $datems = strtotime(date('Y-m-d', strtotime($event->strval('date'))))*1000;
49  $timems = (strtotime(date('H:i:s', strtotime($event->strval('start')))) - strtotime(date('Y-m-d')))*1000;
50 
51  $events[] = array('title'=>$record->getTitle(), 'description'=>$record->getDescription(), 'date'=>$datems+$timems, 'startTime'=>strtotime($event->strval('date'))*1000, 'record_id'=>$record->getId());
52 
53  unset($event);
54  unset($record);
55  }
56 
57  import('Services/JSON.php');
58  $json = new Services_JSON();
59  $event_data = 'var events = '.$json->encode($events);
60 
61  import('Dataface/ResultList.php');
62  $rs = new Dataface_ResultList($query['-table']);
63 
64 
65  df_display(array('event_data'=>$event_data,'nav'=>&$nav, 'currentTime'=>$startTime, 'filters'=>$rs->getResultFilters()), 'Dataface_Calendar.html');
66  }
67 
68 }