Completed
Push — master ( 303753...a4b8a4 )
by Jean-Christophe
03:17
created
Ajax/semantic/widgets/datatable/DataTable.php 3 patches
Doc Comments   +18 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,6 +40,10 @@  discard block
 block discarded – undo
40 40
 		parent::run($js);
41 41
 	}
42 42
 
43
+	/**
44
+	 * @param string $identifier
45
+	 * @param string $model
46
+	 */
43 47
 	public function __construct($identifier,$model,$modelInstance=NULL) {
44 48
 		parent::__construct($identifier, $model,$modelInstance);
45 49
 		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
@@ -154,6 +158,9 @@  discard block
 block discarded – undo
154 158
 		return $this;
155 159
 	}
156 160
 
161
+	/**
162
+	 * @param PositionInTable $part
163
+	 */
157 164
 	private function addToolbarRow($part,$table,$captions){
158 165
 		$hasPart=$table->hasPart($part);
159 166
 		if($hasPart){
@@ -198,7 +205,7 @@  discard block
 block discarded – undo
198 205
 	/**
199 206
 	 * @param string $caption
200 207
 	 * @param callable $callback
201
-	 * @return callable
208
+	 * @return \Closure
202 209
 	 */
203 210
 	private function getFieldButtonCallable($caption,$callback=null){
204 211
 		return $this->getCallable("getFieldButton",[$caption],$callback);
@@ -206,9 +213,9 @@  discard block
 block discarded – undo
206 213
 
207 214
 	/**
208 215
 	 * @param callable $thisCallback
209
-	 * @param array $parameters
216
+	 * @param string[] $parameters
210 217
 	 * @param callable $callback
211
-	 * @return callable
218
+	 * @return \Closure
212 219
 	 */
213 220
 	private function getCallable($thisCallback,$parameters,$callback=null){
214 221
 		$result=function($instance) use($thisCallback,$parameters,$callback){
@@ -269,11 +276,19 @@  discard block
 block discarded – undo
269 276
 		return $this;
270 277
 	}
271 278
 
279
+	/**
280
+	 * @param string $icon
281
+	 * @param string $class
282
+	 */
272 283
 	private function addDefaultButton($icon,$class=null,$callback=null){
273 284
 		$this->addField($this->getCallable("getDefaultButton",[$icon,$class],$callback));
274 285
 		return $this;
275 286
 	}
276 287
 
288
+	/**
289
+	 * @param string $icon
290
+	 * @param string $class
291
+	 */
277 292
 	private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){
278 293
 		$this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class],$callback));
279 294
 		return $this;
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	protected $_hasCheckboxes;
31 31
 	protected $_compileParts;
32 32
 
33
-	public function run(JsUtils $js){
34
-		if($this->_hasCheckboxes && isset($js)){
33
+	public function run(JsUtils $js) {
34
+		if ($this->_hasCheckboxes && isset($js)) {
35 35
 			$js->execOn("change", "#".$this->identifier." [name='selection[]']", "
36 36
 		var \$parentCheckbox=\$('#ck-main-ck-{$this->identifier}'),\$checkbox=\$('#{$this->identifier} [name=\"selection[]\"]'),allChecked=true,allUnchecked=true;
37 37
 		\$checkbox.each(function() {if($(this).prop('checked')){allUnchecked = false;}else{allChecked = false;}});
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		parent::run($js);
41 41
 	}
42 42
 
43
-	public function __construct($identifier,$model,$modelInstance=NULL) {
44
-		parent::__construct($identifier, $model,$modelInstance);
45
-		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false);
43
+	public function __construct($identifier, $model, $modelInstance=NULL) {
44
+		parent::__construct($identifier, $model, $modelInstance);
45
+		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false);
46 46
 	}
47 47
 
48 48
 	/**
@@ -54,61 +54,61 @@  discard block
 block discarded – undo
54 54
 	}
55 55
 
56 56
 
57
-	public function compile(JsUtils $js=NULL,&$view=NULL){
57
+	public function compile(JsUtils $js=NULL, &$view=NULL) {
58 58
 		$this->_instanceViewer->setInstance($this->_model);
59 59
 		$captions=$this->_instanceViewer->getCaptions();
60 60
 
61 61
 		$table=$this->content["table"];
62 62
 
63
-		if($this->_hasCheckboxes){
63
+		if ($this->_hasCheckboxes) {
64 64
 			$this->_generateMainCheckbox($captions);
65 65
 		}
66 66
 
67 67
 		$table->setRowCount(0, \sizeof($captions));
68 68
 		$table->setHeaderValues($captions);
69
-		if(isset($this->_compileParts))
69
+		if (isset($this->_compileParts))
70 70
 			$table->setCompileParts($this->_compileParts);
71
-		if(isset($this->_searchField) && isset($js)){
72
-			$this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]);
71
+		if (isset($this->_searchField) && isset($js)) {
72
+			$this->_searchField->postOn("change", $this->_urls, "{'s':$(this).val()}", "-#".$this->identifier." tbody", ["preventDefault"=>false]);
73 73
 		}
74 74
 
75 75
 		$this->_generateContent($table);
76 76
 
77
-		if($this->_hasCheckboxes && $table->hasPart("thead")){
78
-				$table->getHeader()->getCell(0, 0)->addToProperty("class","no-sort");
77
+		if ($this->_hasCheckboxes && $table->hasPart("thead")) {
78
+				$table->getHeader()->getCell(0, 0)->addToProperty("class", "no-sort");
79 79
 		}
80 80
 
81
-		if(isset($this->_pagination) && $this->_pagination->getVisible()){
81
+		if (isset($this->_pagination) && $this->_pagination->getVisible()) {
82 82
 			$this->_generatePagination($table);
83 83
 		}
84
-		if(isset($this->_toolbar)){
84
+		if (isset($this->_toolbar)) {
85 85
 			$this->_setToolbarPosition($table, $captions);
86 86
 		}
87
-		$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]);
88
-		return parent::compile($js,$view);
87
+		$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]);
88
+		return parent::compile($js, $view);
89 89
 	}
90 90
 
91
-	private function _generateMainCheckbox(&$captions){
92
-		$ck=new HtmlCheckbox("main-ck-".$this->identifier,"");
91
+	private function _generateMainCheckbox(&$captions) {
92
+		$ck=new HtmlCheckbox("main-ck-".$this->identifier, "");
93 93
 		$ck->setOnChecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',true);");
94 94
 		$ck->setOnUnchecked("$('#".$this->identifier." [name=%quote%selection[]%quote%]').prop('checked',false);");
95 95
 		\array_unshift($captions, $ck);
96 96
 	}
97 97
 
98
-	protected function _generateContent($table){
98
+	protected function _generateContent($table) {
99 99
 		$objects=$this->_modelInstance;
100
-		if(isset($this->_pagination)){
100
+		if (isset($this->_pagination)) {
101 101
 			$objects=$this->_pagination->getObjects($this->_modelInstance);
102 102
 		}
103 103
 		InstanceViewer::setIndex(0);
104
-		$table->fromDatabaseObjects($objects, function($instance){
104
+		$table->fromDatabaseObjects($objects, function($instance) {
105 105
 			$this->_instanceViewer->setInstance($instance);
106 106
 			InstanceViewer::$index++;
107
-			$result= $this->_instanceViewer->getValues();
108
-			if($this->_hasCheckboxes){
109
-				$ck=new HtmlCheckbox("ck-".$this->identifier,"");
107
+			$result=$this->_instanceViewer->getValues();
108
+			if ($this->_hasCheckboxes) {
109
+				$ck=new HtmlCheckbox("ck-".$this->identifier, "");
110 110
 				$field=$ck->getField();
111
-				$field->setProperty("value",$this->_instanceViewer->getIdentifier());
111
+				$field->setProperty("value", $this->_instanceViewer->getIdentifier());
112 112
 				$field->setProperty("name", "selection[]");
113 113
 				\array_unshift($result, $ck);
114 114
 			}
@@ -116,28 +116,28 @@  discard block
 block discarded – undo
116 116
 		});
117 117
 	}
118 118
 
119
-	private function _generatePagination($table){
119
+	private function _generatePagination($table) {
120 120
 		$footer=$table->getFooter();
121 121
 		$footer->mergeCol();
122
-		$menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers());
122
+		$menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers());
123 123
 		$menu->floatRight();
124 124
 		$menu->setActiveItem($this->_pagination->getPage()-1);
125 125
 		$footer->setValues($menu);
126
-		$menu->postOnClick($this->_urls,"{'p':$(this).attr('data-page')}","-#".$this->identifier." tbody",["preventDefault"=>false]);
126
+		$menu->postOnClick($this->_urls, "{'p':$(this).attr('data-page')}", "-#".$this->identifier." tbody", ["preventDefault"=>false]);
127 127
 	}
128 128
 
129
-	protected function _setToolbarPosition($table,$captions=NULL){
130
-		switch ($this->_toolbarPosition){
129
+	protected function _setToolbarPosition($table, $captions=NULL) {
130
+		switch ($this->_toolbarPosition) {
131 131
 			case PositionInTable::BEFORETABLE:
132 132
 			case PositionInTable::AFTERTABLE:
133
-				if(isset($this->_compileParts)===false){
133
+				if (isset($this->_compileParts)===false) {
134 134
 					$this->content[$this->_toolbarPosition]=$this->_toolbar;
135 135
 				}
136 136
 				break;
137 137
 			case PositionInTable::HEADER:
138 138
 			case PositionInTable::FOOTER:
139 139
 			case PositionInTable::BODY:
140
-				$this->addToolbarRow($this->_toolbarPosition,$table, $captions);
140
+				$this->addToolbarRow($this->_toolbarPosition, $table, $captions);
141 141
 				break;
142 142
 		}
143 143
 	}
@@ -149,23 +149,23 @@  discard block
 block discarded – undo
149 149
 	 * @param callable $callback function called after the field compilation
150 150
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
151 151
 	 */
152
-	public function afterCompile($index,$callback){
153
-		$this->_instanceViewer->afterCompile($index,$callback);
152
+	public function afterCompile($index, $callback) {
153
+		$this->_instanceViewer->afterCompile($index, $callback);
154 154
 		return $this;
155 155
 	}
156 156
 
157
-	private function addToolbarRow($part,$table,$captions){
157
+	private function addToolbarRow($part, $table, $captions) {
158 158
 		$hasPart=$table->hasPart($part);
159
-		if($hasPart){
159
+		if ($hasPart) {
160 160
 			$row=$table->getPart($part)->addRow(\sizeof($captions));
161
-		}else{
161
+		} else {
162 162
 			$row=$table->getPart($part)->getRow(0);
163 163
 		}
164 164
 		$row->mergeCol();
165 165
 		$row->setValues([$this->_toolbar]);
166 166
 	}
167 167
 
168
-	public function getHtmlComponent(){
168
+	public function getHtmlComponent() {
169 169
 		return $this->content["table"];
170 170
 	}
171 171
 
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
 		return $this;
179 179
 	}
180 180
 
181
-	public function paginate($items_per_page=10,$page=1){
182
-		$this->_pagination=new Pagination($items_per_page,4,$page);
181
+	public function paginate($items_per_page=10, $page=1) {
182
+		$this->_pagination=new Pagination($items_per_page, 4, $page);
183 183
 	}
184 184
 
185 185
 	public function getHasCheckboxes() {
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		return $this;
192 192
 	}
193 193
 
194
-	public function refresh($compileParts=["tbody"]){
194
+	public function refresh($compileParts=["tbody"]) {
195 195
 		$this->_compileParts=$compileParts;
196 196
 		return $this;
197 197
 	}
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 	 * @param callable $callback
201 201
 	 * @return callable
202 202
 	 */
203
-	private function getFieldButtonCallable($caption,$callback=null){
204
-		return $this->getCallable("getFieldButton",[$caption],$callback);
203
+	private function getFieldButtonCallable($caption, $callback=null) {
204
+		return $this->getCallable("getFieldButton", [$caption], $callback);
205 205
 	}
206 206
 
207 207
 	/**
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
 	 * @param callable $callback
211 211
 	 * @return callable
212 212
 	 */
213
-	private function getCallable($thisCallback,$parameters,$callback=null){
214
-		$result=function($instance) use($thisCallback,$parameters,$callback){
215
-			$object=call_user_func_array(array($this,$thisCallback), $parameters);
216
-			if(isset($callback)){
217
-				if(\is_callable($callback)){
218
-					$callback($object,$instance);
213
+	private function getCallable($thisCallback, $parameters, $callback=null) {
214
+		$result=function($instance) use($thisCallback, $parameters, $callback){
215
+			$object=call_user_func_array(array($this, $thisCallback), $parameters);
216
+			if (isset($callback)) {
217
+				if (\is_callable($callback)) {
218
+					$callback($object, $instance);
219 219
 				}
220 220
 			}
221
-			if($object instanceof HtmlSemDoubleElement){
222
-				$object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier());
221
+			if ($object instanceof HtmlSemDoubleElement) {
222
+				$object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier());
223 223
 			}
224 224
 			return $object;
225 225
 		};
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * @param string $caption
231 231
 	 * @return HtmlButton
232 232
 	 */
233
-	private function getFieldButton($caption){
234
-		return new HtmlButton("",$caption);
233
+	private function getFieldButton($caption) {
234
+		return new HtmlButton("", $caption);
235 235
 	}
236 236
 
237 237
 	/**
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * @param callable $callback
241 241
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
242 242
 	 */
243
-	public function addFieldButton($caption,$callback=null){
244
-		$this->addField($this->getCallable("getFieldButton",[$caption],$callback));
243
+	public function addFieldButton($caption, $callback=null) {
244
+		$this->addField($this->getCallable("getFieldButton", [$caption], $callback));
245 245
 		return $this;
246 246
 	}
247 247
 
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @param callable $callback
253 253
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
254 254
 	 */
255
-	public function insertFieldButton($index,$caption,$callback=null){
256
-		$this->insertField($index, $this->getFieldButtonCallable($caption,$callback));
255
+	public function insertFieldButton($index, $caption, $callback=null) {
256
+		$this->insertField($index, $this->getFieldButtonCallable($caption, $callback));
257 257
 		return $this;
258 258
 	}
259 259
 
@@ -264,60 +264,60 @@  discard block
 block discarded – undo
264 264
 	 * @param callable $callback
265 265
 	 * @return \Ajax\semantic\widgets\datatable\DataTable
266 266
 	 */
267
-	public function insertInFieldButton($index,$caption,$callback=null){
268
-		$this->insertInField($index, $this->getFieldButtonCallable($caption,$callback));
267
+	public function insertInFieldButton($index, $caption, $callback=null) {
268
+		$this->insertInField($index, $this->getFieldButtonCallable($caption, $callback));
269 269
 		return $this;
270 270
 	}
271 271
 
272
-	private function addDefaultButton($icon,$class=null,$callback=null){
273
-		$this->addField($this->getCallable("getDefaultButton",[$icon,$class],$callback));
272
+	private function addDefaultButton($icon, $class=null, $callback=null) {
273
+		$this->addField($this->getCallable("getDefaultButton", [$icon, $class], $callback));
274 274
 		return $this;
275 275
 	}
276 276
 
277
-	private function insertDefaultButtonIn($index,$icon,$class=null,$callback=null){
278
-		$this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class],$callback));
277
+	private function insertDefaultButtonIn($index, $icon, $class=null, $callback=null) {
278
+		$this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class], $callback));
279 279
 		return $this;
280 280
 	}
281 281
 
282
-	private function getDefaultButton($icon,$class=null){
282
+	private function getDefaultButton($icon, $class=null) {
283 283
 		$bt=$this->getFieldButton("");
284 284
 		$bt->asIcon($icon);
285
-		if(isset($class))
285
+		if (isset($class))
286 286
 			$bt->addToProperty("class", $class);
287 287
 		return $bt;
288 288
 	}
289 289
 
290
-	public function addDeleteButton($callback=null){
291
-		return $this->addDefaultButton("remove","delete red basic",$callback);
290
+	public function addDeleteButton($callback=null) {
291
+		return $this->addDefaultButton("remove", "delete red basic", $callback);
292 292
 	}
293 293
 
294
-	public function addEditButton($callback=null){
295
-		return $this->addDefaultButton("edit","edit basic",$callback);
294
+	public function addEditButton($callback=null) {
295
+		return $this->addDefaultButton("edit", "edit basic", $callback);
296 296
 	}
297 297
 
298
-	public function addEditDeleteButtons($callbackEdit=null,$callbackDelete=null){
298
+	public function addEditDeleteButtons($callbackEdit=null, $callbackDelete=null) {
299 299
 		$this->addEditButton($callbackEdit);
300 300
 		$index=$this->_instanceViewer->visiblePropertiesCount()-1;
301
-		$this->insertDeleteButtonIn($index,$callbackDelete);
301
+		$this->insertDeleteButtonIn($index, $callbackDelete);
302 302
 		return $this;
303 303
 	}
304 304
 
305
-	public function insertDeleteButtonIn($index,$callback=null){
306
-		return $this->insertDefaultButtonIn($index,"remove","delete red basic",$callback);
305
+	public function insertDeleteButtonIn($index, $callback=null) {
306
+		return $this->insertDefaultButtonIn($index, "remove", "delete red basic", $callback);
307 307
 	}
308 308
 
309
-	public function insertEditButtonIn($index,$callback=null){
310
-		return $this->insertDefaultButtonIn($index,"edit","edit basic",$callback);
309
+	public function insertEditButtonIn($index, $callback=null) {
310
+		return $this->insertDefaultButtonIn($index, "edit", "edit basic", $callback);
311 311
 	}
312 312
 
313
-	public function addSearchInToolbar($position=Direction::RIGHT){
313
+	public function addSearchInToolbar($position=Direction::RIGHT) {
314 314
 		return $this->addInToolbar($this->getSearchField())->setPosition($position);
315 315
 	}
316 316
 
317
-	public function getSearchField(){
318
-		if(isset($this->_searchField)===false){
319
-			$this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search...");
320
-			$this->_searchField->addIcon("search",Direction::RIGHT);
317
+	public function getSearchField() {
318
+		if (isset($this->_searchField)===false) {
319
+			$this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search...");
320
+			$this->_searchField->addIcon("search", Direction::RIGHT);
321 321
 		}
322 322
 		return $this->_searchField;
323 323
 	}
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,8 +66,9 @@  discard block
 block discarded – undo
66 66
 
67 67
 		$table->setRowCount(0, \sizeof($captions));
68 68
 		$table->setHeaderValues($captions);
69
-		if(isset($this->_compileParts))
70
-			$table->setCompileParts($this->_compileParts);
69
+		if(isset($this->_compileParts)) {
70
+					$table->setCompileParts($this->_compileParts);
71
+		}
71 72
 		if(isset($this->_searchField) && isset($js)){
72 73
 			$this->_searchField->postOn("change", $this->_urls,"{'s':$(this).val()}","-#".$this->identifier." tbody",["preventDefault"=>false]);
73 74
 		}
@@ -158,7 +159,7 @@  discard block
 block discarded – undo
158 159
 		$hasPart=$table->hasPart($part);
159 160
 		if($hasPart){
160 161
 			$row=$table->getPart($part)->addRow(\sizeof($captions));
161
-		}else{
162
+		} else{
162 163
 			$row=$table->getPart($part)->getRow(0);
163 164
 		}
164 165
 		$row->mergeCol();
@@ -282,8 +283,9 @@  discard block
 block discarded – undo
282 283
 	private function getDefaultButton($icon,$class=null){
283 284
 		$bt=$this->getFieldButton("");
284 285
 		$bt->asIcon($icon);
285
-		if(isset($class))
286
-			$bt->addToProperty("class", $class);
286
+		if(isset($class)) {
287
+					$bt->addToProperty("class", $class);
288
+		}
287 289
 		return $bt;
288 290
 	}
289 291
 
Please login to merge, or discard this patch.