Completed
Push — master ( 5c7ff3...abc246 )
by Jean-Christophe
03:41
created
Ajax/semantic/widgets/datatable/DataTable.php 2 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -32,6 +32,10 @@  discard block
 block discarded – undo
32 32
 	protected $_targetSelector;
33 33
 
34 34
 
35
+	/**
36
+	 * @param string $identifier
37
+	 * @param string $model
38
+	 */
35 39
 	public function __construct($identifier,$model,$modelInstance=NULL) {
36 40
 		parent::__construct($identifier, $model,$modelInstance);
37 41
 		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
@@ -55,6 +59,9 @@  discard block
 block discarded – undo
55 59
 
56 60
 
57 61
 
62
+	/**
63
+	 * @param string $op
64
+	 */
58 65
 	protected function _generateBehavior($op,$params,JsUtils $js){
59 66
 		if(isset($this->_urls[$op])){
60 67
 			$params=\array_merge($params,["attr"=>"data-ajax"]);
@@ -184,6 +191,9 @@  discard block
 block discarded – undo
184 191
 		return $this;
185 192
 	}
186 193
 
194
+	/**
195
+	 * @param PositionInTable $part
196
+	 */
187 197
 	private function addToolbarRow($part,$table,$captions){
188 198
 		$hasPart=$table->hasPart($part);
189 199
 		if($hasPart){
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  *
22 22
  */
23 23
 class DataTable extends Widget {
24
-	use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait;
24
+	use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait;
25 25
 	protected $_searchField;
26 26
 	protected $_urls;
27 27
 	protected $_pagination;
@@ -32,33 +32,33 @@  discard block
 block discarded – undo
32 32
 	protected $_targetSelector;
33 33
 
34 34
 
35
-	public function __construct($identifier,$model,$modelInstance=NULL) {
36
-		parent::__construct($identifier, $model,$modelInstance);
37
-		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
35
+	public function __construct($identifier, $model, $modelInstance=NULL) {
36
+		parent::__construct($identifier, $model, $modelInstance);
37
+		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false);
38 38
 		$this->_urls=[];
39 39
 	}
40 40
 
41
-	public function run(JsUtils $js){
42
-		if($this->_hasCheckboxes && isset($js)){
41
+	public function run(JsUtils $js) {
42
+		if ($this->_hasCheckboxes && isset($js)) {
43 43
 			$this->_runCheckboxes($js);
44 44
 		}
45
-		if($this->_visibleHover){
46
-			$js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]);
47
-			$js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]);
45
+		if ($this->_visibleHover) {
46
+			$js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]);
47
+			$js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]);
48 48
 		}
49
-		if(\is_array($this->_deleteBehavior))
50
-			$this->_generateBehavior("delete",$this->_deleteBehavior, $js);
51
-		if(\is_array($this->_editBehavior))
52
-			$this->_generateBehavior("edit",$this->_editBehavior,$js);
49
+		if (\is_array($this->_deleteBehavior))
50
+			$this->_generateBehavior("delete", $this->_deleteBehavior, $js);
51
+		if (\is_array($this->_editBehavior))
52
+			$this->_generateBehavior("edit", $this->_editBehavior, $js);
53 53
 		return parent::run($js);
54 54
 	}
55 55
 
56 56
 
57 57
 
58
-	protected function _generateBehavior($op,$params,JsUtils $js){
59
-		if(isset($this->_urls[$op])){
60
-			$params=\array_merge($params,["attr"=>"data-ajax"]);
61
-			$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector(),$params);
58
+	protected function _generateBehavior($op, $params, JsUtils $js) {
59
+		if (isset($this->_urls[$op])) {
60
+			$params=\array_merge($params, ["attr"=>"data-ajax"]);
61
+			$js->getOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector(), $params);
62 62
 		}
63 63
 	}
64 64
 
@@ -71,62 +71,62 @@  discard block
 block discarded – undo
71 71
 	}
72 72
 
73 73
 
74
-	public function compile(JsUtils $js=NULL,&$view=NULL){
75
-		if(!$this->_generated){
74
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
75
+		if (!$this->_generated) {
76 76
 			$this->_instanceViewer->setInstance($this->_model);
77 77
 			$captions=$this->_instanceViewer->getCaptions();
78 78
 
79 79
 			$table=$this->content["table"];
80 80
 
81
-			if($this->_hasCheckboxes){
81
+			if ($this->_hasCheckboxes) {
82 82
 				$this->_generateMainCheckbox($captions);
83 83
 			}
84 84
 
85 85
 			$table->setRowCount(0, \sizeof($captions));
86 86
 			$table->setHeaderValues($captions);
87
-			if(isset($this->_compileParts))
87
+			if (isset($this->_compileParts))
88 88
 				$table->setCompileParts($this->_compileParts);
89 89
 
90
-			if(isset($this->_searchField) && isset($js)){
91
-				if(isset($this->_urls["refresh"]))
92
-					$this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]);
90
+			if (isset($this->_searchField) && isset($js)) {
91
+				if (isset($this->_urls["refresh"]))
92
+					$this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]);
93 93
 			}
94 94
 
95 95
 			$this->_generateContent($table);
96 96
 
97
-			if($this->_hasCheckboxes && $table->hasPart("thead")){
97
+			if ($this->_hasCheckboxes && $table->hasPart("thead")) {
98 98
 					$table->getHeader()->getCell(0, 0)->addClass("no-sort");
99 99
 			}
100 100
 
101
-			if(isset($this->_pagination) && $this->_pagination->getVisible()){
101
+			if (isset($this->_pagination) && $this->_pagination->getVisible()) {
102 102
 				$this->_generatePagination($table);
103 103
 			}
104
-			if(isset($this->_toolbar)){
104
+			if (isset($this->_toolbar)) {
105 105
 				$this->_setToolbarPosition($table, $captions);
106 106
 			}
107
-			$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]);
107
+			$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]);
108 108
 			$this->_compileForm();
109 109
 			$this->_generated=true;
110 110
 		}
111
-		return parent::compile($js,$view);
111
+		return parent::compile($js, $view);
112 112
 	}
113 113
 
114 114
 
115 115
 
116
-	protected function _generateContent($table){
116
+	protected function _generateContent($table) {
117 117
 		$objects=$this->_modelInstance;
118
-		if(isset($this->_pagination)){
118
+		if (isset($this->_pagination)) {
119 119
 			$objects=$this->_pagination->getObjects($this->_modelInstance);
120 120
 		}
121 121
 		InstanceViewer::setIndex(0);
122 122
 		$table->fromDatabaseObjects($objects, function($instance) use($table){
123 123
 			$this->_instanceViewer->setInstance($instance);
124 124
 			InstanceViewer::$index++;
125
-			$values= $this->_instanceViewer->getValues();
126
-			if($this->_hasCheckboxes){
127
-				$ck=new HtmlCheckbox("ck-".$this->identifier,"");
125
+			$values=$this->_instanceViewer->getValues();
126
+			if ($this->_hasCheckboxes) {
127
+				$ck=new HtmlCheckbox("ck-".$this->identifier, "");
128 128
 				$field=$ck->getField();
129
-				$field->setProperty("value",$this->_instanceViewer->getIdentifier());
129
+				$field->setProperty("value", $this->_instanceViewer->getIdentifier());
130 130
 				$field->setProperty("name", "selection[]");
131 131
 				\array_unshift($values, $ck);
132 132
 			}
@@ -137,37 +137,37 @@  discard block
 block discarded – undo
137 137
 		});
138 138
 	}
139 139
 
140
-	private function _generatePagination($table){
140
+	private function _generatePagination($table) {
141 141
 		$footer=$table->getFooter();
142 142
 		$footer->mergeCol();
143
-		$menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers());
143
+		$menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers());
144 144
 		$menu->floatRight();
145 145
 		$menu->setActiveItem($this->_pagination->getPage()-1);
146 146
 		$footer->setValues($menu);
147
-		if(isset($this->_urls["refresh"]))
148
-			$menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]);
147
+		if (isset($this->_urls["refresh"]))
148
+			$menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]);
149 149
 	}
150 150
 
151
-	protected function _getFieldName($index){
151
+	protected function _getFieldName($index) {
152 152
 		return parent::_getFieldName($index)."[]";
153 153
 	}
154 154
 
155
-	protected function _getFieldCaption($index){
155
+	protected function _getFieldCaption($index) {
156 156
 		return null;
157 157
 	}
158 158
 
159
-	protected function _setToolbarPosition($table,$captions=NULL){
160
-		switch ($this->_toolbarPosition){
159
+	protected function _setToolbarPosition($table, $captions=NULL) {
160
+		switch ($this->_toolbarPosition) {
161 161
 			case PositionInTable::BEFORETABLE:
162 162
 			case PositionInTable::AFTERTABLE:
163
-				if(isset($this->_compileParts)===false){
163
+				if (isset($this->_compileParts)===false) {
164 164
 					$this->content[$this->_toolbarPosition]=$this->_toolbar;
165 165
 				}
166 166
 				break;
167 167
 			case PositionInTable::HEADER:
168 168
 			case PositionInTable::FOOTER:
169 169
 			case PositionInTable::BODY:
170
-				$this->addToolbarRow($this->_toolbarPosition,$table, $captions);
170
+				$this->addToolbarRow($this->_toolbarPosition, $table, $captions);
171 171
 				break;
172 172
 		}
173 173
 	}
@@ -179,23 +179,23 @@  discard block
 block discarded – undo
179 179
 	 * @param callable $callback function called after the field compilation
180 180
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
181 181
 	 */
182
-	public function afterCompile($index,$callback){
183
-		$this->_instanceViewer->afterCompile($index,$callback);
182
+	public function afterCompile($index, $callback) {
183
+		$this->_instanceViewer->afterCompile($index, $callback);
184 184
 		return $this;
185 185
 	}
186 186
 
187
-	private function addToolbarRow($part,$table,$captions){
187
+	private function addToolbarRow($part, $table, $captions) {
188 188
 		$hasPart=$table->hasPart($part);
189
-		if($hasPart){
189
+		if ($hasPart) {
190 190
 			$row=$table->getPart($part)->addRow(\sizeof($captions));
191
-		}else{
191
+		} else {
192 192
 			$row=$table->getPart($part)->getRow(0);
193 193
 		}
194 194
 		$row->mergeCol();
195 195
 		$row->setValues([$this->_toolbar]);
196 196
 	}
197 197
 
198
-	public function getHtmlComponent(){
198
+	public function getHtmlComponent() {
199 199
 		return $this->content["table"];
200 200
 	}
201 201
 
@@ -209,36 +209,36 @@  discard block
 block discarded – undo
209 209
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
210 210
 	 */
211 211
 	public function setUrls($urls) {
212
-		if(\is_array($urls)){
213
-			$this->_urls["refresh"]=JArray::getValue($urls, "refresh",0);
214
-			$this->_urls["edit"]=JArray::getValue($urls, "edit",1);
215
-			$this->_urls["delete"]=JArray::getValue($urls, "delete",2);
216
-		}else{
217
-			$this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls];
212
+		if (\is_array($urls)) {
213
+			$this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0);
214
+			$this->_urls["edit"]=JArray::getValue($urls, "edit", 1);
215
+			$this->_urls["delete"]=JArray::getValue($urls, "delete", 2);
216
+		} else {
217
+			$this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls];
218 218
 		}
219 219
 		return $this;
220 220
 	}
221 221
 
222
-	public function paginate($items_per_page=10,$page=1){
223
-		$this->_pagination=new Pagination($items_per_page,4,$page);
222
+	public function paginate($items_per_page=10, $page=1) {
223
+		$this->_pagination=new Pagination($items_per_page, 4, $page);
224 224
 	}
225 225
 
226 226
 
227 227
 
228
-	public function refresh($compileParts=["tbody"]){
228
+	public function refresh($compileParts=["tbody"]) {
229 229
 		$this->_compileParts=$compileParts;
230 230
 		return $this;
231 231
 	}
232 232
 
233 233
 
234
-	public function addSearchInToolbar($position=Direction::RIGHT){
234
+	public function addSearchInToolbar($position=Direction::RIGHT) {
235 235
 		return $this->addInToolbar($this->getSearchField())->setPosition($position);
236 236
 	}
237 237
 
238
-	public function getSearchField(){
239
-		if(isset($this->_searchField)===false){
240
-			$this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search...");
241
-			$this->_searchField->addIcon("search",Direction::RIGHT);
238
+	public function getSearchField() {
239
+		if (isset($this->_searchField)===false) {
240
+			$this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search...");
241
+			$this->_searchField->addIcon("search", Direction::RIGHT);
242 242
 		}
243 243
 		return $this->_searchField;
244 244
 	}
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		return $this;
255 255
 	}
256 256
 
257
-	public function asForm(){
257
+	public function asForm() {
258 258
 		return $this->getForm();
259 259
 	}
260 260
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 
263 263
 	protected function getTargetSelector() {
264 264
 		$result=$this->_targetSelector;
265
-		if(!isset($result))
265
+		if (!isset($result))
266 266
 			$result="#".$this->identifier;
267 267
 		return $result;
268 268
 	}
Please login to merge, or discard this patch.
Ajax/semantic/widgets/datatable/HasCheckboxesTrait.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@  discard block
 block discarded – undo
10 10
  * @author jc
11 11
  * @property string identifier
12 12
  */
13
-trait HasCheckboxesTrait{
13
+trait HasCheckboxesTrait {
14 14
 	protected $_hasCheckboxes;
15 15
 	protected $_hasCheckedMessage=false;
16 16
 	protected $_checkedMessage;
17 17
 	protected $_checkedClass;
18 18
 
19
-	abstract public function addInToolbar($element,$callback=NULL);
19
+	abstract public function addInToolbar($element, $callback=NULL);
20 20
 
21
-	protected function _runCheckboxes(JsUtils $js){
21
+	protected function _runCheckboxes(JsUtils $js) {
22 22
 		$checkedMessageCall="";
23
-		if($this->_hasCheckedMessage){
23
+		if ($this->_hasCheckedMessage) {
24 24
 			$msg=$this->getCheckedMessage();
25 25
 			$checkedMessageFunction="function updateChecked(){var msg='".$msg[0]."',count=\$('#{$this->identifier} [name=\"selection[]\"]:checked').length,all=\$('#{$this->identifier} [name=\"selection[]\"]').length;
26 26
 			if(count==1) msg='".$msg[1]."';
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 						\$('#checked-count-".$this->identifier."').contents().filter(function() {return this.nodeType == 3;}).each(function(){this.textContent = msg.replace('{count}',count);});
29 29
 							\$('#toolbar-{$this->identifier} .visibleOnChecked').toggle(count>0);}\$('#toolbar-".$this->identifier." .visibleOnChecked').hide();";
30 30
 			$checkedMessageCall="updateChecked();";
31
-			if(isset($this->_checkedClass)){
31
+			if (isset($this->_checkedClass)) {
32 32
 				$checkedMessageCall.="$(this).closest('tr').toggleClass('".$this->_checkedClass."',$(this).prop('checked'));";
33 33
 			}
34
-			$js->exec($checkedMessageFunction,true);
34
+			$js->exec($checkedMessageFunction, true);
35 35
 		}
36 36
 		$js->execOn("change", "#".$this->identifier." [name='selection[]']", "
37 37
 				var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true;
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 				if(allChecked) {\$parentCheckbox.checkbox('set checked');}else if(allUnchecked){\$parentCheckbox.checkbox('set unchecked');}else{\$parentCheckbox.checkbox('set indeterminate');};".$checkedMessageCall);
40 40
 	}
41 41
 
42
-	protected function _generateMainCheckbox(&$captions){
43
-		$ck=new HtmlCheckbox("main-ck-".$this->identifier,"");
42
+	protected function _generateMainCheckbox(&$captions) {
43
+		$ck=new HtmlCheckbox("main-ck-".$this->identifier, "");
44 44
 		$checkedMessageCall="";
45
-		if($this->_hasCheckedMessage)
45
+		if ($this->_hasCheckedMessage)
46 46
 			$checkedMessageCall="updateChecked();";
47 47
 
48 48
 			$ck->setOnChecked($this->_setAllChecked("true").$checkedMessageCall);
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 			\array_unshift($captions, $ck);
51 51
 	}
52 52
 
53
-	protected function _setAllChecked($checked){
53
+	protected function _setAllChecked($checked) {
54 54
 		$result="$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',".$checked.");";
55
-		if(isset($this->_checkedClass)){
55
+		if (isset($this->_checkedClass)) {
56 56
 			$result.="$('#".$this->identifier." tr').toggleClass('".$this->_checkedClass."',".$checked.");";
57 57
 		}
58 58
 		return $result;
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	}
69 69
 
70 70
 	protected function getCheckedMessage() {
71
-		$result= $this->_checkedMessage;
72
-		if(!isset($result)){
73
-			$result=[0=>"none selected",1=>"one item selected","other"=>"{count} items selected"];
71
+		$result=$this->_checkedMessage;
72
+		if (!isset($result)) {
73
+			$result=[0=>"none selected", 1=>"one item selected", "other"=>"{count} items selected"];
74 74
 		}
75 75
 		return $result;
76 76
 	}
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 	 * @param array $checkedMessage
91 91
 	 * @param callable $callback
92 92
 	 */
93
-	public function addCountCheckedInToolbar(array $checkedMessage=null,$callback=null){
94
-		if(isset($checkedMessage))
93
+	public function addCountCheckedInToolbar(array $checkedMessage=null, $callback=null) {
94
+		if (isset($checkedMessage))
95 95
 			$this->_checkedMessage=$checkedMessage;
96 96
 			$checkedMessage=$this->getCheckedMessage();
97 97
 			$this->_hasCheckboxes=true;
98 98
 			$this->_hasCheckedMessage=true;
99
-			$element=new HtmlLabel("checked-count-".$this->identifier,$checkedMessage[0]);
100
-			$this->addInToolbar($element,$callback);
99
+			$element=new HtmlLabel("checked-count-".$this->identifier, $checkedMessage[0]);
100
+			$this->addInToolbar($element, $callback);
101 101
 	}
102 102
 
103 103
 	public function setCheckedClass($_checkedClass) {
Please login to merge, or discard this patch.