![]() |
Xataface Calendar Module 0.1
Full Calendar for Xataface
|
00001 <?php 00002 class actions_calendar_json_feed { 00003 00004 00005 00006 function handle($params){ 00007 session_write_close(); 00008 header('Connection: close'); 00009 00010 $app = Dataface_Application::getInstance(); 00011 $query = $app->getQuery(); 00012 00013 import('Dataface/Ontology.php'); 00014 00015 Dataface_Ontology::registerType('CalendarEvent', dirname(__FILE__).'/../ontologies/CalendarEvent.php', 'Dataface_Ontology_CalendarEvent'); 00016 $ontology =& Dataface_Ontology::newOntology('CalendarEvent', $query['-table']); 00017 00018 $dateAtt = $ontology->getFieldname('start'); 00019 if ( PEAR::isError($dateAtt) ) die($dateAtt->getMessage()); 00020 00021 $repeatAtt = $ontology->getFieldname('repeat'); 00022 if ( PEAR::isError($repeatAtt) ){ 00023 $repeatAtt = null; 00024 } 00025 00026 $q = $query; 00027 00028 //print_r($query); 00029 00030 $q[$dateAtt] = date('Y-m-d H:i:s', strtotime($query['-calendar-start'])).'..'.date('Y-m-d H:i:s', strtotime($query['-calendar-end'])); 00031 00032 $q['-skip'] =0; 00033 $q['-limit'] = 500; 00034 //print_r($q);exit; 00035 00036 00037 00038 $records =& df_get_records_array($query['-table'], $q); 00039 $out = array(); 00040 if ( $records ){ 00041 $del = $records[0]->table()->getDelegate(); 00042 $getColorExists = (isset($del) and method_exists($del, 'getColor')); 00043 $getBgColorExists = (isset($del) and method_exists($del, 'getBgColor')); 00044 00045 } 00046 foreach ($records as $r){ 00047 if ( !$r->checkPermission('view') ) continue; 00048 $i = $ontology->newIndividual($r); 00049 $starttime = $i->strval('start'); 00050 $endtime = $i->strval('end'); 00051 $allDay = intval($i->val('allday')); 00052 00053 //echo "[ALLDAY: ".$allDay.']'; 00054 $startdate = strtotime($starttime); 00055 00056 $enddate = strtotime($endtime); 00057 $evt = array( 00058 'start' => $startdate, 00059 'end'=>$enddate, 00060 'title'=>$r->getTitle(), 00061 'description'=>$r->getDescription(), 00062 'xfid'=>$r->getId(), 00063 'editable'=> $r->checkPermission('edit'), 00064 'repeat'=> ($repeatAtt ? $i->val('repeat') : null), 00065 'allDay'=> $allDay, 00066 'serverOffset'=>intval(date('Z')) 00067 ); 00068 00069 00070 if ( $getColorExists ){ 00071 $color = $del->getColor($r); 00072 if ( $color ){ 00073 $evt['textColor'] = $color; 00074 } 00075 00076 } 00077 if ( $getBgColorExists ){ 00078 $color = $del->getBgColor($r); 00079 if ( $color ) $evt['color'] = $color; 00080 00081 } 00082 00083 00084 00085 00086 $del = $r->table()->getDelegate(); 00087 if ( isset($del) and method_exists($del, 'calendar__decorateEvent') ){ 00088 $del->calendar__decorateEvent($r, $evt); 00089 } 00090 $out[] = $evt; 00091 } 00092 00093 header('Content-type: text/json; charset="'.$app->_conf['oe'].'"'); 00094 echo json_encode(array( 00095 'code'=>200, 00096 'message'=>'success', 00097 'events'=>$out 00098 )); 00099 exit; 00100 00101 } 00102 }