1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
6
|
|
|
use Ajax\semantic\html\content\HtmlListItem; |
7
|
|
|
use Ajax\semantic\html\collections\form\HtmlFormCheckbox; |
8
|
|
|
use Ajax\JsUtils; |
9
|
|
|
|
10
|
|
|
class HtmlList extends HtmlSemCollection{ |
11
|
|
|
protected $_hasCheckedList; |
12
|
|
|
|
13
|
|
|
public function __construct( $identifier, $items=array()){ |
14
|
|
|
parent::__construct( $identifier, "div", "ui list"); |
15
|
|
|
$this->addItems($items); |
16
|
|
|
$this->_hasCheckedList=false; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function createItem($value){ |
21
|
|
|
$count=$this->count(); |
22
|
|
|
if(\is_array($value)){ |
23
|
|
|
$item=new HtmlListItem("item-".$this->identifier."-".$count, $value[0]); |
24
|
|
|
$item->addIcon($value[1]); |
25
|
|
|
}else |
26
|
|
|
$item= new HtmlListItem("item-".$this->identifier."-".$count, $value); |
27
|
|
|
return $item; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function addHeader($niveau,$content){ |
31
|
|
|
return $this->wrap(new HtmlHeader("header-".$this->identifier,$niveau,$content,"page")); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function itemsAs($tagName){ |
35
|
|
|
return $this->contentAs($tagName); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function asLink(){ |
39
|
|
|
$this->addToPropertyCtrl("class", "link", array("link")); |
40
|
|
|
return $this->contentAs("a"); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function addList($items=array()){ |
44
|
|
|
$list=new HtmlList("",$items); |
45
|
|
|
$list->setClass("list"); |
46
|
|
|
return $this->addItem($list); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setCelled(){ |
50
|
|
|
return $this->addToProperty("class", "celled"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function run(JsUtils $js){ |
54
|
|
|
if($this->_hasCheckedList===true){ |
55
|
|
|
$jsCode=include dirname(__FILE__).'/../../components/jsTemplates/tplCheckedList.php'; |
56
|
|
|
$jsCode=\str_replace("%identifier%","#".$this->identifier,$jsCode); |
57
|
|
|
$this->executeOnRun($jsCode); |
58
|
|
|
} |
59
|
|
|
return parent::run($js); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function setRelaxed(){ |
63
|
|
|
return $this->addToProperty("class", "relaxed"); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function addCheckedList($items=array(),$masterItem=NULL,$values=array()){ |
67
|
|
|
$count=$this->count(); |
68
|
|
|
$identifier=$this->identifier."-".$count; |
69
|
|
|
if(isset($masterItem)){ |
70
|
|
|
$masterO=new HtmlFormCheckbox("master-".$identifier,$masterItem); |
71
|
|
|
$masterO->getField()->addToProperty("class","master"); |
72
|
|
|
$masterO->setClass("item"); |
73
|
|
|
$this->addItem($masterO); |
74
|
|
|
} |
75
|
|
|
$fields=array(); |
76
|
|
|
$i=0; |
77
|
|
|
foreach ($items as $val=>$caption){ |
78
|
|
|
$itemO=new HtmlFormCheckbox($identifier."-".$i++,$caption,$val,"child"); |
79
|
|
|
if(\array_search($val, $values)!==false){ |
80
|
|
|
$itemO->getInput()->getField()->setProperty("checked", ""); |
81
|
|
|
} |
82
|
|
|
$itemO->setClass("item"); |
83
|
|
|
$fields[]=$itemO; |
84
|
|
|
} |
85
|
|
|
if(isset($masterO)===true){ |
86
|
|
|
$list=new HtmlList("",$fields); |
87
|
|
|
$list->setClass("list"); |
88
|
|
|
$masterO->addContent($list); |
|
|
|
|
89
|
|
|
}else{ |
90
|
|
|
$this->addList($fields); |
91
|
|
|
} |
92
|
|
|
$this->_hasCheckedList=true; |
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: