Xataface 2.0
Xataface Application Framework
Dataface/RecordView.php
Go to the documentation of this file.
00001 <?php
00002 import('Dataface/GlanceList.php');
00003 class Dataface_RecordView {
00004         var $record;
00005         
00006         var $fieldgroups;
00007         var $sidebars;
00008         var $sections;
00009         var $logos;
00010         var $description;
00011         var $status;
00012         var $showLogo = false; // Whether or not to show the logo spot
00013         
00014         function Dataface_RecordView(&$record){
00015 
00016                 $this->record =& $record;
00017                 $tablename = $this->record->_table->tablename;
00018                 $app =& Dataface_Application::getInstance();
00019                 $query =& $app->getQuery();
00020                 
00021                 $collapseAll = false;
00022                 $expandAll = false;
00023                 $collapsedSections = array();
00024                 $expandedSections = array();
00025                 if ( @$query['--collapse-all'] ) $collapseAll = true;
00026                 if ( @$query['--expand-all'] ) $expandAll=true;
00027                 if ( @$query['--collapsed-sections'] ) $collapsedSections = array_flip(explode(',', $query['--collapsed-sections']));
00028                 if ( @$query['--expanded-sections'] ) $expandedSections = array_flip(explode(',', $query['--expanded-sections']));
00029                 
00030                 
00031                 $fields = $this->record->_table->fields(false,true);
00032 
00033                 // Now get defined sidebars in the delegate class.
00034                 $this->sidebars = array();
00035                 $this->sections = array();
00036                 
00037                 $this->description = $record->getDescription();
00038                 if ( intval($record->getLastModified()) > 0 ){
00039                         $this->status = "Last updated ".df_offset(date('Y-m-d H:i:s',intval($record->getLastModified())));
00040                 } else {
00041                         $this->status = '';
00042                 }
00043                 
00044                 import('Dataface/PreferencesTool.php');
00045                 $pt =& Dataface_PreferencesTool::getInstance();
00046 
00047                 $prefs =& $pt->getPreferences($record->getId());
00048                 
00049                 $delegate =& $this->record->_table->getDelegate();
00050                 if ( isset($delegate) ){
00051                         $delegate_methods = get_class_methods(get_class($delegate));
00052                         $delegate_sidebars = preg_grep('/^sidebar__/', $delegate_methods);
00053                         $delegate_fields = preg_grep('/^field__/', $delegate_methods);
00054                         $delegate_sections = preg_grep('/^section__/', $delegate_methods);
00055                         
00056                         
00057                         foreach ($delegate_fields as $dfield){
00058                                 $dfieldname = substr($dfield,7);
00059                                 $fields[$dfieldname] = $this->record->_table->_newSchema('varchar(32)', $dfieldname);
00060                                 $fields[$dfieldname]['visibility']['browse'] = 'hidden';
00061                                 if ( isset($this->record->_table->_atts[$dfieldname]) and 
00062                                          is_array($this->record->_table->_atts[$dfieldname]) ){
00063                                         $this->record->_table->_parseINISection($this->record->_table->_atts[$dfieldname], $fields[$dfieldname]);
00064                                         
00065                                 }
00066                                 
00067                                 
00068                         }
00069                         
00070                         foreach ( $delegate_sidebars as $sb ){
00071                                 $this->sidebars[] = $delegate->$sb($this->record);
00072                         }
00073                         
00074                         foreach ( $delegate_sections as $sec ){
00075                                 $secobj = $delegate->$sec($this->record);
00076                                 if ( !isset($secobj['name']) ){
00077                                         $secobj['name'] = substr($sec,9);
00078                                 }       
00079                                 
00080                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.order']) ){
00081                                         $secobj['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.order']);
00082                                 }
00083                                 
00084                                 
00085                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.display']) ){
00086                         
00087                                         $secobj['display'] = $prefs['tables.'.$tablename.'.sections.'.$secobj['name'].'.display'];
00088                                 } else {
00089                                         $secobj['display'] = 'expanded';
00090                                 }
00091                                 
00092                                 if ( $expandAll ) $secobj['display'] = 'expanded';
00093                                 if ( $collapseAll ) $secobj['display'] = 'collapsed';
00094                                 if ( isset($collapsedSections[$secobj['name']]) ) $secobj['display'] = 'collapsed';
00095                                 if ( isset($expandedSections[$secobj['name']]) ) $secobj['display'] = 'expanded';
00096                                 
00097                                 
00098                                 $this->sections[] =& $secobj;
00099                                 unset($secobj);
00100                         }
00101                         
00102                 }
00103                 
00104                 
00105                 
00106                 // build the field groups
00107                 $this->fieldgroups = array();
00108                 $this->logos = array();
00109 
00110                 
00111                                                   
00112                 foreach ( $fields as $field ){
00113                         
00114                         if ( !$record->checkPermission('view', array('field'=>$field['name']))){
00115                                 continue;
00116                         }
00117                         if ( $record->_table->isMetaField($field['name']) ) continue;
00118                         
00119                         if ( !@$app->prefs['hide_record_view_logo'] ){
00120                                 if ( ($record->isImage($field['name']) and @$field['logo'] !== '0') or @$field['logo']) {
00121                                         $this->showLogo = true;
00122                                         
00123                                         if ( !isset($field['width']) ) {
00124                                                 if ( isset($this->record->_table->_fields[$field['name']]) ){
00125                                                         $this->record->_table->_fields[$field['name']]['width'] = 225;
00126                                                 } else {
00127                                                         $this->record->_table->_atts[$field['name']]['width'] = 225;
00128                                                 }
00129                                                         
00130                                         }
00131                                         $this->logos[] = $field;
00132                                         continue;
00133                                         
00134                                 } else if ( @$field['image'] ){
00135                                         $this->logos[] = $field;
00136                                         $this->showLogo = true;
00137                                 }
00138                         }
00139                         if ( $field['visibility']['browse'] == 'hidden' ) continue;
00140                         
00141                         if ( isset($field['viewgroup']) ){
00142                                 $group = $field['viewgroup'];
00143                                 
00144                         } else if ( isset($field['group']) ){
00145                                 $group = $field['group'];
00146                         } else {
00147                                 $group = '__main__';
00148                         }
00149                         if ( !isset($this->fieldgroups[$group]) ){
00150                                 $this->fieldgroups[$group][$field['name']] = $field;
00151                                 $fldgrp =& $this->record->_table->getFieldGroup($group);
00152                                 $class = 'main';
00153                                 if ( PEAR::isError($fldgrp) ){
00154                                         $label = ucwords(str_replace('_',' ',$group));
00155                                         if ( $group == '__main__' ){
00156                                                 $label = "Details";
00157                                                 if ( @$app->prefs['RecordView.showLastModifiedOnDetails'] ){
00158                                                         $label .= ' <span style="color: #666; font-weight: normal; text-style:italic"> - Last modified '.df_offset(date('Y-m-d',$this->record->getLastModified())).'</span>';
00159                                                         
00160                                                 }
00161                                                 
00162                                         }
00163                                         $order = 0;
00164                                         $class = 'main';
00165                                 } else {
00166                                         if ( isset($fldgrp['condition']) and !$app->testCondition($fldgrp['condition'], array('record'=>&$this->record))){
00167                                                 continue;
00168                                         }
00169                                         
00170                                         if ( isset($fldgrp['permission']) and !$record->checkPermission($fldgrp['permission']) ){
00171                                                 continue;
00172                                         }
00173                                         $label = ucwords(str_replace('_',' ',$fldgrp['label']));
00174                                         if ( isset($fldgrp['section']['order']) ) $order = $fldgrp['section']['order'];
00175                                         else $order = 0;
00176                                         if ( isset($fldgrp['section']['class']) ) $class = $fldgrp['section']['class']; 
00177                                 }
00178                                 $sec = array(
00179                                         'name'=>$group.'__fieldgroup',
00180                                         'label'=>$label,
00181                                         'url'=>null,
00182                                         'content'=>null,
00183                                         'fields'=>&$this->fieldgroups[$group],
00184                                         'order'=> $order,
00185                                         'class'=>$class,
00186                                         'display'=>'expanded'
00187                                         );
00188                                 
00189                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']) ){
00190                                         $sec['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']);
00191                                 }
00192                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display']) ){
00193                                         $sec['display'] = $prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display'];
00194                                 }
00195                                 
00196                                 if ( $expandAll ) $sec['display'] = 'expanded';
00197                                 if ( $collapseAll ) $sec['display'] = 'collapsed';
00198                                 if ( isset($collapsedSections[$sec['name']]) ) $sec['display'] = 'collapsed';
00199                                 if ( isset($expandedSections[$sec['name']]) ) $sec['display'] = 'expanded';
00200                                 
00201                                 
00202                                 $this->sections[] =& $sec;
00203                                 unset($sec);    
00204                                         
00205                                 unset($fldgrp);
00206                         } else {
00207                                 $this->fieldgroups[$group][$field['name']] = $field;
00208                         }
00209                         
00210                                 
00211                 }
00212                 if ( count($this->logos)>1 ){
00213                         $theLogo = $this->logos[0];
00214                         if ( !@$theLogo['logo'] ){
00215                                 foreach ($this->logos as $logofield){
00216                                         if ( @$logoField['logo'] ){
00217                                                 $theLogo = $logoField;
00218                                                 break;
00219                                         }
00220                                 }
00221                         }
00222                         $this->logos = array($theLogo);
00223                 }
00224                 
00225                 if ( !@$app->prefs['hide_related_sections'] ){
00226                         // Create the relationship sections
00227                         foreach ( $this->record->_table->relationships() as $relname=>$relationship ){
00228                                 $schema =& $relationship->_schema;
00229                                 
00230                                 if ( isset($schema['section']['visible']) and !$schema['section']['visible'] ) continue;
00231                                 if ( isset($schema['section']['condition']) and !$app->testCondition($schema['section']['condition'], array('record'=>&$this->record,'relationship'=>&$relationship))){
00232                                         continue;
00233                                 }
00234                                 
00235                                 if ( isset($schema['action']['condition']) and !$app->testCondition($schema['action']['condition'], array('record'=>&$this->record,'relationship'=>&$relationship))){
00236                                         continue;
00237                                 }
00238                                 
00239                                 if ( isset($schema['action']['permission']) and !$record->checkPermission($schema['action']['permission']) ){
00240                                         continue;
00241                                 }
00242                                 
00243                                 if ( isset($schema['section']['permission']) and !$record->checkPermission($schema['section']['permission']) ){
00244                                         continue;       
00245                                 }
00246                                 
00247                                 if ( isset($schema['section']['label']) ) $label = $schema['section']['label'];
00248                                 else if ( isset($schema['action']['label'] )) $label = $schema['action']['label'];
00249                                 else $label = $relname;
00250                                 
00251                                 if ( isset($schema['section']['order']) ) $order = $schema['section']['order'];
00252                                 else if ( isset($schema['action']['order']) ) $order = $schema['action']['order'];
00253                                 else $order = 0;
00254                                 
00255                                 if ( isset($schema['section']['limit']) ) $limit = $schema['section']['limit'];
00256                                 else $limit = 5;
00257                                 
00258                                 if ( isset($schema['section']['sort']) ) $sort = $schema['section']['sort'];
00259                                 else $sort = 0;
00260                                 
00261                                 if ( isset($schema['section']['filter']) ) $filter = $schema['section']['filter'];
00262                                 else $filter = 0;
00263                                 
00264                                 $rrecords = $this->record->getRelatedRecordObjects($relname,0,$limit,$filter,$sort);
00265                                 if ( count($rrecords) == 0 ) continue;
00266                                 $glanceList = new Dataface_GlanceList($rrecords);
00267                                 
00268                                 if ( isset($schema['section']['class']) ) $class = $schema['section']['class'];
00269                                 else $class = 'left';
00270                                 
00271                                 
00272                                 $sec = array(
00273                                         'name'=>$relname.'__relationship',
00274                                         'label'=>$label, 
00275                                         'url'=>$this->record->getURL('-action=related_records_list&-relationship='.$relname), 
00276                                         'content'=>$glanceList->toHtml(),
00277                                         'order'=>$order,
00278                                         'class'=>$class,
00279                                         'display'=>'expanded'
00280                                 );
00281                                 
00282                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']) ){
00283                                         $sec['order'] = intval($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.order']);
00284                                 }
00285                                 
00286                                 if ( isset($prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display']) ){
00287                                         $sec['display'] = $prefs['tables.'.$tablename.'.sections.'.$sec['name'].'.display'];
00288                                 }
00289                                 
00290                                 if ( $expandAll ) $sec['display'] = 'expanded';
00291                                 if ( $collapseAll ) $sec['display'] = 'collapsed';
00292                                 if ( isset($collapsedSections[$sec['name']]) ) $secj['display'] = 'collapsed';
00293                                 if ( isset($expandedSections[$sec['name']]) ) $sec['display'] = 'expanded';
00294                                 
00295                                 
00296                                 $this->sections[] =& $sec;
00297                                 
00298                                 unset($sec);
00299                                 unset($schema);
00300                                 unset($relationship);
00301                         
00302                         }
00303                 }
00304                 
00305 
00306                 usort($this->sections,array(&$this,'section_cmp'));
00307                 
00308                 
00309                 
00310                 
00311         }
00312         
00313         
00314         
00315         function section_cmp($a,$b){
00316                 $ao = (isset($a['order']) ? $a['order'] : 0);
00317                 $bo = (isset($b['order']) ? $b['order'] : 0 );
00318                 return ($ao < $bo) ? -1:1;
00319         }
00320         
00321         
00322 }
 All Data Structures Namespaces Files Functions Variables Enumerations