<?php\r
\r
-class wsParametres extends cubeMetier implements Iterator {\r
-\r
- protected $datas;\r
- protected $fields;\r
- protected $forms;\r
- protected $parent;\r
-\r
- // Magic functions\r
- public function __construct($parent) {\r
- $this->parent = $parent;\r
- $this->initFields();\r
- $this->datas = array();\r
- $this->setDefaultValues();\r
- }\r
-\r
- public function isEmpty() {\r
- return count($this->datas) == 0;\r
- }\r
-\r
- public function setParent($parent) {\r
- $this->parent = $parent;\r
- $this->initFields();\r
- }\r
-\r
- public function __set($varname, $value) {\r
- if (empty($varname)) {\r
- return;\r
- }\r
- $this->set($varname, $value);\r
- }\r
-\r
- public function __unset($varname) {\r
- $this->set($varname, null);\r
- }\r
-\r
- public function __get($varname) {\r
- return $this->get($varname);\r
- }\r
-\r
- public function __isset($varname) {\r
- return $this->_isset($varname);\r
- }\r
-\r
- public function __sleep() {\r
- return array('datas');\r
- }\r
-\r
- public function __wakeup() {\r
- $this->initFields();\r
- }\r
-\r
- // Iterator functions\r
- public function rewind() {\r
- reset($this->fields);\r
- }\r
-\r
- public function current() {\r
- return $this->get($this->key());\r
- }\r
-\r
- public function key() {\r
- return key($this->fields);\r
- }\r
-\r
- public function next() {\r
- return next($this->fields);\r
- }\r
-\r
- public function valid() {\r
- return $this->_isset($this->key());\r
- }\r
-\r
- protected function initFields() {\r
- $this->fields = array();\r
- $this->forms = array();\r
- }\r
-\r
- protected function setDefaultValues() {\r
- foreach ($this->fields as $k => $f) {\r
- if (isset($f["default"])) {\r
- $this->set($k, $f['default']);\r
- }\r
- }\r
- }\r
-\r
- protected function set($varname, $value) {\r
- if (!$this->_isset($varname)) {\r
- throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
- }\r
-\r
- if (is_null($value)) {\r
- $this->datas[$varname] = null;\r
- return;\r
- }\r
-\r
- switch ($this->fields[$varname]['type']) {\r
- case 'integer':\r
- if (!is_int($value)) {\r
- $value = intval($value);\r
- }\r
- break;\r
- case 'float':\r
- if (!is_float($value)) {\r
- $value = floatval($value);\r
- }\r
- break;\r
- case 'boolean':\r
- if (!is_bool($value)) {\r
- $value = ($value == '' || $value == '0' || $value == 'false') ? false : true;\r
- }\r
- break;\r
- case 'color':\r
- case 'couleur':\r
- $value = cubeMath::fill(ltrim($value, '#'), 6);\r
- break;\r
- case 'couleurAlpha':\r
- $value = cubeMath::fill(ltrim($value, '#'), 6);\r
- $value = cubeMath::fill($value, 8, 'f');\r
- break;\r
- case 'date':\r
- if (!is_int($value)) {\r
- $value = intval($value);\r
- }\r
- break;\r
- case 'file':\r
- $e = explode('/', $value);\r
- $value = array_pop($e);\r
- break;\r
- default:\r
- $value = (string)$value;\r
- break;\r
- } // switch\r
- $this->datas[$varname] = $value;\r
- }\r
-\r
- protected function _isset($varname) {\r
- return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']);\r
- }\r
-\r
- protected function get($varname) {\r
- if (is_null($varname)) {\r
- return false;\r
- }\r
- if (!$this->_isset($varname)) {\r
- throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
- }\r
- if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) {\r
- return $this->getDefault($varname);\r
- }\r
- return $this->datas[$varname];\r
- }\r
-\r
- protected function getDefault($varname) {\r
- if (substr($this->fields[$varname]['default'], 0, 1) == '$') {\r
- return $this->get(substr($this->fields[$varname]['default'], 1));\r
- } else {\r
- return $this->fields[$varname]['default'];\r
- }\r
- }\r
-\r
- public function getForm($name,$ignoreMeta=false) {\r
- $f = $this->forms[$name];\r
- $f['fields'] = array();\r
- foreach ($f['fieldsnames'] as $n) {\r
- if ($n == '|') {\r
- if($ignoreMeta){\r
- continue;\r
+class wsParametres extends cubeMetier implements Iterator\r
+{\r
+\r
+ protected $datas;\r
+ protected $fields;\r
+ protected $forms;\r
+ protected $parent;\r
+\r
+ // Magic functions\r
+ public function __construct($parent)\r
+ {\r
+ $this->parent = $parent;\r
+ $this->initFields();\r
+ $this->datas = array();\r
+ $this->setDefaultValues();\r
+ }\r
+\r
+ public function isEmpty()\r
+ {\r
+ return count($this->datas) == 0;\r
+ }\r
+\r
+ public function setParent($parent)\r
+ {\r
+ $this->parent = $parent;\r
+ $this->initFields();\r
+ }\r
+\r
+ public function __set($varname, $value)\r
+ {\r
+ if (empty($varname)) {\r
+ return;\r
+ }\r
+ $this->set($varname, $value);\r
+ }\r
+\r
+ public function __unset($varname)\r
+ {\r
+ $this->set($varname, null);\r
+ }\r
+\r
+ public function __get($varname)\r
+ {\r
+ return $this->get($varname);\r
+ }\r
+\r
+ public function __isset($varname)\r
+ {\r
+ return $this->_isset($varname);\r
+ }\r
+\r
+ public function __sleep()\r
+ {\r
+ return array('datas');\r
+ }\r
+\r
+ public function __wakeup()\r
+ {\r
+ $this->initFields();\r
+ }\r
+\r
+ // Iterator functions\r
+ public function rewind()\r
+ {\r
+ reset($this->fields);\r
+ }\r
+\r
+ public function current()\r
+ {\r
+ return $this->get($this->key());\r
+ }\r
+\r
+ public function key()\r
+ {\r
+ return key($this->fields);\r
+ }\r
+\r
+ public function next()\r
+ {\r
+ return next($this->fields);\r
+ }\r
+\r
+ public function valid()\r
+ {\r
+ return $this->_isset($this->key());\r
+ }\r
+\r
+ protected function initFields()\r
+ {\r
+ $this->fields = array();\r
+ $this->forms = array();\r
+ }\r
+\r
+ protected function setDefaultValues()\r
+ {\r
+ foreach ($this->fields as $k => $f) {\r
+ if (isset($f["default"])) {\r
+ $this->set($k, $f['default']);\r
+ }\r
+ }\r
+ }\r
+\r
+ protected function set($varname, $value)\r
+ {\r
+ if (!$this->_isset($varname)) {\r
+ throw new Exception('You are setting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
+ }\r
+\r
+ if (is_null($value)) {\r
+ $this->datas[$varname] = null;\r
+ return;\r
+ }\r
+\r
+ switch ($this->fields[$varname]['type']) {\r
+ case 'integer':\r
+ if (!is_int($value)) {\r
+ $value = intval($value);\r
}\r
- $f['fields'][] = '|';\r
- } else {\r
- $f['fields'][$n] = $this->fields[$n];\r
- $f['fields'][$n]['value'] = $this->get($n);\r
- }\r
- }\r
- return $f;\r
- }\r
-\r
- public function getForms() {\r
- return array_keys($this->forms);\r
- }\r
-\r
- public function fromRecord($r) {\r
- $c = array_flip($r->columns());\r
- foreach ($this->fields as $n => $f) {\r
- if (isset($c[$n]) && !is_null($r->$n)) {\r
- $this->set($n, $r->$n);\r
- }\r
- }\r
- }\r
-\r
- public function fromXML($xml) {\r
- foreach ($this->fields as $n => $f) {\r
- $xp = $xml->$n;\r
- if (!$xp || !count($xp)) {\r
- continue;\r
- }\r
- foreach ($xp as $x) {\r
- $this->set($n, $x);\r
- }\r
- }\r
- }\r
-\r
- public function toStandardObject() {\r
- $res = new stdClass();\r
- foreach ($this as $k => $v) {\r
- $res->$k = $v;\r
- }\r
- return $res;\r
- }\r
-\r
- public function getHelp() {\r
- $rubriques = array();\r
- foreach ($this->forms as $name => $form) {\r
- $rub = array();\r
- foreach ($form['fieldsnames'] as $f) {\r
- if ($f == '|') {\r
- $rub[] = '|';\r
- } else {\r
-\r
- $d = self::formatValueForHelp($this->getDefault($f));\r
- $v = self::formatValueForHelp($this->get($f));\r
- if ($d != $v) {\r
- $v = '<strong>' . $v . '</strong>';\r
- }\r
-\r
-\r
- $field = $this->fields[$f];\r
- $t = array();\r
- $t[] = $f;\r
- $t[] = $field['type'];\r
- $t[] = $field['label'];\r
- $t[] = $d;\r
- $t[] = $v;\r
- $rub[$f] = $t;\r
- }\r
- }\r
- $rubriques[$form['label']] = $rub;\r
- }\r
- return $rubriques;\r
- }\r
-\r
- public static function formatValueForHelp($v) {\r
- if (is_bool($v)) {\r
- $v = ($v) ? 'true' : 'false';\r
- }\r
- return $v;\r
- }\r
+ break;\r
+ case 'float':\r
+ if (!is_float($value)) {\r
+ $value = floatval($value);\r
+ }\r
+ break;\r
+ case 'boolean':\r
+ if ($value === 'TRUE') {\r
+ $value = true;\r
+ }\r
+ if ($value === 'FALSE') {\r
+ return false;\r
+ }\r
+ if (!is_bool($value)) {\r
+ $value = !($value == '' || $value == '0' || $value === 'false');\r
+ }\r
+ $value = (bool)$value;\r
+ break;\r
+ case 'color':\r
+ case 'couleur':\r
+ $value = cubeMath::fill(ltrim($value, '#'), 6);\r
+ break;\r
+ case 'couleurAlpha':\r
+ $value = cubeMath::fill(ltrim($value, '#'), 6);\r
+ $value = cubeMath::fill($value, 8, 'f');\r
+ break;\r
+ case 'date':\r
+ if (!is_int($value)) {\r
+ $value = intval($value);\r
+ }\r
+ break;\r
+ case 'file':\r
+ $e = explode('/', $value);\r
+ $value = array_pop($e);\r
+ break;\r
+ default:\r
+ $value = (string)$value;\r
+ break;\r
+ } // switch\r
+ $this->datas[$varname] = $value;\r
+ }\r
+\r
+ protected function _isset($varname)\r
+ {\r
+ return isset($this->fields[$varname]) && isset($this->fields[$varname]['default']);\r
+ }\r
+\r
+ protected function get($varname)\r
+ {\r
+ if (is_null($varname)) {\r
+ return false;\r
+ }\r
+ if (!$this->_isset($varname)) {\r
+ throw new Exception('You are getting an attribute (' . get_class($this) . '::' . $varname . ') which not exists');\r
+ }\r
+ if (!isset($this->datas[$varname]) || is_null($this->datas[$varname])) {\r
+ return $this->getDefault($varname);\r
+ }\r
+ return $this->datas[$varname];\r
+ }\r
+\r
+ protected function getDefault($varname)\r
+ {\r
+ if (substr($this->fields[$varname]['default'], 0, 1) == '$') {\r
+ return $this->get(substr($this->fields[$varname]['default'], 1));\r
+ } else {\r
+ return $this->fields[$varname]['default'];\r
+ }\r
+ }\r
+\r
+ public function getForm($name, $ignoreMeta = false)\r
+ {\r
+ $f = $this->forms[$name];\r
+ $f['fields'] = array();\r
+ foreach ($f['fieldsnames'] as $n) {\r
+ if ($n == '|') {\r
+ if ($ignoreMeta) {\r
+ continue;\r
+ }\r
+ $f['fields'][] = '|';\r
+ } else {\r
+ $f['fields'][$n] = $this->fields[$n];\r
+ $f['fields'][$n]['value'] = $this->get($n);\r
+ }\r
+ }\r
+ return $f;\r
+ }\r
+\r
+ public function getForms()\r
+ {\r
+ return array_keys($this->forms);\r
+ }\r
+\r
+ public function fromRecord($r)\r
+ {\r
+ $c = array_flip($r->columns());\r
+ foreach ($this->fields as $n => $f) {\r
+ if (isset($c[$n]) && !is_null($r->$n)) {\r
+ $this->set($n, $r->$n);\r
+ }\r
+ }\r
+ }\r
+\r
+ public function fromXML($xml)\r
+ {\r
+ foreach ($this->fields as $n => $f) {\r
+ $xp = $xml->$n;\r
+ if (!$xp || !count($xp)) {\r
+ continue;\r
+ }\r
+ foreach ($xp as $x) {\r
+ $this->set($n, $x);\r
+ }\r
+ }\r
+ }\r
+\r
+ public function toStandardObject()\r
+ {\r
+ $res = new stdClass();\r
+ foreach ($this as $k => $v) {\r
+ $res->$k = $v;\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public function toArray()\r
+ {\r
+ $res = [];\r
+ foreach ($this as $k => $v) {\r
+ $res[$k]=$v;\r
+ }\r
+ return $res;\r
+ }\r
+\r
+ public function getHelp()\r
+ {\r
+ $rubriques = array();\r
+ foreach ($this->forms as $name => $form) {\r
+ $rub = array();\r
+ foreach ($form['fieldsnames'] as $f) {\r
+ if ($f == '|') {\r
+ $rub[] = '|';\r
+ } else {\r
+\r
+ $d = self::formatValueForHelp($this->getDefault($f));\r
+ $v = self::formatValueForHelp($this->get($f));\r
+ if ($d != $v) {\r
+ $v = '<strong>' . $v . '</strong>';\r
+ }\r
+\r
+\r
+ $field = $this->fields[$f];\r
+ $t = array();\r
+ $t[] = $f;\r
+ $t[] = $field['type'];\r
+ $t[] = $field['label'];\r
+ $t[] = $d;\r
+ $t[] = $v;\r
+ $rub[$f] = $t;\r
+ }\r
+ }\r
+ $rubriques[$form['label']] = $rub;\r
+ }\r
+ return $rubriques;\r
+ }\r
+\r
+ public static function formatValueForHelp($v)\r
+ {\r
+ if (is_bool($v)) {\r
+ $v = ($v) ? 'true' : 'false';\r
+ }\r
+ return $v;\r
+ }\r
\r
}
\ No newline at end of file