@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | * @version 1.3 |
| 16 | 16 | */ |
| 17 | 17 | abstract class BaseHtml extends BaseWidget { |
| 18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
| 18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
| 19 | 19 | protected $_template; |
| 20 | 20 | protected $tagName; |
| 21 | - protected $_wrapBefore=array (); |
|
| 22 | - protected $_wrapAfter=array (); |
|
| 21 | + protected $_wrapBefore=array(); |
|
| 22 | + protected $_wrapAfter=array(); |
|
| 23 | 23 | protected $_bsComponent; |
| 24 | 24 | |
| 25 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 25 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 26 | 26 | $result=false; |
| 27 | 27 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
| 28 | 28 | try { |
| 29 | 29 | $this->$setter($value); |
| 30 | 30 | unset($array[$key]); |
| 31 | 31 | $result=true; |
| 32 | - } catch ( \Exception $e ) { |
|
| 32 | + }catch (\Exception $e) { |
|
| 33 | 33 | $result=false; |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -37,17 +37,17 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | protected function getTemplate(JsUtils $js=NULL) { |
| 40 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 40 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | protected function ctrl($name, $value, $typeCtrl) { |
| 44 | 44 | if (\is_array($typeCtrl)) { |
| 45 | - if (array_search($value, $typeCtrl) === false) { |
|
| 46 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 45 | + if (array_search($value, $typeCtrl)===false) { |
|
| 46 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 47 | 47 | } |
| 48 | 48 | } else { |
| 49 | 49 | if (!$typeCtrl($value)) { |
| 50 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 50 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | return true; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 59 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 59 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 60 | 60 | return $name=$value; |
| 61 | 61 | } |
| 62 | 62 | return $this; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 66 | 66 | if (\is_array($typeCtrl)) { |
| 67 | 67 | $this->removeOldValues($name, $typeCtrl); |
| 68 | - $name.=$separator . $value; |
|
| 68 | + $name.=$separator.$value; |
|
| 69 | 69 | } |
| 70 | 70 | return $this; |
| 71 | 71 | } |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 76 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 76 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 77 | 77 | if (\is_array($typeCtrl)) { |
| 78 | 78 | $this->removeOldValues($name, $typeCtrl); |
| 79 | 79 | } |
| 80 | - $name.=$separator . $value; |
|
| 80 | + $name.=$separator.$value; |
|
| 81 | 81 | } |
| 82 | 82 | return $this; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | protected function addToMember(&$name, $value, $separator=" ") { |
| 86 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 86 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 87 | 87 | return $this; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -94,17 +94,17 @@ discard block |
||
| 94 | 94 | $oldValue=trim($oldValue); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - protected function _getElementBy($callback,$elements){ |
|
| 97 | + protected function _getElementBy($callback, $elements) { |
|
| 98 | 98 | if (\is_array($elements)) { |
| 99 | 99 | $flag=false; |
| 100 | 100 | $index=0; |
| 101 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 101 | + while (!$flag && $index<sizeof($elements)) { |
|
| 102 | 102 | if ($elements[$index] instanceof BaseHtml) |
| 103 | 103 | $flag=($callback($elements[$index])); |
| 104 | 104 | $index++; |
| 105 | 105 | } |
| 106 | - if ($flag === true) |
|
| 107 | - return $elements[$index - 1]; |
|
| 106 | + if ($flag===true) |
|
| 107 | + return $elements[$index-1]; |
|
| 108 | 108 | } elseif ($elements instanceof BaseHtml) { |
| 109 | 109 | if ($callback($elements)) |
| 110 | 110 | return $elements; |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function fromArray($array) { |
| 142 | - foreach ( $this as $key => $value ) { |
|
| 143 | - if(array_key_exists($key, $array)===true) |
|
| 144 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 142 | + foreach ($this as $key => $value) { |
|
| 143 | + if (array_key_exists($key, $array)===true) |
|
| 144 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 145 | 145 | } |
| 146 | - foreach ( $array as $key => $value ) { |
|
| 147 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 148 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 146 | + foreach ($array as $key => $value) { |
|
| 147 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 148 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | return $array; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | public function fromDatabaseObjects($objects, $function) { |
| 155 | 155 | if (isset($objects)) { |
| 156 | - foreach ( $objects as $object ) { |
|
| 156 | + foreach ($objects as $object) { |
|
| 157 | 157 | $this->fromDatabaseObject($object, $function); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | public function getElementById($identifier, $elements) { |
| 177 | - return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 177 | + return $this->_getElementBy(function($element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function getBsComponent() { |
@@ -188,19 +188,19 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 190 | 190 | $result=$this->getTemplate($js); |
| 191 | - foreach ( $this as $key => $value ) { |
|
| 192 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
| 191 | + foreach ($this as $key => $value) { |
|
| 192 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
| 193 | 193 | if (\is_array($value)) { |
| 194 | 194 | $v=PropertyWrapper::wrap($value, $js); |
| 195 | 195 | } else { |
| 196 | 196 | $v=$value; |
| 197 | 197 | } |
| 198 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
| 198 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | if (isset($js)===true) { |
| 202 | 202 | $this->run($js); |
| 203 | - if (isset($view) === true) { |
|
| 203 | + if (isset($view)===true) { |
|
| 204 | 204 | $js->addViewElement($this->identifier, $result, $view); |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -14,64 +14,64 @@ |
||
| 14 | 14 | protected $params; |
| 15 | 15 | protected $semElement; |
| 16 | 16 | |
| 17 | - public function __construct($semElement,$title="",$content="",$variation=NULL,$params=array()){ |
|
| 17 | + public function __construct($semElement, $title="", $content="", $variation=NULL, $params=array()) { |
|
| 18 | 18 | $this->semElement=$semElement; |
| 19 | 19 | $this->title=$title; |
| 20 | 20 | $this->content=$content; |
| 21 | - $this->setAttributes($variation,$params); |
|
| 21 | + $this->setAttributes($variation, $params); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function setHtml($html) { |
| 25 | - $this->html= $html; |
|
| 25 | + $this->html=$html; |
|
| 26 | 26 | return $this; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function setAttributes($variation=NULL,$params=array()){ |
|
| 29 | + public function setAttributes($variation=NULL, $params=array()) { |
|
| 30 | 30 | $this->variation=$variation; |
| 31 | 31 | $this->params=$params; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function onShow($jsCode){ |
|
| 34 | + public function onShow($jsCode) { |
|
| 35 | 35 | $this->params["onShow"]=$jsCode; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function compile(JsUtils $js=NULL){ |
|
| 39 | - if(JString::isNotNull($this->title)){ |
|
| 38 | + public function compile(JsUtils $js=NULL) { |
|
| 39 | + if (JString::isNotNull($this->title)) { |
|
| 40 | 40 | $this->semElement->addToProperty("data-title", $this->title); |
| 41 | 41 | } |
| 42 | - if(JString::isNotNull($this->content)){ |
|
| 42 | + if (JString::isNotNull($this->content)) { |
|
| 43 | 43 | $this->semElement->addToProperty("data-content", $this->content); |
| 44 | 44 | } |
| 45 | 45 | $this->_compileHtml($js); |
| 46 | - if(JString::isNotNull($this->variation)){ |
|
| 46 | + if (JString::isNotNull($this->variation)) { |
|
| 47 | 47 | $this->semElement->addToProperty("data-variation", $this->variation); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - private function _compileHtml(JsUtils $js=NULL){ |
|
| 52 | - if(JString::isNotNull($this->html)){ |
|
| 51 | + private function _compileHtml(JsUtils $js=NULL) { |
|
| 52 | + if (JString::isNotNull($this->html)) { |
|
| 53 | 53 | $html=$this->html; |
| 54 | - if(\is_array($html)){ |
|
| 54 | + if (\is_array($html)) { |
|
| 55 | 55 | \array_walk($html, function(&$item) use($js){ |
| 56 | - if($item instanceof HtmlSemDoubleElement){ |
|
| 56 | + if ($item instanceof HtmlSemDoubleElement) { |
|
| 57 | 57 | $comp=$item->compile($js); |
| 58 | - if(isset($js)){ |
|
| 58 | + if (isset($js)) { |
|
| 59 | 59 | $bs=$item->run($js); |
| 60 | - if(isset($bs)) |
|
| 60 | + if (isset($bs)) |
|
| 61 | 61 | $this->params['onShow']=$bs->getScript(); |
| 62 | 62 | } |
| 63 | 63 | $item=$comp; |
| 64 | 64 | } |
| 65 | 65 | }); |
| 66 | - $html=\implode("",$html); |
|
| 66 | + $html=\implode("", $html); |
|
| 67 | 67 | } |
| 68 | 68 | $html=\str_replace("\"", "'", $html); |
| 69 | 69 | $this->semElement->addToProperty("data-html", $html); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function run(JsUtils $js){ |
|
| 74 | - $js->semantic()->popup("#".$this->semElement->getIdentifier(),$this->params); |
|
| 73 | + public function run(JsUtils $js) { |
|
| 74 | + $js->semantic()->popup("#".$this->semElement->getIdentifier(), $this->params); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | \ No newline at end of file |