Xataface Calendar Module 0.1
Full Calendar for Xataface
/Applications/XAMPP/xamppfiles/htdocs/nanofabrication/modules/calendar/ontologies/CalendarEvent.php
Go to the documentation of this file.
00001 <?php
00014 class Dataface_Ontology_CalendarEvent extends Dataface_Ontology {
00015         function buildAttributes(){
00016                 $this->fieldnames = array();
00017                 $this->attributes = array();
00018                 
00019                 $start = null;
00020                 $end = null;
00021                 $location = null;
00022                 $category = null;
00023                 $allday = null;
00024                 $repeat = null;
00025                 $repeat_seed = null;
00026                 
00027                 // First let's find the email field.
00028                 
00029                 // First we'll check to see if any fields have been explicitly 
00030                 // flagged as email address fields.
00031                 foreach ( $this->table->fields(false,true) as $field ){
00032                         if ( @$field['event.start'] ){
00033                                 $start = $field['name'];
00034                                 
00035                         }
00036                         if ( @$field['event.end'] ){
00037                                 $end = $field['name'];
00038                         
00039                         }
00040                         if ( @$field['event.location'] ){
00041                                 $location = $field['name'];
00042                         } 
00043                         if ( @$field['event.category'] ){
00044                                 $category = $field['name'];
00045                         }
00046                         
00047                         if ( @$field['event.allday'] ){
00048                                 $allday = $field['name'];
00049                         }
00050                         
00051                         if ( @$field['event.repeat'] ){
00052                                 $repeat = $field['name'];
00053                         }
00054                         
00055                         if ( @$field['event.repeat_seed'] ){
00056                                 $repeat_seed = $field['name'];
00057                         }
00058                         
00059                         
00060                 }
00061                 
00062                 if ( !isset($start) ){
00063                         // Next lets see if any of the fields actually contain the word
00064                         // email in the name
00065                         $candidates = preg_grep('/(date|start|time)/i', array_keys($this->table->fields(false,true)));
00066                         foreach ( $candidates as $candidate ){
00067                                 if ( $this->table->isDate($candidate) ){
00068                                         $start = $candidate;
00069                                         break;
00070                                 }
00071                         }
00072                 }
00073                 
00074                 if ( !isset($end) ){
00075                         // Next lets see if any of the fields actually contain the word
00076                         // email in the name
00077                         $candidates = preg_grep('/(time|end|finish|fin|close|stop|date)/i', array_keys($this->table->fields(false,true)));
00078                         foreach ( $candidates as $candidate ){
00079                                 if ( $this->table->isDate($candidate) ){
00080                                         if ( $candidate == $start ) continue;
00081                                         $end = $candidate;
00082                                         break;
00083                                 }
00084                         }
00085                 }
00086                 
00087                 
00088                 
00089                 if ( !isset($location) ){
00090                         // Next lets see if any of the fields actually contain the word
00091                         // email in the name
00092                         $candidates = preg_grep('/(location|place|addr|venue)/i', array_keys($this->table->fields(false,true)));
00093                         foreach ( $candidates as $candidate ){
00094                                 if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){
00095                                         if ( $this->table->isInt($candidate) ){
00096                                                 $field =& $this->table->getField($candidate);
00097                                                 if ( @$field['vocabulary'] ){
00098                                                         $location = $candidate;
00099                                                         break;
00100                                                 }
00101                                         } else {
00102                                                 $location = $candidate;
00103                                                 break;
00104                                         }
00105                                 }
00106                         }
00107                 }
00108                 
00109                 if ( !isset($category) ){
00110                         // Next lets see if any of the fields actually contain the word
00111                         // email in the name
00112                         $candidates = preg_grep('/(cat|type)/i', array_keys($this->table->fields(false,true)));
00113                         foreach ( $candidates as $candidate ){
00114                                 if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){
00115                                         if ( $this->table->isInt($candidate) ){
00116                                                 $field =& $this->table->getField($candidate);
00117                                                 if ( @$field['vocabulary'] ){
00118                                                         $category = $candidate;
00119                                                         break;
00120                                                 }
00121                                         } else {
00122                                                 $category = $candidate;
00123                                                 break;
00124                                         }
00125                                 }
00126                         }
00127                 }
00128                 
00129                 
00130                 if ( !isset($allday) ){
00131                         // Next lets see if any of the fields actually contain the word
00132                         // email in the name
00133                         $candidates = preg_grep('/(all|full|todo)/i', array_keys($this->table->fields(false,true)));
00134                         foreach ( $candidates as $candidate ){
00135                                 if ( in_array($this->table->getType($candidate), array('tinyint','boolean') ) ){
00136                                         $allday = $candidate;
00137                                         break;
00138                                         
00139                                 }
00140                         }
00141                 }
00142                 
00143                 
00144                 if ( !isset($repeat) ){
00145                         // Next lets see if any of the fields actually contain the word
00146                         // email in the name
00147                         $candidates = preg_grep('/(repeat|recurr|)/i', array_keys($this->table->fields(false,true)));
00148                         foreach ( $candidates as $candidate ){
00149                                 if ( in_array($this->table->getType($candidate), array('int','mediumint') ) ){
00150                                         $repeat = $candidate;
00151                                         break;
00152                                         
00153                                 }
00154                         }
00155                 }
00156                 
00157                 if ( !isset($repeat_seed) ){
00158                         $repeat_seed = $this->table->getAutoIncrementField();
00159                         
00160                 }
00161                 if ( !isset($repeat_seed) ){
00162                         $keys = array_keys($this->table->keys());
00163                         if ( !isset($keys[1]) and $this->table->isInt($keys[0]) ){
00164                                 $repeat_seed = $keys[0];
00165                         }
00166                 }
00167                 
00168                 $atts = array('start'=>$start, 'end'=>$end, 'location'=>$location, 'category'=>$category, 'allday'=>$allday, 'repeat'=>$repeat, 'repeat_seed'=>$repeat_seed);
00169                 foreach ($atts as $key=>$val ){
00170                         if ( isset($val) ){
00171                                 $field =& $this->table->getField($val);
00172                                 $this->attributes[$key] =& $field;
00173                                 unset($field);
00174                                 $this->fieldnames[$key] = $val;
00175                         }
00176                 }
00177                 
00178                 return true;
00179                 
00180         }
00181         
00182         
00183 }
 All Data Structures Files Functions Variables