FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Group.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class Group extends \Rsi\Fred\Controller\Widget{
6 
7  const VALUE_GLUE = 'valueGlue'; //!< Delimiter to glue the different values together (empty = use array).
8  const FORMAT = 'format'; //!< Format (use [{id}] to replace with widget value; empty = implode with space).
9 
10  public $valueGlue = null;
11 
12  protected $_format = null;
13 
14  public function clientConfig(){
15  return array_merge(parent::clientConfig(),[self::CLASS_NAME => get_class()]);
16  }
17 
18  public function convert($value){
19  $result = [];
20  foreach($this->widgets as $id => $widget) $result[$id] = $widget->convert($value[$id]);
21  return $result;
22  }
23 
24  public function clientConvert($value){
25  $result = [];
26  foreach($this->widgets as $id => $widget) $result[$id] = $widget->clientConvert($value[$id]);
27  return $result;
28  }
29 
30  public function dataConvert($value){
31  return $this->valueGlue ? implode($this->valueGlue,$value) : $value;
32  }
33 
34  public function explode($value){
35  if(
36  !is_array($value) &&
37  $this->valueGlue &&
38  (count($parts = explode($this->valueGlue,$value)) == count($this->widgets))
39  ) $value = array_combine(array_keys($this->widgets),$parts);
40  return $value;
41  }
42 
43  public function format($value){
44  if(!is_array($value = $this->explode($value))) return $value;
45  $format = $this->format;
46  foreach($this->widgets as $id => $widget) $format = str_replace("[$id]",$widget->format($value[$id]),$format);
47  return $format;
48  }
49 
50  protected function purgeBase($value){
51  $result = [];
52  foreach($this->widgets as $id => $widget) $result[$id] = \Rsi\Record::get($value,$id);
53  return $result;
54  }
55 
56  protected function executeChild($id){
57  if(array_key_exists($id = array_pop($id),$this->widgets)) $this->widgets[$this->request->widgetId = $id]->execute();
58  else parent::executeChild($id);
59  }
60 
61  protected function checkWidgets($value,$index = null){
62  foreach($this->widgets as $id => $widget) if($widget->check($value[$id] ?? null,$index)) return false;
63  return true;
64  }
65 
66  protected function getFormat(){
67  if(!$this->_format) $this->_format = '[' . implode('] [',array_keys($this->widgets)) . ']';
68  return $this->_format;
69  }
70 
71 }
const FORMAT
Format (use [{id}] to replace with widget value; empty = implode with space).
Definition: Group.php:8
checkWidgets($value, $index=null)
Definition: Group.php:61
const VALUE_GLUE
Delimiter to glue the different values together (empty = use array).
Definition: Group.php:7