![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 class Dataface_SummaryList { 00003 var $records; 00004 var $table; 00005 function Dataface_SummaryList(&$records){ 00006 $this->records =& $records; 00007 if ( count($this->records) > 0 ) $this->table =& $this->records[0]->_table; 00008 } 00009 00010 function showSummary(&$record){ 00011 $del =& $record->_table->getDelegate(); 00012 if ( isset($del) and method_exists($del, 'showSummary') ){ 00013 return $del->showSummary($record); 00014 } 00015 00016 $app =& Dataface_Application::getInstance(); 00017 $adel =& $app->getDelegate(); 00018 if ( isset($adel) and method_exists($adel, 'showSummary') ){ 00019 return $adel->showSummary($record); 00020 } 00021 00022 // No custom summary defined. We build our own. 00023 // See if there is an image of sorts. 00024 $logoField = $this->getLogoField($record); 00025 $out = '<div class="Dataface_SummaryList-record-summary">'; 00026 if ( $logoField ){ 00027 if ( isset($app->prefs['SummaryList_logo_width']) ) $width = $apps->prefs['SummaryList_logo_width']; 00028 else $width = '60'; 00029 $out .= '<div class="Dataface_SummaryList-record-logo"><a href="'.$record->getURL('-action=view').'" title="Record details"> 00030 <img src="'.$record->display($logoField).'" width="'.htmlspecialchars($width).'"/> 00031 </a> 00032 </div>'; 00033 } 00034 00035 $out .= '<table class="record-view-table"> 00036 <tbody>'; 00037 foreach ( $this->getSummaryColumns($record) as $fieldname){ 00038 $field =& $record->_table->getField($fieldname); 00039 $out .= ' 00040 <tr><th class="record-view-label">'.htmlspecialchars($field['widget']['label']).'</th><td class="record-view-value">'.$record->htmlValue($fieldname).'</td></tr> 00041 '; 00042 } 00043 $out .= ' </tbody></table>'; 00044 00045 //$out .= '<h5 class="Dataface_SummaryList-record-title"><a href="'.$record->getURL('-action=view').'">'.htmlspecialchars($record->callDelegateFunction('summaryTitle',$record->getTitle())).'</a></h5>'; 00046 //$out .= '<div class="Dataface_SummaryList-record-description">'.$record->callDelegateFunction('summaryDescription',$record->getDescription()).'</div>'; 00047 //$out .= ( $record->getLastModified() + $record->getCreated() > 0 ? '<div class="Dataface_SummaryLIst-record-status">'. 00048 // ( $record->getLastModified() > 0 ? '<span class="Dataface_SummaryList-record-last-modified"> 00049 // '.df_translate('scripts.GLOBAL.LABEL_LAST_MODIFIED', 'Last updated '.df_offset(date('Y-m-d H:i:s',intval($record->getLastModified()))), array('last_mod'=>df_offset(date('Y-m-d H:i:s',intval($record->getLastModified()))))).' 00050 // </span>' : ''). 00051 // ( $record->getCreated() > 0 ? 00052 // '<span class="Dataface_SummaryList-record-created">'.df_translate('scripts.GLOBAL.LABEL_DATE_CREATED','Created '.df_offset(date('Y-m-d H:i:s',intval($record->getCreated()))), array('created'=>df_offset(date('Y-m-d H:i:s',intval($record->getCreated()))))).'</span>':'' 00053 // ).' 00054 // </div>': '').' 00055 $out .=' </div>'; 00056 return $out; 00057 00058 } 00059 00060 function getSummaryColumns(&$record){ 00061 $cols = array(); 00062 $count= 0; 00063 foreach ($record->_table->fields(false,true) as $field){ 00064 //print_r($field); 00065 if ( ( $record->_table->isContainer($field['name']) or 00066 $record->_table->isBlob($field['name']) or 00067 $field['widget']['type'] == 'htmlarea' or 00068 $record->_table->isPassword($field['name']) or 00069 $record->_table->isMetaField($field['name'])) and (@$field['visibility']['summary'] != 'visible')) continue; 00070 if ( @$field['visibility']['summary'] == 'hidden' ) continue; 00071 if ( @$field['visibility']['list'] == 'hidden' and @$field['visibility']['summary'] != 'visible' ) continue; 00072 //if ( (@$field['visibility']['summary'] == 'visible') or !isset($field['visibility']['summary']) ){ 00073 $count++; 00074 $cols[] = $field['name']; 00075 //} 00076 if ( $count > 5 ) break; 00077 } 00078 return $cols; 00079 00080 00081 00082 } 00083 00084 function toHtml(){ 00085 ob_start(); 00086 df_display(array('records'=>&$this->records, 'list'=>&$this), 'Dataface_Summary_List.html'); 00087 $out = ob_get_contents(); 00088 ob_end_clean(); 00089 return $out; 00090 } 00091 00092 function getLogoField(&$record){ 00093 static $logoFields = 0; 00094 if ( $logoFields === 0 ) $logoFields = array(); 00095 if ( !array_key_exists($record->_table->tablename, $logoFields) ){ 00096 $found = false; 00097 foreach ( $record->_table->fields(false,true) as $field ){ 00098 00099 if ( ($record->isImage($field['name']) and @$field['logo'] !== 0 ) or @$field['logo'] ){ 00100 $logoFields[$record->_table->tablename] = $field['name']; 00101 $found = true; 00102 } 00103 00104 } 00105 foreach ( $record->_table->delegateFields(true) as $field ){ 00106 00107 if ( ($record->isImage($field['name']) and @$field['logo'] !== 0 ) or @$field['logo'] ){ 00108 $logoFields[$record->_table->tablename] = $field['name']; 00109 $found = true; 00110 } 00111 00112 } 00113 if ( !$found ){ 00114 $logoFields[$record->_table->tablename] = null; 00115 } 00116 00117 } 00118 return $logoFields[$record->_table->tablename]; 00119 00120 } 00121 00122 }