![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00014 class Dataface_Ontology_Event extends Dataface_Ontology { 00015 function buildAttributes(){ 00016 $this->fieldnames = array(); 00017 $this->attributes = array(); 00018 00019 $date = null; 00020 $start = null; 00021 $end = null; 00022 $location = null; 00023 $category = null; 00024 $allday = null; 00025 00026 // First let's find the email field. 00027 00028 // First we'll check to see if any fields have been explicitly 00029 // flagged as email address fields. 00030 foreach ( $this->table->fields(false,true) as $field ){ 00031 if ( @$field['event.date'] ){ 00032 $date = $field['name']; 00033 00034 } 00035 if ( @$field['event.start'] ){ 00036 $start = $field['name']; 00037 00038 } 00039 if ( @$field['event.end'] ){ 00040 $end = $field['name']; 00041 } 00042 if ( @$field['event.location'] ){ 00043 $location = $field['name']; 00044 } 00045 if ( @$field['event.category'] ){ 00046 $category = $field['name']; 00047 } 00048 00049 if ( @$field['event.allday'] ){ 00050 $allday = $field['name']; 00051 } 00052 } 00053 00054 if ( !isset($date) ){ 00055 // Next lets see if any of the fields actually contain the word 00056 // email in the name 00057 $candidates = preg_grep('/(date)/i', array_keys($this->table->fields(false,true))); 00058 foreach ( $candidates as $candidate ){ 00059 if ( $this->table->isDate($candidate) ){ 00060 $date = $candidate; 00061 break; 00062 } 00063 } 00064 } 00065 00066 if ( !isset($start) ){ 00067 // Next lets see if any of the fields actually contain the word 00068 // email in the name 00069 $candidates = preg_grep('/(time|start)/i', array_keys($this->table->fields(false,true))); 00070 foreach ( $candidates as $candidate ){ 00071 if ( $this->table->isDate($candidate) ){ 00072 $start = $candidate; 00073 break; 00074 } 00075 } 00076 } 00077 00078 if ( !isset($end) ){ 00079 // Next lets see if any of the fields actually contain the word 00080 // email in the name 00081 $candidates = preg_grep('/(time|end)/i', array_keys($this->table->fields(false,true))); 00082 foreach ( $candidates as $candidate ){ 00083 if ( $this->table->isDate($candidate) ){ 00084 $end = $candidate; 00085 break; 00086 } 00087 } 00088 } 00089 00090 if ( !isset($location) ){ 00091 // Next lets see if any of the fields actually contain the word 00092 // email in the name 00093 $candidates = preg_grep('/(location|place|addr|venue)/i', array_keys($this->table->fields(false,true))); 00094 foreach ( $candidates as $candidate ){ 00095 if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){ 00096 if ( $this->table->isInt($candidate) ){ 00097 $field =& $this->table->getField($candidate); 00098 if ( @$field['vocabulary'] ){ 00099 $location = $candidate; 00100 break; 00101 } 00102 } else { 00103 $location = $candidate; 00104 break; 00105 } 00106 } 00107 } 00108 } 00109 00110 if ( !isset($location) ){ 00111 // Next lets see if any of the fields actually contain the word 00112 // email in the name 00113 $candidates = preg_grep('/(cat|type)/i', array_keys($this->table->fields(false,true))); 00114 foreach ( $candidates as $candidate ){ 00115 if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){ 00116 if ( $this->table->isInt($candidate) ){ 00117 $field =& $this->table->getField($candidate); 00118 if ( @$field['vocabulary'] ){ 00119 $category = $candidate; 00120 break; 00121 } 00122 } else { 00123 $category = $candidate; 00124 break; 00125 } 00126 } 00127 } 00128 } 00129 00130 00131 if ( !isset($allday) ){ 00132 // Next lets see if any of the fields actually contain the word 00133 // email in the name 00134 $candidates = preg_grep('/(all|full|todo)/i', array_keys($this->table->fields(false,true))); 00135 foreach ( $candidates as $candidate ){ 00136 if ( in_array($this->table->getType($candidate), array('tinyint','boolean') ) ){ 00137 $allday = $candidate; 00138 break; 00139 00140 } 00141 } 00142 } 00143 00144 00145 $atts = array('date'=>$date, 'start'=>$start, 'end'=>$end, 'location'=>$location, 'category'=>$category, 'allday'=>$allday); 00146 foreach ($atts as $key=>$val ){ 00147 if ( isset($val) ){ 00148 $field =& $this->table->getField($val); 00149 $this->attributes[$key] =& $field; 00150 unset($field); 00151 $this->fieldnames[$key] = $val; 00152 } 00153 } 00154 00155 return true; 00156 00157 } 00158 00159 00160 }