FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Options.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Options extends \Rsi\Fred\Controller\View\Html\Widget{
6 
7  protected function options($value){
8  if(($popular = $this->_widget->popular) && $value)
9  foreach((array)$value as $key) if(!array_key_exists($key,$popular)){
10  $popular = null;
11  break;
12  }
13  return \Rsi\Record::merge(
14  $this->_widget->placeholder ? [null => $this->_view->component('trans')->str($this->_widget->placeholder)] : [],
15  $popular ?: $this->_widget->options
16  );
17  }
18 
19  protected function renderGroup($value,$attribs,$options,$group = null){
20  if(!$options) return null;
21  $options = $this->html->input($value,$attribs,$this->_widget->multi ? 'checkbox' : 'radio',$this->_name,$options);
22  return $group
23  ? $this->html->div($this->html->label($group,['class' => 'fred-group']) . $options,null,'fred-group')
24  : $options;
25  }
26 
27  protected function renderOptions($value,$attribs = null){
28  $this->html->escape = $this->_widget->escape;
29  $attribs = array_merge($this->attribs(),$attribs ?: []);
30  $content = $group = null;
31  $options = [];
32  foreach($this->options($value) as $key => $label){
33  if(count($label = explode($this->_widget->groupDelimiter,$label)) == 1) array_unshift($label,null);
34  if($label[0] != $group){
35  $content .= $this->renderGroup($value,$attribs,$options,$group);
36  $group = $label[0];
37  $options = [];
38  }
39  $options[$key] = $label[1];
40  }
41  return $content . $this->renderGroup($value,$attribs,$options,$group);
42  }
43 
44  protected function renderMinimal($value,$raw){
45  $content = $this->renderHidden($this->_widget->multi ? json_encode($value) : $value,$raw);
46  foreach(\Rsi\Record::select($this->_widget->options,$this->_widget->multi ? $value : [$value]) as $descr)
47  $content .= $this->html->_div($descr,null,'value');
48  return $this->container($content,'minimal');
49  }
50 
51  protected function renderReadable($value,$raw){
52  return $this->container($this->renderOptions($value,['disabled' => true]),'readable');
53  }
54 
55  protected function renderWriteable($value,$raw){
56  return $this->container($this->renderOptions($value),'writeable');
57  }
58 
59 }
renderOptions($value, $attribs=null)
Definition: Options.php:27
container($content, $display)
Definition: Widget.php:42
renderGroup($value, $attribs, $options, $group=null)
Definition: Options.php:19