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-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 = $this->_view->createWidget([$this->_id,$index,$id],$widget);
49 $row .= $this->html->td(
50 $widget->render($record ? ($record[$id] ?? null) : $widget->defaultValue,$raw),
51 [
'class' =>
'id-' . $id]
54 return $this->html->tr(
55 $row . $this->html->td(
'',[
'class' =>
'fred-actions']),
56 [
'id' => $this->_id .
'__' . $index,
'class' =>
'fred-' . ($record === null ? $index :
'grid')]
60 public function render($value = null,$raw =
false){
63 if($value)
foreach($value as $record) $rows .= $this->
renderRow($index++,$record,$raw);
66 $this->renderHeader() .
68 $this->html->tbody($rows),
69 array_merge($this->
attribs(),[
'class' =>
'fred-grid'])