Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
RecordView.php
Go to the documentation of this file.
1 <?php
2 import('Dataface/GlanceList.php');
4  var $record;
5 
7  var $sidebars;
8  var $sections;
9  var $logos;
11  var $status;
12  var $showLogo = false; // Whether or not to show the logo spot
13 
15 
16  $this->record =& $record;
17  $tablename = $this->record->_table->tablename;
19  $query =& $app->getQuery();
20 
21  $collapseAll = false;
22  $expandAll = false;
23  $collapsedSections = array();
24  $expandedSections = array();
25  if ( @$query['--collapse-all'] ) $collapseAll = true;
26  if ( @$query['--expand-all'] ) $expandAll=true;
27  if ( @$query['--collapsed-sections'] ) $collapsedSections = array_flip(explode(',', $query['--collapsed-sections']));
28  if ( @$query['--expanded-sections'] ) $expandedSections = array_flip(explode(',', $query['--expanded-sections']));
29 
30 
31  $fields = $this->record->_table->fields(false,true);
32 
33  // Now get defined sidebars in the delegate class.
34  $this->sidebars = array();
35  $this->sections = array();
36 
37  $this->description = $record->getDescription();
38  if ( intval($record->getLastModified()) > 0 ){
39  $this->status = "Last updated ".df_offset(date('Y-m-d H:i:s',intval($record->getLastModified())));
40  } else {
41  $this->status = '';
42  }
43 
44  import('Dataface/PreferencesTool.php');
46 
47  $prefs =& $pt->getPreferences($record->getId());
48 
49  $delegate =& $this->record->_table->getDelegate();
50  if ( isset($delegate) ){
51  $delegate_methods = get_class_methods(get_class($delegate));
52  $delegate_sidebars = preg_grep('/^sidebar__/', $delegate_methods);
53  $delegate_fields = preg_grep('/^field__/', $delegate_methods);
54  $delegate_sections = preg_grep('/^section__/', $delegate_methods);
55 
56 
57  foreach ($delegate_fields as $dfield){
58  $dfieldname = substr($dfield,7);
59  $fields[$dfieldname] = $this->record->_table->_newSchema('varchar(32)', $dfieldname);
60  $fields[$dfieldname]['visibility']['browse'] = 'hidden';
61  if ( isset($this->record->_table->_atts[$dfieldname]) and
62  is_array($this->record->_table->_atts[$dfieldname]) ){
63  $this->record->_table->_parseINISection($this->record->_table->_atts[$dfieldname], $fields[$dfieldname]);
64 
65  }
66 
67 
68  }
69 
70  foreach ( $delegate_sidebars as $sb ){
71  $this->sidebars[] = $delegate->$sb($this->record);
72  }
73 
74  foreach ( $delegate_sections as $sec ){
75  $secobj = $delegate->$sec($this->record);
76  if ( !isset($secobj['name']) ){
77  $secobj['name'] = substr($sec,9);
78  }
79 
80  if ( isset($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.order']) ){
81  $secobj['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.order']);
82  }
83 
84 
85  if ( isset($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.display']) ){
86 
87  $secobj['display'] = $prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.display'];
88  } else {
89  $secobj['display'] = 'expanded';
90  }
91 
92  if ( $expandAll ) $secobj['display'] = 'expanded';
93  if ( $collapseAll ) $secobj['display'] = 'collapsed';
94  if ( isset($collapsedSections[$secobj['name']]) ) $secobj['display'] = 'collapsed';
95  if ( isset($expandedSections[$secobj['name']]) ) $secobj['display'] = 'expanded';
96 
97 
98  $this->sections[] =& $secobj;
99  unset($secobj);
100  }
101 
102  }
103 
104 
105 
106  // build the field groups
107  $this->fieldgroups = array();
108  $this->logos = array();
109 
110 
111 
112  foreach ( $fields as $field ){
113 
114  if ( !$record->checkPermission('view', array('field'=>$field['name']))){
115  continue;
116  }
117  if ( $record->_table->isMetaField($field['name']) ) continue;
118 
119  if ( !@$app->prefs['hide_record_view_logo'] ){
120  if ( ($record->isImage($field['name']) and @$field['logo'] !== '0') or @$field['logo']) {
121  $this->showLogo = true;
122 
123  if ( !isset($field['width']) ) {
124  if ( isset($this->record->_table->_fields[$field['name']]) ){
125  $this->record->_table->_fields[$field['name']]['width'] = 225;
126  } else {
127  $this->record->_table->_atts[$field['name']]['width'] = 225;
128  }
129 
130  }
131  $this->logos[] = $field;
132  continue;
133 
134  } else if ( @$field['image'] ){
135  $this->logos[] = $field;
136  $this->showLogo = true;
137  }
138  }
139  if ( $field['visibility']['browse'] == 'hidden' ) continue;
140 
141  if ( isset($field['viewgroup']) ){
142  $group = $field['viewgroup'];
143 
144  } else if ( isset($field['group']) ){
145  $group = $field['group'];
146  } else {
147  $group = '__main__';
148  }
149  if ( !isset($this->fieldgroups[$group]) ){
150  $this->fieldgroups[$group][$field['name']] = $field;
151  $fldgrp =& $this->record->_table->getFieldGroup($group);
152  $class = 'main';
153  if ( PEAR::isError($fldgrp) ){
154  $label = ucwords(str_replace('_',' ',$group));
155  if ( $group == '__main__' ){
156  $label = "Details";
157  if ( @$app->prefs['RecordView.showLastModifiedOnDetails'] ){
158  $label .= ' <span style="color: #666; font-weight: normal; text-style:italic"> - Last modified '.df_offset(date('Y-m-d',$this->record->getLastModified())).'</span>';
159 
160  }
161 
162  }
163  $order = 0;
164  $class = 'main';
165  } else {
166  if ( isset($fldgrp['condition']) and !$app->testCondition($fldgrp['condition'], array('record'=>&$this->record))){
167  continue;
168  }
169 
170  if ( isset($fldgrp['permission']) and !$record->checkPermission($fldgrp['permission']) ){
171  continue;
172  }
173  $label = ucwords(str_replace('_',' ',$fldgrp['label']));
174  if ( isset($fldgrp['section']['order']) ) $order = $fldgrp['section']['order'];
175  else $order = 0;
176  if ( isset($fldgrp['section']['class']) ) $class = $fldgrp['section']['class'];
177  }
178  $sec = array(
179  'name'=>$group.'__fieldgroup',
180  'label'=>$label,
181  'url'=>null,
182  'content'=>null,
183  'fields'=>&$this->fieldgroups[$group],
184  'order'=> $order,
185  'class'=>$class,
186  'display'=>'expanded'
187  );
188 
189  if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']) ){
190  $sec['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']);
191  }
192  if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display']) ){
193  $sec['display'] = $prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display'];
194  }
195 
196  if ( $expandAll ) $sec['display'] = 'expanded';
197  if ( $collapseAll ) $sec['display'] = 'collapsed';
198  if ( isset($collapsedSections[$sec['name']]) ) $sec['display'] = 'collapsed';
199  if ( isset($expandedSections[$sec['name']]) ) $sec['display'] = 'expanded';
200 
201 
202  $this->sections[] =& $sec;
203  unset($sec);
204 
205  unset($fldgrp);
206  } else {
207  $this->fieldgroups[$group][$field['name']] = $field;
208  }
209 
210 
211  }
212  if ( count($this->logos)>1 ){
213  $theLogo = $this->logos[0];
214  if ( !@$theLogo['logo'] ){
215  foreach ($this->logos as $logofield){
216  if ( @$logoField['logo'] ){
217  $theLogo = $logoField;
218  break;
219  }
220  }
221  }
222  $this->logos = array($theLogo);
223  }
224 
225  if ( !@$app->prefs['hide_related_sections'] ){
226  // Create the relationship sections
227  foreach ( $this->record->_table->relationships() as $relname=>$relationship ){
228  $schema =& $relationship->_schema;
229 
230  if ( isset($schema['section']['visible']) and !$schema['section']['visible'] ) continue;
231  if ( isset($schema['section']['condition']) and !$app->testCondition($schema['section']['condition'], array('record'=>&$this->record,'relationship'=>&$relationship))){
232  continue;
233  }
234 
235  if ( isset($schema['action']['condition']) and !$app->testCondition($schema['action']['condition'], array('record'=>&$this->record,'relationship'=>&$relationship))){
236  continue;
237  }
238 
239  if ( isset($schema['action']['permission']) and !$record->checkPermission($schema['action']['permission']) ){
240  continue;
241  }
242 
243  if ( isset($schema['section']['permission']) and !$record->checkPermission($schema['section']['permission']) ){
244  continue;
245  }
246 
247  if ( isset($schema['section']['label']) ) $label = $schema['section']['label'];
248  else if ( isset($schema['action']['label'] )) $label = $schema['action']['label'];
249  else $label = $relname;
250 
251  if ( isset($schema['section']['order']) ) $order = $schema['section']['order'];
252  else if ( isset($schema['action']['order']) ) $order = $schema['action']['order'];
253  else $order = 0;
254 
255  if ( isset($schema['section']['limit']) ) $limit = $schema['section']['limit'];
256  else $limit = 5;
257 
258  if ( isset($schema['section']['sort']) ) $sort = $schema['section']['sort'];
259  else $sort = 0;
260 
261  if ( isset($schema['section']['filter']) ) $filter = $schema['section']['filter'];
262  else $filter = 0;
263 
264  $rrecords = $this->record->getRelatedRecordObjects($relname,0,$limit,$filter,$sort);
265  if ( count($rrecords) == 0 ) continue;
266  $glanceList = new Dataface_GlanceList($rrecords);
267 
268  if ( isset($schema['section']['class']) ) $class = $schema['section']['class'];
269  else $class = 'left';
270 
271 
272  $sec = array(
273  'name'=>$relname.'__relationship',
274  'label'=>$label,
275  'url'=>$this->record->getURL('-action=related_records_list&-relationship='.$relname),
276  'content'=>$glanceList->toHtml(),
277  'order'=>$order,
278  'class'=>$class,
279  'display'=>'expanded'
280  );
281 
282  if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']) ){
283  $sec['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']);
284  }
285 
286  if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display']) ){
287  $sec['display'] = $prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display'];
288  }
289 
290  if ( $expandAll ) $sec['display'] = 'expanded';
291  if ( $collapseAll ) $sec['display'] = 'collapsed';
292  if ( isset($collapsedSections[$sec['name']]) ) $secj['display'] = 'collapsed';
293  if ( isset($expandedSections[$sec['name']]) ) $sec['display'] = 'expanded';
294 
295 
296  $this->sections[] =& $sec;
297 
298  unset($sec);
299  unset($schema);
300  unset($relationship);
301 
302  }
303  }
304 
305 
306  usort($this->sections,array(&$this,'section_cmp'));
307 
308 
309 
310 
311  }
312 
313 
314 
315  function section_cmp($a,$b){
316  $ao = (isset($a['order']) ? $a['order'] : 0);
317  $bo = (isset($b['order']) ? $b['order'] : 0 );
318  return ($ao < $bo) ? -1:1;
319  }
320 
321 
322 }