Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Event.php
Go to the documentation of this file.
1 <?php
15  function buildAttributes(){
16  $this->fieldnames = array();
17  $this->attributes = array();
18 
19  $date = null;
20  $start = null;
21  $end = null;
22  $location = null;
23  $category = null;
24  $allday = null;
25 
26  // First let's find the email field.
27 
28  // First we'll check to see if any fields have been explicitly
29  // flagged as email address fields.
30  foreach ( $this->table->fields(false,true) as $field ){
31  if ( @$field['event.date'] ){
32  $date = $field['name'];
33 
34  }
35  if ( @$field['event.start'] ){
36  $start = $field['name'];
37 
38  }
39  if ( @$field['event.end'] ){
40  $end = $field['name'];
41  }
42  if ( @$field['event.location'] ){
43  $location = $field['name'];
44  }
45  if ( @$field['event.category'] ){
46  $category = $field['name'];
47  }
48 
49  if ( @$field['event.allday'] ){
50  $allday = $field['name'];
51  }
52  }
53 
54  if ( !isset($date) ){
55  // Next lets see if any of the fields actually contain the word
56  // email in the name
57  $candidates = preg_grep('/(date)/i', array_keys($this->table->fields(false,true)));
58  foreach ( $candidates as $candidate ){
59  if ( $this->table->isDate($candidate) ){
60  $date = $candidate;
61  break;
62  }
63  }
64  }
65 
66  if ( !isset($start) ){
67  // Next lets see if any of the fields actually contain the word
68  // email in the name
69  $candidates = preg_grep('/(time|start)/i', array_keys($this->table->fields(false,true)));
70  foreach ( $candidates as $candidate ){
71  if ( $this->table->isDate($candidate) ){
72  $start = $candidate;
73  break;
74  }
75  }
76  }
77 
78  if ( !isset($end) ){
79  // Next lets see if any of the fields actually contain the word
80  // email in the name
81  $candidates = preg_grep('/(time|end)/i', array_keys($this->table->fields(false,true)));
82  foreach ( $candidates as $candidate ){
83  if ( $this->table->isDate($candidate) ){
84  $end = $candidate;
85  break;
86  }
87  }
88  }
89 
90  if ( !isset($location) ){
91  // Next lets see if any of the fields actually contain the word
92  // email in the name
93  $candidates = preg_grep('/(location|place|addr|venue)/i', array_keys($this->table->fields(false,true)));
94  foreach ( $candidates as $candidate ){
95  if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){
96  if ( $this->table->isInt($candidate) ){
97  $field =& $this->table->getField($candidate);
98  if ( @$field['vocabulary'] ){
99  $location = $candidate;
100  break;
101  }
102  } else {
103  $location = $candidate;
104  break;
105  }
106  }
107  }
108  }
109 
110  if ( !isset($location) ){
111  // Next lets see if any of the fields actually contain the word
112  // email in the name
113  $candidates = preg_grep('/(cat|type)/i', array_keys($this->table->fields(false,true)));
114  foreach ( $candidates as $candidate ){
115  if ( in_array($this->table->getType($candidate), array('enum','varchar','char','int') ) ){
116  if ( $this->table->isInt($candidate) ){
117  $field =& $this->table->getField($candidate);
118  if ( @$field['vocabulary'] ){
119  $category = $candidate;
120  break;
121  }
122  } else {
123  $category = $candidate;
124  break;
125  }
126  }
127  }
128  }
129 
130 
131  if ( !isset($allday) ){
132  // Next lets see if any of the fields actually contain the word
133  // email in the name
134  $candidates = preg_grep('/(all|full|todo)/i', array_keys($this->table->fields(false,true)));
135  foreach ( $candidates as $candidate ){
136  if ( in_array($this->table->getType($candidate), array('tinyint','boolean') ) ){
137  $allday = $candidate;
138  break;
139 
140  }
141  }
142  }
143 
144 
145  $atts = array('date'=>$date, 'start'=>$start, 'end'=>$end, 'location'=>$location, 'category'=>$category, 'allday'=>$allday);
146  foreach ($atts as $key=>$val ){
147  if ( isset($val) ){
148  $field =& $this->table->getField($val);
149  $this->attributes[$key] =& $field;
150  unset($field);
151  $this->fieldnames[$key] = $val;
152  }
153  }
154 
155  return true;
156 
157  }
158 
159 
160 }