Xataface 2.0
Xataface Application Framework
actions/calendar.php
Go to the documentation of this file.
00001 <?php
00002 class dataface_actions_calendar {
00003         function handle(&$params){
00004                 $app =& Dataface_Application::getInstance();
00005                 $query =& $app->getQuery();
00006                 
00007                 $nav = array(
00008                         'prev'=>array('label'=>null, 'url'=>null),
00009                         'next'=>array('label'=>null, 'url'=>null),
00010                         'current'=>array('label'=>null)
00011                         );
00012                 
00013                 import('Dataface/Ontology.php');
00014                 
00015                 Dataface_Ontology::registerType('Event', 'Dataface/Ontology/Event.php', 'Dataface_Ontology_Event');
00016                 $ontology =& Dataface_Ontology::newOntology('Event', $query['-table']);
00017                 
00018                 $dateAtt = $ontology->getFieldname('date');
00019                 if ( PEAR::isError($dateAtt) ) die($dateAtt->getMessage());
00020                 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]) ){
00021                         $query[$dateAtt] = date('Y-m-01').'..'.date('Y-m-31');
00022                         
00023                 }
00024                 
00025                 list($startDate) = explode('..',$query[$dateAtt]);
00026                 $startTime = strtotime($startDate);
00027                 $prevMonth = (intval(date('m', $startTime)) -1 );
00028                 $nextMonth = (intval(date('m', $startTime)) +1 );
00029                 
00030                 $prevTime = mktime(0,0,0,$prevMonth,1,date('Y', $startTime));
00031                 $nextTime = mktime(0,0,0,$nextMonth,1,date('Y', $startTime));
00032                 
00033                 $nav['prev']['label'] = date('F Y', $prevTime);
00034                 $nav['prev']['url'] = $app->url('-action=calendar&'.$dateAtt.'='.urlencode(date('Y-m-01',$prevTime).'..'.date('Y-m-31', $prevTime)), true, true);
00035                 
00036                 $nav['next']['label'] = date('F Y', $nextTime);
00037                 $nav['next']['url'] = $app->url('-action=calendar&'.$dateAtt.'='.urlencode(date('Y-m-01',$nextTime).'..'.date('Y-m-31', $nextTime)), true, true);
00038                 
00039                 $nav['current']['label'] = date('F Y', $startTime);
00040                 
00041                 $query['-limit'] = 500;
00042                 
00043                 $records =& df_get_records_array($query['-table'], $query);
00044                 
00045                 $events = array();
00046                 foreach ( $records as $record){
00047                         $event = $ontology->newIndividual($record);
00048                         $datems = strtotime(date('Y-m-d', strtotime($event->strval('date'))))*1000;
00049                         $timems = (strtotime(date('H:i:s', strtotime($event->strval('start')))) - strtotime(date('Y-m-d')))*1000;
00050                         
00051                         $events[] = array('title'=>$record->getTitle(), 'description'=>$record->getDescription(), 'date'=>$datems+$timems, 'startTime'=>strtotime($event->strval('date'))*1000, 'record_id'=>$record->getId());
00052                         
00053                         unset($event);
00054                         unset($record);
00055                 }
00056                 
00057                 import('Services/JSON.php');
00058                 $json = new Services_JSON();
00059                 $event_data = 'var events = '.$json->encode($events);
00060                 
00061                 import('Dataface/ResultList.php');
00062                 $rs = new Dataface_ResultList($query['-table']);
00063                 
00064                 
00065                 df_display(array('event_data'=>$event_data,'nav'=>&$nav, 'currentTime'=>$startTime, 'filters'=>$rs->getResultFilters()), 'Dataface_Calendar.html');
00066         }
00067 
00068 }
 All Data Structures Namespaces Files Functions Variables Enumerations