Passed
Push — master ( 336023...99e98a )
by Jean-Christophe
02:32
created

DataTable   F

Complexity

Total Complexity 121

Size/Duplication

Total Lines 686
Duplicated Lines 0 %

Importance

Changes 36
Bugs 4 Features 2
Metric Value
eloc 300
c 36
b 4
f 2
dl 0
loc 686
rs 2
wmc 121

59 Methods

Rating   Name   Duplication   Size   Complexity  
B _setToolbarPosition() 0 13 7
A setDisplayBehavior() 0 2 1
A setEmptyMessage() 0 3 1
A compile() 0 32 5
A setActiveRowSelector() 0 3 1
A getRefreshSelector() 0 4 2
A getDeleteBehavior() 0 2 1
A compileExtraElements() 0 12 6
A setRefreshSelector() 0 3 1
A setGroupByFields() 0 2 1
A _associatePaginationBehavior() 0 13 5
A __construct() 0 6 1
A onNewRow() 0 3 1
A getFieldValue() 0 9 3
A _generateContent() 0 28 5
A getEditBehavior() 0 2 1
A setSortable() 0 3 1
A afterCompile() 0 3 1
A _generateHeader() 0 4 2
A setTargetSelector() 0 9 2
A _associateSearchFieldBehavior() 0 1 1
A _generatePagination() 0 9 3
A setRowClass() 0 3 1
A trigger() 0 2 1
A setColWidth() 0 3 1
A setColWidths() 0 3 1
A getTargetSelector() 0 5 2
A setUrls() 0 15 2
A _getFieldName() 0 5 2
A getPaginationToolbar() 0 2 1
A setColAlignment() 0 3 1
A refreshTR() 0 3 1
A onActiveRowChange() 0 3 1
A setVisibleHover() 0 2 1
A getHtmlComponent() 0 2 1
A autoPaginate() 0 3 1
A addToolbarRow() 0 10 2
A getSearchField() 0 6 2
A getElementContent() 0 5 2
A show() 0 6 4
B run() 0 28 9
A _hideColumns() 0 5 2
A refresh() 0 5 1
A paginate() 0 3 1
A getDisplayBehavior() 0 2 1
A refreshTD() 0 6 1
A hideColumn() 0 5 2
A getUrls() 0 2 1
A getGroupByFields() 0 2 1
A _generateGroupByRow() 0 15 3
A addSearchInToolbar() 0 3 1
A _getFieldCaption() 0 2 1
A _compileSearchFieldBehavior() 0 7 4
A getTable() 0 2 1
A getRowClass() 0 2 1
A _generateBehavior() 0 6 2
A asForm() 0 2 1
A _applyStyleAttributes() 0 6 4
A _generateRow() 0 33 5

How to fix   Complexity   

Complex Class

Complex classes like DataTable often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DataTable, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace Ajax\semantic\widgets\datatable;
3
4
use Ajax\JsUtils;
5
use Ajax\common\Widget;
6
use Ajax\common\html\HtmlDoubleElement;
7
use Ajax\semantic\html\base\constants\Direction;
8
use Ajax\semantic\html\base\traits\BaseTrait;
9
use Ajax\semantic\html\collections\HtmlMessage;
10
use Ajax\semantic\html\collections\table\HtmlTable;
11
use Ajax\semantic\html\collections\table\traits\TableTrait;
12
use Ajax\semantic\html\elements\HtmlInput;
13
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox;
14
use Ajax\semantic\widgets\base\InstanceViewer;
15
use Ajax\service\JArray;
16
use Ajax\service\JString;
17
18
/**
19
 * DataTable widget for displaying list of objects
20
 *
21
 * @version 1.1.0
22
 * @author jc
23
 * @since 2.2
24
 *
25
 */
26
class DataTable extends Widget {
27
	use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait;
28
29
	protected $_searchField;
30
31
	protected $_urls;
32
33
	protected $_pagination;
34
35
	protected $_compileParts;
36
37
	protected $_deleteBehavior;
38
39
	protected $_editBehavior;
40
41
	protected $_displayBehavior;
42
43
	protected $_visibleHover = false;
44
45
	protected $_targetSelector;
46
47
	protected $_refreshSelector;
48
49
	protected $_emptyMessage;
50
51
	protected $_json;
52
53
	protected $_rowClass = "_element";
54
55
	protected $_sortable;
56
57
	protected $_hiddenColumns;
58
59
	protected $_colWidths;
60
	
61
	protected $_paginationToolbar;
62
63
	public function __construct($identifier, $model, $modelInstance = NULL) {
64
		parent::__construct($identifier, $model, $modelInstance);
65
		$this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false);
66
		$this->_urls = [];
67
		$this->_emptyMessage = new HtmlMessage("", "nothing to display");
68
		$this->_emptyMessage->setIcon("info circle");
69
	}
70
71
	public function run(JsUtils $js) {
72
		if ($this->_runned !== true) {
73
			$offset = $js->scriptCount();
74
			if ($this->_hasCheckboxes && isset($js)) {
75
				$this->_runCheckboxes($js);
76
			}
77
			if ($this->_visibleHover) {
78
				$js->execOn("mouseover", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'visible');", [
79
					"preventDefault" => false,
80
					"stopPropagation" => true
81
				]);
82
				$js->execOn("mouseout", "#" . $this->identifier . " tr", "$(event.currentTarget).closest('tr').find('.visibleover').css('visibility', 'hidden');$(event.currentTarget).trigger('visibleoverOut');", [
83
					"preventDefault" => false,
84
					"stopPropagation" => true
85
				]);
86
			}
87
			if (\is_array($this->_deleteBehavior))
88
				$this->_generateBehavior("delete", $this->_deleteBehavior, $js);
89
			if (\is_array($this->_editBehavior))
90
				$this->_generateBehavior("edit", $this->_editBehavior, $js);
91
			if (\is_array($this->_displayBehavior)) {
92
				$this->_generateBehavior("display", $this->_displayBehavior, $js);
93
			}
94
			parent::run($js);
95
			if (isset($this->_pagination))
96
				$this->_associatePaginationBehavior($js, $offset);
97
			$this->_associateSearchFieldBehavior($js, $offset);
98
			$this->_runned = true;
99
		}
100
	}
101
102
	protected function _generateBehavior($op, $params, JsUtils $js) {
103
		if (isset($this->_urls[$op])) {
104
			$params = \array_merge($params, [
105
				"attr" => "data-ajax"
106
			]);
107
			$js->ajaxOnClick("#" . $this->identifier . " ._" . $op, $this->_urls[$op], $this->getTargetSelector($op), $params);
108
		}
109
	}
110
111
	/**
112
	 *
113
	 * {@inheritdoc}
114
	 * @see TableTrait::getTable()
115
	 */
116
	protected function getTable() {
117
		return $this->content["table"];
118
	}
119
120
	public function refreshTR() {
121
		$this->getTable()->refreshTR();
122
		return $this;
123
	}
124
125
	public function refreshTD($fieldName, $jquery, $view) {
126
		$index = $this->_getIndex($fieldName);
127
		$this->compile($jquery, $view);
128
		return $this->refreshTR()
129
			->getTable()
130
			->getCell(0, $index);
131
	}
132
133
	public function compile(JsUtils $js = NULL, &$view = NULL) {
134
		if (! $this->_generated) {
135
			if (isset($this->_buttonsColumn)) {
136
				$this->_instanceViewer->sortColumnContent($this->_buttonsColumn, $this->_buttons);
137
			}
138
			$this->_instanceViewer->setInstance($this->_model);
139
			$captions = $this->_instanceViewer->getCaptions();
140
			$table = $this->content["table"];
141
			if ($this->_hasCheckboxes) {
142
				$this->_generateMainCheckbox($captions);
143
			}
144
			$table->setRowCount(0, \sizeof($captions));
145
			$this->_generateHeader($table, $captions);
146
147
			if (isset($this->_compileParts))
148
				$table->setCompileParts($this->_compileParts);
149
150
			$this->_generateContent($table);
151
152
			$this->compileExtraElements($table, $captions);
153
			$this->_compileSearchFieldBehavior($js);
154
155
			$this->content = JArray::sortAssociative($this->content, [
156
				PositionInTable::BEFORETABLE,
157
				"table",
158
				PositionInTable::AFTERTABLE
159
			]);
160
			$this->_compileForm();
161
			$this->_applyStyleAttributes($table);
162
			$this->_generated = true;
163
		}
164
		return parent::compile($js, $view);
165
	}
166
167
	protected function compileExtraElements($table, $captions) {
168
		if ($this->_hasCheckboxes && $table->hasPart("thead")) {
169
			$table->getHeader()
170
				->getCell(0, 0)
171
				->addClass("no-sort");
172
		}
173
174
		if (isset($this->_toolbar)) {
175
			$this->_setToolbarPosition($table, $captions);
176
		}
177
		if (isset($this->_pagination) && $this->_pagination->getVisible()) {
178
			$this->_generatePagination($table);
179
		}
180
	}
181
182
	protected function _applyStyleAttributes($table) {
183
		if (isset($this->_hiddenColumns))
184
			$this->_hideColumns();
185
		if (isset($this->_colWidths)) {
186
			foreach ($this->_colWidths as $colIndex => $width) {
187
				$table->setColWidth($colIndex, $width);
188
			}
189
		}
190
	}
191
192
	protected function _hideColumns() {
193
		foreach ($this->_hiddenColumns as $colIndex) {
194
			$this->_self->hideColumn($colIndex);
195
		}
196
		return $this;
197
	}
198
199
	protected function _generateHeader(HtmlTable $table, $captions) {
200
		$table->setHeaderValues($captions);
201
		if (isset($this->_sortable)) {
202
			$table->setSortable($this->_sortable);
203
		}
204
	}
205
206
	protected function _generateContent($table) {
207
		$objects = $this->_modelInstance;
208
		if (isset($this->_pagination)) {
209
			$objects = $this->_pagination->getObjects($this->_modelInstance);
210
		}
211
		InstanceViewer::setIndex(0);
212
		$fields = $this->_instanceViewer->getSimpleProperties();
213
		$groupByFields = $this->_instanceViewer->getGroupByFields();
214
		if (! is_array($groupByFields)) {
215
			$table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields) {
216
				return $this->_generateRow($instance, $fields, $table);
217
			});
218
		} else {
219
			$activeValues = array_combine($groupByFields, array_fill(0, sizeof($groupByFields), null));
220
			$uuids = [];
221
			$table->fromDatabaseObjects($objects, function ($instance) use ($table, $fields, &$activeValues, $groupByFields, &$uuids) {
222
				$this->_instanceViewer->setInstance($instance);
223
				foreach ($groupByFields as $index => $gbField) {
224
					$this->_generateGroupByRow($index, $gbField, $table, $fields, $activeValues, $uuids);
225
				}
226
				return $this->_generateRow($instance, $fields, $table, null, $uuids);
227
			});
228
		}
229
		if ($table->getRowCount() == 0) {
230
			$result = $table->addRow();
231
			$result->mergeRow();
232
			$result->setValues([
233
				$this->_emptyMessage
234
			]);
235
		}
236
	}
237
238
	protected function _generateGroupByRow($index, $gbField, $table, $fields, &$activeValues, &$uuids) {
239
		$newValue = $this->_instanceViewer->getValue($gbField);
240
		if ($this->getElementContent($activeValues[$gbField]) !== $this->getElementContent($newValue)) {
241
			if ($index == 0) {
242
				$uuids = [];
243
			}
244
			$uuid = uniqid("grp");
245
			$uuids[$gbField] = $uuid;
246
			$id = $this->_instanceViewer->getIdentifier();
247
			$result = $table->addMergeRow(sizeof($fields) + 1, $newValue);
248
			$result->setIdentifier($this->identifier . "-tr-gb-" . $id);
249
			$result->setProperty("data-ajax", $id);
250
			$result->setProperty("data-group", $uuid);
251
			$result->addToProperty("class", $this->_rowClass);
252
			$activeValues[$gbField] = $newValue;
253
		}
254
	}
255
256
	private function getElementContent($elm) {
257
		if ($elm instanceof HtmlDoubleElement) {
258
			return $elm->getTextContent();
259
		}
260
		return $elm;
261
	}
262
263
	public function getFieldValue($index) {
264
		$index = $this->_getIndex($index);
265
		if (is_numeric($index)) {
266
			$values = $this->_instanceViewer->getValues();
267
			if (isset($values[$index])) {
268
				return $values[$index];
269
			}
270
		}
271
		return null;
272
	}
273
274
	protected function _generateRow($instance, $fields, &$table, $checkedClass = null, $uuids = null) {
275
		$this->_instanceViewer->setInstance($instance);
276
		InstanceViewer::$index ++;
277
		$values = $this->_instanceViewer->getValues();
278
		$id = $this->_instanceViewer->getIdentifier();
279
		$dataAjax = $id;
280
		$id = $this->cleanIdentifier($id);
281
		if ($this->_hasCheckboxes) {
282
			$ck = new HtmlCheckbox("ck-" . $this->identifier . "-" . $id, "");
283
			$checked = false;
284
			if (isset($this->_checkedCallback)) {
285
				$func = $this->_checkedCallback;
286
				$checked = $func($instance);
287
			}
288
			$ck->setChecked($checked);
289
			// $ck->setOnChange("event.stopPropagation();");
290
			$field = $ck->getField();
291
			$field->setProperty("value", $dataAjax);
292
			$field->setProperty("name", "selection[]");
293
			if (isset($checkedClass))
294
				$field->setClass($checkedClass);
295
			\array_unshift($values, $ck);
296
		}
297
		$result = $table->newRow();
298
		$result->setIdentifier($this->identifier . "-tr-" . $id);
299
		$result->setProperty("data-ajax", $dataAjax);
300
		$result->setValues($values);
301
		$result->addToProperty("class", $this->_rowClass);
302
		$result->setPropertyValues("data-field", $fields);
303
		if (isset($uuids)) {
304
			$result->setProperty("data-child", implode(" ", $uuids));
305
		}
306
		return $result;
307
	}
308
309
	protected function _generatePagination($table) {
310
		if (isset($this->_toolbar)) {
311
			if ($this->_toolbarPosition == PositionInTable::FOOTER)
312
				$this->_toolbar->setFloated("left");
313
		}
314
		$footer = $table->getFooter();
315
		$footer->mergeCol();
316
		$this->_paginationToolbar=$this->_pagination->generateMenu($this->identifier);
317
		$footer->addValues($this->_paginationToolbar);
318
	}
319
320
	protected function _associatePaginationBehavior(JsUtils $js = NULL, $offset = null) {
321
		if (isset($this->_urls["refresh"])) {
322
			$menu = $this->_pagination->getMenu();
323
			if (isset($menu) && isset($js)) {
324
				$js->postOnClick("#" . $menu->getIdentifier() . " .item", $this->_urls["refresh"], "{'p':$(this).attr('data-page'),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", $this->getRefreshSelector(), [
325
					"preventDefault" => false,
326
					"jqueryDone" => "replaceWith",
327
					"hasLoader" => false,
328
					"jsCallback" => '$("#' . $this->identifier . '").trigger("pageChange");$("#' . $this->identifier . '").trigger("activeRowChange");'
329
				]);
330
				$page = $_POST["p"] ?? null;
331
				if (isset($page)) {
332
					$js->execAtLast('$("#' . $this->getIdentifier() . ' .pagination").children("a.item").removeClass("active");$("#' . $this->getIdentifier() . ' .pagination").children("a.item[data-page=' . $page . ']:not(.no-active)").addClass("active");');
333
				}
334
			}
335
		}
336
	}
337
338
	protected function _compileSearchFieldBehavior(JsUtils $js = NULL) {
339
		if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) {
340
			$this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(self).val(),'_model':'" . JString::doubleBackSlashes($this->_model) . "'}", "#" . $this->identifier . " tbody", [
341
				"preventDefault" => false,
342
				"jqueryDone" => "replaceWith",
343
				"hasLoader" => "internal",
344
				"jsCallback" => '$("#' . $this->identifier . '").trigger("searchTerminate",[$(self).val()]);'
345
			]);
346
		}
347
	}
348
349
	protected function _associateSearchFieldBehavior(JsUtils $js = NULL, $offset = null) {}
350
351
	protected function _getFieldName($index) {
352
		$fieldName = parent::_getFieldName($index);
353
		if (\is_object($fieldName))
354
			$fieldName = "field-" . $index;
355
		return $fieldName . "[]";
356
	}
357
358
	protected function _getFieldCaption($index) {
359
		return null;
360
	}
361
362
	protected function _setToolbarPosition($table, $captions = NULL) {
363
		switch ($this->_toolbarPosition) {
364
			case PositionInTable::BEFORETABLE:
365
			case PositionInTable::AFTERTABLE:
366
				if (isset($this->_compileParts) === false) {
367
					$this->content[$this->_toolbarPosition] = $this->_toolbar;
368
				}
369
				break;
370
			case PositionInTable::HEADER:
371
			case PositionInTable::FOOTER:
372
			case PositionInTable::BODY:
373
				$this->addToolbarRow($this->_toolbarPosition, $table, $captions);
374
				break;
375
		}
376
	}
377
378
	/**
379
	 * Associates a $callback function after the compilation of the field at $index position
380
	 * The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position
381
	 *
382
	 * @param int $index
383
	 *        	postion of the compiled field
384
	 * @param callable $callback
385
	 *        	function called after the field compilation
386
	 * @return DataTable
387
	 */
388
	public function afterCompile($index, $callback) {
389
		$this->_instanceViewer->afterCompile($index, $callback);
390
		return $this;
391
	}
392
393
	private function addToolbarRow($part, $table, $captions) {
394
		$hasPart = $table->hasPart($part);
395
		if ($hasPart) {
396
			$row = $table->getPart($part)->addRow(\sizeof($captions));
397
		} else {
398
			$row = $table->getPart($part)->getRow(0);
399
		}
400
		$row->mergeCol();
401
		$row->setValues([
402
			$this->_toolbar
403
		]);
404
	}
405
406
	/**
407
	 *
408
	 * {@inheritdoc}
409
	 * @see Widget::getHtmlComponent()
410
	 * @return HtmlTable
411
	 */
412
	public function getHtmlComponent() {
413
		return $this->content["table"];
414
	}
415
416
	public function getUrls() {
417
		return $this->_urls;
418
	}
419
420
	/**
421
	 * Sets the associative array of urls for refreshing, updating or deleting
422
	 * think of defining the update zone with the setTargetSelector method
423
	 *
424
	 * @param string|array $urls
425
	 *        	associative array with keys refresh: for refreshing with search field or pagination, edit : for updating a row, delete: for deleting a row
426
	 * @return DataTable
427
	 */
428
	public function setUrls($urls) {
429
		if (\is_array($urls)) {
430
			$this->_urls["refresh"] = JArray::getValue($urls, "refresh", 0);
431
			$this->_urls["edit"] = JArray::getValue($urls, "edit", 1);
432
			$this->_urls["delete"] = JArray::getValue($urls, "delete", 2);
433
			$this->_urls["display"] = JArray::getValue($urls, "display", 3);
434
		} else {
435
			$this->_urls = [
436
				"refresh" => $urls,
437
				"edit" => $urls,
438
				"delete" => $urls,
439
				"display" => $urls
440
			];
441
		}
442
		return $this;
443
	}
444
445
	/**
446
	 * Paginates the DataTable element with a Semantic HtmlPaginationMenu component
447
	 *
448
	 * @param number $page
449
	 *        	the active page number
450
	 * @param number $total_rowcount
451
	 *        	the total number of items
452
	 * @param number $items_per_page
453
	 *        	The number of items per page
454
	 * @param number $pages_visibles
455
	 *        	The number of visible pages in the Pagination component
456
	 * @return DataTable
457
	 */
458
	public function paginate($page, $total_rowcount, $items_per_page = 10, $pages_visibles = null) {
459
		$this->_pagination = new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount);
460
		return $this;
461
	}
462
463
	/**
464
	 * Auto Paginates the DataTable element with a Semantic HtmlPaginationMenu component
465
	 *
466
	 * @param number $page
467
	 *        	the active page number
468
	 * @param number $items_per_page
469
	 *        	The number of items per page
470
	 * @param number $pages_visibles
471
	 *        	The number of visible pages in the Pagination component
472
	 * @return DataTable
473
	 */
474
	public function autoPaginate($page = 1, $items_per_page = 10, $pages_visibles = 4) {
475
		$this->_pagination = new Pagination($items_per_page, $pages_visibles, $page);
476
		return $this;
477
	}
478
479
	/**
480
	 *
481
	 * @param array $compileParts
482
	 * @return DataTable
483
	 */
484
	public function refresh($compileParts = [
485
		"tbody"
486
	]) {
487
		$this->_compileParts = $compileParts;
488
		return $this;
489
	}
490
491
	/**
492
	 * Adds a search input in toolbar
493
	 *
494
	 * @param string $position
495
	 * @return \Ajax\common\html\HtmlDoubleElement
496
	 */
497
	public function addSearchInToolbar($position = Direction::RIGHT) {
498
		return $this->addInToolbar($this->getSearchField())
499
			->setPosition($position);
500
	}
501
502
	public function getSearchField() {
503
		if (isset($this->_searchField) === false) {
504
			$this->_searchField = new HtmlInput("search-" . $this->identifier, "search", "", "Search...");
505
			$this->_searchField->addIcon("search", Direction::RIGHT);
506
		}
507
		return $this->_searchField;
508
	}
509
510
	/**
511
	 * The callback function called after the insertion of each row when fromDatabaseObjects is called
512
	 * callback function takes the parameters $row : the row inserted and $object: the instance of model used
513
	 *
514
	 * @param callable $callback
515
	 * @return DataTable
516
	 */
517
	public function onNewRow($callback) {
518
		$this->content["table"]->onNewRow($callback);
519
		return $this;
520
	}
521
522
	/**
523
	 * Returns a form corresponding to the Datatable
524
	 *
525
	 * @return \Ajax\semantic\html\collections\form\HtmlForm
526
	 */
527
	public function asForm() {
528
		return $this->getForm();
529
	}
530
531
	protected function getTargetSelector($op) {
532
		$result = $this->_targetSelector;
533
		if (! isset($result[$op]))
534
			$result = "#" . $this->identifier;
535
		return $result[$op];
536
	}
537
538
	/**
539
	 * Sets the response element selector for Edit and Delete request with ajax
540
	 *
541
	 * @param string|array $_targetSelector
542
	 *        	string or associative array ["edit"=>"edit_selector","delete"=>"delete_selector"]
543
	 * @return DataTable
544
	 */
545
	public function setTargetSelector($_targetSelector) {
546
		if (! \is_array($_targetSelector)) {
547
			$_targetSelector = [
548
				"edit" => $_targetSelector,
549
				"delete" => $_targetSelector
550
			];
551
		}
552
		$this->_targetSelector = $_targetSelector;
553
		return $this;
554
	}
555
556
	public function getRefreshSelector() {
557
		if (isset($this->_refreshSelector))
558
			return $this->_refreshSelector;
559
		return "#" . $this->identifier . " tbody";
560
	}
561
562
	/**
563
	 *
564
	 * @param string $_refreshSelector
565
	 * @return DataTable
566
	 */
567
	public function setRefreshSelector($_refreshSelector) {
568
		$this->_refreshSelector = $_refreshSelector;
569
		return $this;
570
	}
571
572
	/**
573
	 *
574
	 * {@inheritdoc}
575
	 * @see \Ajax\common\Widget::show()
576
	 */
577
	public function show($modelInstance) {
578
		if (\is_array($modelInstance)) {
579
			if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0]))
580
				$modelInstance = \json_decode(\json_encode($modelInstance), FALSE);
581
		}
582
		$this->_modelInstance = $modelInstance;
583
	}
584
585
	public function getRowClass() {
586
		return $this->_rowClass;
587
	}
588
589
	/**
590
	 * Sets the default row class (tr class)
591
	 *
592
	 * @param string $_rowClass
593
	 * @return DataTable
594
	 */
595
	public function setRowClass($_rowClass) {
596
		$this->_rowClass = $_rowClass;
597
		return $this;
598
	}
599
600
	/**
601
	 * Sets the message displayed when there is no record
602
	 *
603
	 * @param mixed $_emptyMessage
604
	 * @return DataTable
605
	 */
606
	public function setEmptyMessage($_emptyMessage) {
607
		$this->_emptyMessage = $_emptyMessage;
608
		return $this;
609
	}
610
611
	public function setSortable($colIndex = NULL) {
612
		$this->_sortable = $colIndex;
613
		return $this;
614
	}
615
616
	public function setActiveRowSelector($class = "active", $event = "click", $multiple = false) {
617
		$this->_self->setActiveRowSelector($class, $event, $multiple);
618
		return $this;
619
	}
620
621
	public function hideColumn($colIndex) {
622
		if (! \is_array($this->_hiddenColumns))
623
			$this->_hiddenColumns = [];
624
		$this->_hiddenColumns[] = $colIndex;
625
		return $this;
626
	}
627
628
	public function setColWidth($colIndex, $width) {
629
		$this->_colWidths[$colIndex] = $width;
630
		return $this;
631
	}
632
633
	public function setColWidths($_colWidths) {
634
		$this->_colWidths = $_colWidths;
635
		return $this;
636
	}
637
638
	public function setColAlignment($colIndex, $alignment) {
639
		$this->content["table"]->setColAlignment($colIndex, $alignment);
640
		return $this;
641
	}
642
643
	public function trigger($event, $params = "[]") {
644
		return $this->getHtmlComponent()->trigger($event, $params);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getHtmlComponent(...rigger($event, $params) targeting Ajax\common\html\BaseHtml::trigger() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
645
	}
646
647
	public function onActiveRowChange($jsCode) {
648
		$this->getHtmlComponent()->onActiveRowChange($jsCode);
649
		return $this;
650
	}
651
652
	/**
653
	 *
654
	 * @return mixed
655
	 */
656
	public function getDeleteBehavior() {
657
		return $this->_deleteBehavior;
658
	}
659
660
	/**
661
	 *
662
	 * @return mixed
663
	 */
664
	public function getEditBehavior() {
665
		return $this->_editBehavior;
666
	}
667
668
	/**
669
	 *
670
	 * @return mixed
671
	 */
672
	public function getDisplayBehavior() {
673
		return $this->_displayBehavior;
674
	}
675
676
	/**
677
	 *
678
	 * @param mixed $_displayBehavior
679
	 */
680
	public function setDisplayBehavior($_displayBehavior) {
681
		$this->_displayBehavior = $_displayBehavior;
682
	}
683
684
	/**
685
	 *
686
	 * @return mixed
687
	 */
688
	public function getGroupByFields() {
689
		return $this->_instanceViewer->getGroupByFields();
690
	}
691
692
	/**
693
	 *
694
	 * @param mixed $_groupByFields
695
	 */
696
	public function setGroupByFields($_groupByFields) {
697
		$this->_instanceViewer->setGroupByFields($_groupByFields);
698
	}
699
700
	/**
701
	 *
702
	 * @param boolean $_visibleHover
703
	 */
704
	public function setVisibleHover($_visibleHover) {
705
		$this->_visibleHover = $_visibleHover;
706
	}
707
	/**
708
	 * @return \Ajax\semantic\html\collections\menus\HtmlPaginationMenu
709
	 */
710
	public function getPaginationToolbar() {
711
		return $this->_paginationToolbar;
712
	}
713
714
}
715