5 use \Rsi\Fred\Controller\Widget;
7 class Grid extends \Rsi\Fred\Controller\View\Html\Widget{
10 $captions = $edit_alls =
'';
11 $has_edit_all =
false;
12 foreach($this->_widget->widgets as $id => $widget){
14 $captions .= $this->html->th(
15 $hidden ?
null : $widget->caption($id),
16 $attribs = [
'class' =>
'id-' . $id . ($widget->required && !$hidden ?
' fred-required' :
'')]
20 $edit_all = $this->_view->createWidget([$this->_id,
'editAll',$id],$widget)->render();
23 $edit_alls .= $this->html->th($edit_all,$attribs);
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']) :
'')
32 if(!$this->_widget->total)
return null;
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);
40 $totals .= $this->html->th($content,[
'class' =>
'id-' . $id . ($types ?
' total-' . implode(
'-',$types) :
'')]);
42 return $this->html->tfoot($this->html->tr($totals . $this->html->th(
''),[
'class' =>
'fred-total']));
45 protected function renderRow($index,$record =
null,$raw =
false){
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]
55 return $this->html->tr(
56 $row . $this->html->td(
'',[
'class' =>
'fred-actions']),
57 [
'id' => $this->_id .
'__' . $index,
'class' =>
'fred-' . ($record ===
null ? $index :
'grid')]
61 public function render($value =
null,$raw =
false){
64 if($value)
foreach($value as $record) $rows .= $this->
renderRow($index++,$record,$raw);
67 $this->renderHeader() .
68 $this->renderFooter() .
69 $this->html->tbody($rows),
70 array_merge($this->
attribs(),[
'class' =>
'fred-grid'])