FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Grid.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use \Rsi\Fred\Controller\Widget;
6 
7 class Grid extends \Rsi\Fred\Controller\View\Html\Widget{
8 
9  protected function renderHeader(){
10  $captions = $edit_alls = '';
11  $has_edit_all = false;
12  foreach($this->_widget->widgets as $id => $widget){
13  $hidden = $widget->display <= Widget::DISPLAY_HIDDEN;
14  $captions .= $this->html->th(
15  $hidden ? null : $widget->caption($id),
16  $attribs = ['class' => 'id-' . $id . ($widget->required && !$hidden ? ' fred-required' : '')]
17  );
18  $edit_all = '';
19  if(in_array($id,$this->_widget->editAll) && ($widget->display >= Widget::DISPLAY_WRITEABLE)){
20  $edit_all = $this->_view->createWidget([$this->_id,'editAll',$id],$widget)->render();
21  $has_edit_all = true;
22  }
23  $edit_alls .= $this->html->th($edit_all,$attribs);
24  }
25  return $this->html->thead(
26  $this->html->tr($captions . $this->html->th('',['class' => 'fred-actions']),['class' => 'fred-captions']) .
27  ($has_edit_all ? $this->html->tr($edit_alls . $this->html->th('',['class' => 'fred-actions']),['class' => 'fred-edit-all']) : '')
28  );
29  }
30 
31  protected function renderFooter(){
32  if(!$this->_widget->total) return null;
33  $totals = '';
34  foreach($this->_widget->widgets as $id => $widget){
35  $content = $types = null;
36  if(array_key_exists($id,$this->_widget->total)){
37  if(!is_array($types = $this->_widget->total[$id])) $types = [$types];
38  foreach($types as $type) $content .= $this->html->div('',null,'fred-total-' . $type);
39  }
40  $totals .= $this->html->th($content,['class' => 'id-' . $id . ($types ? ' total-' . implode('-',$types) : '')]);
41  }
42  return $this->html->tfoot($this->html->tr($totals . $this->html->th(''),['class' => 'fred-total']));
43  }
44 
45  protected function renderRow($index,$record = null,$raw = false){
46  $row = '';
47  foreach($this->_widget->widgets as $id => $widget){
48  $widget->indexes = array_merge($this->_widget->indexes,[$index]);
49  $widget = $this->_view->createWidget([$this->_id,$index,$id],$widget);
50  $row .= $this->html->td(
51  $widget->render($record ? ($record[$id] ?? null) : $widget->defaultValue,$raw),
52  ['class' => 'id-' . $id]
53  );
54  }
55  return $this->html->tr(
56  $row . $this->html->td('',['class' => 'fred-actions']),
57  ['id' => $this->_id . '__' . $index,'class' => 'fred-' . ($record === null ? $index : 'grid')]
58  );
59  }
60 
61  public function render($value = null,$raw = false){
62  $rows = $this->renderRow('template');
63  $index = 0;
64  if($value) foreach($value as $record) $rows .= $this->renderRow($index++,$record,$raw);
65  return $this->container(
66  $this->html->table(
67  $this->renderHeader() .
68  $this->renderFooter() .
69  $this->html->tbody($rows),
70  array_merge($this->attribs(),['class' => 'fred-grid'])
71  ),
72  $this->_widget->display >= Widget::DISPLAY_WRITEABLE ? 'writeable' : 'readable'
73  );
74  }
75 
76 }
Rsi\Fred\Controller\View\Html\Widget\Grid\renderFooter
renderFooter()
Definition: Grid.php:31
Rsi\Fred\Controller\Widget\DISPLAY_HIDDEN
const DISPLAY_HIDDEN
Do not show (only hidden)
Definition: Widget.php:38
Rsi\Fred\Controller\View\Html\Widget\Grid\renderRow
renderRow($index, $record=null, $raw=false)
Definition: Grid.php:45
Rsi\Fred\Controller\View\Html\Widget\Grid\render
render($value=null, $raw=false)
Definition: Grid.php:61
Rsi\Fred\Controller\View\Html\Widget\attribs
attribs()
Definition: Widget.php:29
Rsi\Fred\Controller\Widget\DISPLAY_WRITEABLE
const DISPLAY_WRITEABLE
Show editable input element(s).
Definition: Widget.php:41
Rsi\Fred\Controller\View\Html\Widget
Definition: Char.php:3
Rsi\Fred\Controller\View\Html\Widget\container
container($content, $display)
Definition: Widget.php:43
Rsi\Fred\Controller\View\Html\Widget\Grid\renderHeader
renderHeader()
Definition: Grid.php:9
Rsi\Fred\Controller\View\Html\Widget\Grid
Definition: Grid.php:7