Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
SummaryList.php
Go to the documentation of this file.
1 <?php
3  var $records;
4  var $table;
6  $this->records =& $records;
7  if ( count($this->records) > 0 ) $this->table =& $this->records[0]->_table;
8  }
9 
10  function showSummary(&$record){
11  $del =& $record->_table->getDelegate();
12  if ( isset($del) and method_exists($del, 'showSummary') ){
13  return $del->showSummary($record);
14  }
15 
17  $adel =& $app->getDelegate();
18  if ( isset($adel) and method_exists($adel, 'showSummary') ){
19  return $adel->showSummary($record);
20  }
21 
22  // No custom summary defined. We build our own.
23  // See if there is an image of sorts.
24  $logoField = $this->getLogoField($record);
25  $out = '<div class="Dataface_SummaryList-record-summary">';
26  if ( $logoField ){
27  if ( isset($app->prefs['SummaryList_logo_width']) ) $width = $apps->prefs['SummaryList_logo_width'];
28  else $width = '60';
29  $out .= '<div class="Dataface_SummaryList-record-logo"><a href="'.$record->getURL('-action=view').'" title="Record details">
30  <img src="'.$record->display($logoField).'" width="'.htmlspecialchars($width).'"/>
31  </a>
32  </div>';
33  }
34 
35  $out .= '<table class="record-view-table">
36  <tbody>';
37  foreach ( $this->getSummaryColumns($record) as $fieldname){
38  $field =& $record->_table->getField($fieldname);
39  $out .= '
40  <tr><th class="record-view-label">'.htmlspecialchars($field['widget']['label']).'</th><td class="record-view-value">'.$record->htmlValue($fieldname).'</td></tr>
41  ';
42  }
43  $out .= ' </tbody></table>';
44 
45  //$out .= '<h5 class="Dataface_SummaryList-record-title"><a href="'.$record->getURL('-action=view').'">'.htmlspecialchars($record->callDelegateFunction('summaryTitle',$record->getTitle())).'</a></h5>';
46  //$out .= '<div class="Dataface_SummaryList-record-description">'.$record->callDelegateFunction('summaryDescription',$record->getDescription()).'</div>';
47  //$out .= ( $record->getLastModified() + $record->getCreated() > 0 ? '<div class="Dataface_SummaryLIst-record-status">'.
48  // ( $record->getLastModified() > 0 ? '<span class="Dataface_SummaryList-record-last-modified">
49  // '.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()))))).'
50  // </span>' : '').
51  // ( $record->getCreated() > 0 ?
52  // '<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>':''
53  // ).'
54  // </div>': '').'
55  $out .=' </div>';
56  return $out;
57 
58  }
59 
60  function getSummaryColumns(&$record){
61  $cols = array();
62  $count= 0;
63  foreach ($record->_table->fields(false,true) as $field){
64  //print_r($field);
65  if ( ( $record->_table->isContainer($field['name']) or
66  $record->_table->isBlob($field['name']) or
67  $field['widget']['type'] == 'htmlarea' or
68  $record->_table->isPassword($field['name']) or
69  $record->_table->isMetaField($field['name'])) and (@$field['visibility']['summary'] != 'visible')) continue;
70  if ( @$field['visibility']['summary'] == 'hidden' ) continue;
71  if ( @$field['visibility']['list'] == 'hidden' and @$field['visibility']['summary'] != 'visible' ) continue;
72  //if ( (@$field['visibility']['summary'] == 'visible') or !isset($field['visibility']['summary']) ){
73  $count++;
74  $cols[] = $field['name'];
75  //}
76  if ( $count > 5 ) break;
77  }
78  return $cols;
79 
80 
81 
82  }
83 
84  function toHtml(){
85  ob_start();
86  df_display(array('records'=>&$this->records, 'list'=>&$this), 'Dataface_Summary_List.html');
87  $out = ob_get_contents();
88  ob_end_clean();
89  return $out;
90  }
91 
92  function getLogoField(&$record){
93  static $logoFields = 0;
94  if ( $logoFields === 0 ) $logoFields = array();
95  if ( !array_key_exists($record->_table->tablename, $logoFields) ){
96  $found = false;
97  foreach ( $record->_table->fields(false,true) as $field ){
98 
99  if ( ($record->isImage($field['name']) and @$field['logo'] !== 0 ) or @$field['logo'] ){
100  $logoFields[$record->_table->tablename] = $field['name'];
101  $found = true;
102  }
103 
104  }
105  foreach ( $record->_table->delegateFields(true) as $field ){
106 
107  if ( ($record->isImage($field['name']) and @$field['logo'] !== 0 ) or @$field['logo'] ){
108  $logoFields[$record->_table->tablename] = $field['name'];
109  $found = true;
110  }
111 
112  }
113  if ( !$found ){
114  $logoFields[$record->_table->tablename] = null;
115  }
116 
117  }
118  return $logoFields[$record->_table->tablename];
119 
120  }
121 
122 }