Test Failed
Push — master ( 827664...293942 )
by Jean-Christophe
19:02
created

ModelViewer::oneToManyFormField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 12
rs 9.9
cc 1
nc 1
nop 4
1
<?php
2
3
namespace Ubiquity\controllers\crud\viewers;
4
5
use Ajax\semantic\html\elements\HtmlButton;
6
use Ajax\semantic\html\elements\HtmlHeader;
7
use Ajax\semantic\html\elements\HtmlLabel;
8
use Ajax\semantic\widgets\dataform\DataForm;
9
use Ajax\semantic\widgets\datatable\DataTable;
10
use Ajax\semantic\widgets\datatable\PositionInTable;
11
use Ajax\service\JArray;
12
use Ubiquity\controllers\crud\CRUDHelper;
13
use Ubiquity\controllers\crud\EditMemberParams;
14
use Ubiquity\controllers\crud\interfaces\HasModelViewerInterface;
15
use Ubiquity\controllers\crud\viewers\traits\FormModelViewerTrait;
16
use Ubiquity\orm\DAO;
17
use Ubiquity\orm\OrmUtils;
18
use Ubiquity\orm\parser\Reflexion;
19
use Ubiquity\utils\base\UString;
20
21
/**
22
 * Associated with a CRUDController class
23
 * Responsible of the display
24
 *
25
 * @author jc
26
 *
27
 */
28
class ModelViewer {
29
	use FormModelViewerTrait;
1 ignored issue
show
Bug introduced by
The trait Ubiquity\controllers\cru...ts\FormModelViewerTrait requires the property $_new which is not provided by Ubiquity\controllers\crud\viewers\ModelViewer.
Loading history...
30
	/**
31
	 *
32
	 * @var \Ajax\JsUtils
33
	 */
34
	private $jquery;
35
36
	/**
37
	 *
38
	 * @var HasModelViewerInterface
39
	 */
40
	protected $controller;
41
42
	public function __construct(HasModelViewerInterface $controller) {
43
		$this->jquery = $controller->jquery;
44
		$this->controller = $controller;
45
	}
46
47
	/**
48
	 * Returns a DataElement object for displaying the instance
49
	 * Used in the display method of the CrudController
50
	 * in display route
51
	 *
52
	 * @param object $instance
53
	 * @param string $model The model class name (long name)
54
	 * @param boolean $modal
55
	 * @return \Ajax\semantic\widgets\dataelement\DataElement
56
	 */
57
	public function getModelDataElement($instance, $model, $modal) {
1 ignored issue
show
Unused Code introduced by
The parameter $modal is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

57
	public function getModelDataElement($instance, $model, /** @scrutinizer ignore-unused */ $modal) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
		$semantic = $this->jquery->semantic ();
59
		$fields = $this->controller->_getAdminData ()->getElementFieldNames ( $model );
60
61
		$dataElement = $semantic->dataElement ( "de", $instance );
62
		$pk = OrmUtils::getFirstKeyValue ( $instance );
63
		$dataElement->getInstanceViewer ()->setIdentifierFunction ( function () use ($pk) {
64
			return $pk;
65
		} );
66
		$dataElement->setFields ( $fields );
67
		$dataElement->setCaptions ( $this->getElementCaptions ( $fields, $model, $instance ) );
68
69
		$fkInstances = CRUDHelper::getFKIntances ( $instance, $model );
70
		foreach ( $fkInstances as $member => $fkInstanceArray ) {
71
			if (array_search ( $member, $fields ) !== false) {
72
				$dataElement->setValueFunction ( $member, function () use ($fkInstanceArray, $member) {
73
					return $this->getFkMemberElement ( $member, $fkInstanceArray ["objectFK"], $fkInstanceArray ["fkClass"], $fkInstanceArray ["fkTable"] );
74
				} );
75
			}
76
		}
77
		$this->addEditMemberFonctionality ( "dataElement" );
78
		return $dataElement;
79
	}
80
81
	/**
82
	 * Returns the captions for DataElement fields
83
	 * in display route
84
	 *
85
	 * @param array $captions
86
	 * @param string $className
87
	 */
88
	public function getElementCaptions($captions, $className, $instance) {
2 ignored issues
show
Unused Code introduced by
The parameter $instance is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

88
	public function getElementCaptions($captions, $className, /** @scrutinizer ignore-unused */ $instance) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

88
	public function getElementCaptions($captions, /** @scrutinizer ignore-unused */ $className, $instance) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
		return array_map ( "ucfirst", $captions );
90
	}
91
92
	/**
93
	 * Returns the dataTable responsible for displaying instances of the model
94
	 *
95
	 * @param array $instances objects to display
96
	 * @param string $model model class name (long name)
97
	 * @return DataTable
98
	 */
99
	public function getModelDataTable($instances, $model, $totalCount, $page = 1) {
100
		$adminRoute = $this->controller->_getBaseRoute ();
101
		$files = $this->controller->_getFiles ();
102
		$dataTable = $this->getDataTableInstance ( $instances, $model, $totalCount, $page );
103
		$attributes = $this->controller->_getAdminData ()->getFieldNames ( $model );
104
		$this->setDataTableAttributes ( $dataTable, $attributes, $model, $instances );
105
		$dataTable->setCaptions ( $this->getCaptions ( $attributes, $model ) );
106
107
		$dataTable->addClass ( "small very compact" );
108
		$lbl = new HtmlLabel ( "search-query", "<span id='search-query-content'></span>" );
109
		$icon = $lbl->addIcon ( "delete", false );
110
		$lbl->wrap ( "<span>", "</span>" );
111
		$lbl->setProperty ( "style", "display: none;" );
112
		$icon->getOnClick ( $adminRoute . $files->getRouteRefreshTable (), "#lv", [ "jqueryDone" => "replaceWith","hasLoader" => "internal" ] );
113
114
		$dataTable->addItemInToolbar ( $lbl );
115
		$dataTable->addSearchInToolbar ();
116
		$dataTable->setToolbarPosition ( PositionInTable::FOOTER );
117
		$dataTable->getToolbar ()->setSecondary ();
118
		return $dataTable;
119
	}
120
121
	public function setDataTableAttributes(DataTable $dataTable, $attributes, $model, $instances, $selector = null) {
122
		$modal = ($this->isModal ( $instances, $model ) ? "modal" : "no");
123
124
		$adminRoute = $this->controller->_getBaseRoute ();
125
		$files = $this->controller->_getFiles ();
126
		$dataTable->setButtons ( $this->getDataTableRowButtons () );
127
		$dataTable->setFields ( $attributes );
128
		if (array_search ( "password", $attributes ) !== false) {
129
			$dataTable->setValueFunction ( "password", function ($v) {
130
				return UString::mask ( $v );
131
			} );
132
		}
133
		$dataTable->setIdentifierFunction ( CRUDHelper::getIdentifierFunction ( $model ) );
134
135
		if (! isset ( $selector )) {
136
			if ($this->showDetailsOnDataTableClick ()) {
137
				$dataTable->getOnRow ( "click", $adminRoute . $files->getRouteDetails (), "#table-details", [ "selector" => $selector,"attr" => "data-ajax","hasLoader" => false,"jsCondition" => "!event.detail || event.detail==1","jsCallback" => "return false;" ] );
138
				$dataTable->setActiveRowSelector ( "active" );
139
			}
140
141
			$dataTable->setUrls ( [ "refresh" => $adminRoute . $files->getRouteRefresh (),"delete" => $adminRoute . $files->getRouteDelete (),"edit" => $adminRoute . $files->getRouteEdit () . "/" . $modal,"display" => $adminRoute . $files->getRouteDisplay () . "/" . $modal ] );
142
			$dataTable->setTargetSelector ( [ "delete" => "#table-messages","edit" => "#frm-add-update","display" => "#table-details" ] );
143
			$this->addEditMemberFonctionality ( "dataTable" );
144
		}
145
		$this->addAllButtons ( $dataTable, $attributes );
146
	}
147
148
	public function addEditMemberFonctionality($part) {
149
		if (($editMemberParams = $this->getEditMemberParams ()) !== false) {
1 ignored issue
show
introduced by
The condition $editMemberParams = $thi...emberParams() !== false is always true.
Loading history...
150
			if (isset ( $editMemberParams [$part] )) {
151
				$params = $editMemberParams [$part];
152
				$params->compile ( $this->controller->_getBaseRoute (), $this->jquery, $part );
153
			}
154
		}
155
	}
156
157
	/**
158
	 *
159
	 * @param string $model The model class name (long name)
160
	 * @param number $totalCount The total count of objects
161
	 * @return void|number default : 6
162
	 */
163
	public function recordsPerPage($model, $totalCount = 0) {
1 ignored issue
show
Unused Code introduced by
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

163
	public function recordsPerPage(/** @scrutinizer ignore-unused */ $model, $totalCount = 0) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
164
		if ($totalCount > 6)
165
			return 6;
166
		return;
167
	}
168
169
	/**
170
	 * Returns the fields on which a grouping is performed
171
	 */
172
	public function getGroupByFields() {
173
		return;
174
	}
175
176
	/**
177
	 * Returns the dataTable instance for dispaying a list of object
178
	 *
179
	 * @param array $instances
180
	 * @param string $model
181
	 * @param number $totalCount
182
	 * @param number $page
183
	 * @return DataTable
184
	 */
185
	protected function getDataTableInstance($instances, $model, $totalCount, $page = 1): DataTable {
186
		$semantic = $this->jquery->semantic ();
187
		$recordsPerPage = $this->recordsPerPage ( $model, $totalCount );
188
		if (is_numeric ( $recordsPerPage )) {
1 ignored issue
show
introduced by
The condition is_numeric($recordsPerPage) is always true.
Loading history...
189
			$grpByFields = $this->getGroupByFields ();
1 ignored issue
show
Bug introduced by
Are you sure the assignment to $grpByFields is correct as $this->getGroupByFields() targeting Ubiquity\controllers\cru...wer::getGroupByFields() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
190
			if (is_array ( $grpByFields )) {
191
				$dataTable = $semantic->dataTable ( "lv", $model, $instances );
192
				$dataTable->setGroupByFields ( $grpByFields );
193
			} else {
194
				$dataTable = $semantic->jsonDataTable ( "lv", $model, $instances );
195
			}
196
			$dataTable->paginate ( $page, $totalCount, $recordsPerPage, 5 );
197
			$dataTable->onActiveRowChange ( '$("#table-details").html("");' );
198
			$dataTable->onSearchTerminate ( '$("#search-query-content").html(data);$("#search-query").show();$("#table-details").html("");' );
199
		} else {
200
			$dataTable = $semantic->dataTable ( "lv", $model, $instances );
201
		}
202
		return $dataTable;
203
	}
204
205
	/**
206
	 * Returns an array of buttons ["display","edit","delete"] to display for each row in dataTable
207
	 *
208
	 * @return string[]
209
	 */
210
	protected function getDataTableRowButtons() {
211
		return [ "edit","delete" ];
212
	}
213
214
	public function addAllButtons(DataTable $dataTable, $attributes) {
1 ignored issue
show
Unused Code introduced by
The parameter $attributes is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

214
	public function addAllButtons(DataTable $dataTable, /** @scrutinizer ignore-unused */ $attributes) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
215
		$dataTable->onPreCompile ( function () use (&$dataTable) {
216
			$dataTable->getHtmlComponent ()->colRightFromRight ( 0 );
217
		} );
218
		$dataTable->addAllButtons ( false, [ "ajaxTransition" => "random" ], function ($bt) {
219
			$bt->addClass ( "circular" );
220
			$this->onDataTableRowButton ( $bt );
221
		}, function ($bt) {
222
			$bt->addClass ( "circular" );
223
			$this->onDataTableRowButton ( $bt );
224
		}, function ($bt) {
225
			$bt->addClass ( "circular" );
226
			$this->onDataTableRowButton ( $bt );
227
		} );
228
		$dataTable->setDisplayBehavior ( [ "jsCallback" => '$("#dataTable").hide();',"ajaxTransition" => "random" ] );
229
	}
230
231
	/**
232
	 * To override for modifying the dataTable row buttons
233
	 *
234
	 * @param HtmlButton $bt
235
	 */
236
	public function onDataTableRowButton(HtmlButton $bt) {
1 ignored issue
show
Unused Code introduced by
The parameter $bt is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

236
	public function onDataTableRowButton(/** @scrutinizer ignore-unused */ HtmlButton $bt) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
237
	}
238
239
	/**
240
	 * To override for modifying the showConfMessage dialog buttons
241
	 *
242
	 * @param HtmlButton $confirmBtn The confirmation button
243
	 * @param HtmlButton $cancelBtn The cancellation button
244
	 */
245
	public function onConfirmButtons(HtmlButton $confirmBtn, HtmlButton $cancelBtn) {
2 ignored issues
show
Unused Code introduced by
The parameter $cancelBtn is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

245
	public function onConfirmButtons(HtmlButton $confirmBtn, /** @scrutinizer ignore-unused */ HtmlButton $cancelBtn) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $confirmBtn is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

245
	public function onConfirmButtons(/** @scrutinizer ignore-unused */ HtmlButton $confirmBtn, HtmlButton $cancelBtn) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
246
	}
247
248
	/**
249
	 * Returns the captions for list fields in showTable action
250
	 *
251
	 * @param array $captions
252
	 * @param string $className
253
	 */
254
	public function getCaptions($captions, $className) {
1 ignored issue
show
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

254
	public function getCaptions($captions, /** @scrutinizer ignore-unused */ $className) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
255
		return \array_map ( "ucfirst", $captions );
256
	}
257
258
	/**
259
	 * Returns the header for a single foreign object (element is an instance, issue from ManyToOne), (from DataTable)
260
	 *
261
	 * @param string $member
262
	 * @param string $className
263
	 * @param object $object
264
	 * @return HtmlHeader
265
	 */
266
	public function getFkHeaderElementDetails($member, $className, $object) {
2 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

266
	public function getFkHeaderElementDetails($member, $className, /** @scrutinizer ignore-unused */ $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

266
	public function getFkHeaderElementDetails($member, /** @scrutinizer ignore-unused */ $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
267
		return new HtmlHeader ( "", 4, $member, "content" );
268
	}
269
270
	/**
271
	 * Returns the header for a list of foreign objects (issue from oneToMany or ManyToMany), (from DataTable)
272
	 *
273
	 * @param string $member
274
	 * @param string $className
275
	 * @param array $list
276
	 * @return HtmlHeader
277
	 */
278
	public function getFkHeaderListDetails($member, $className, $list) {
1 ignored issue
show
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

278
	public function getFkHeaderListDetails($member, /** @scrutinizer ignore-unused */ $className, $list) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
279
		return new HtmlHeader ( "", 4, $member . " (" . \count ( $list ) . ")", "content" );
280
	}
281
282
	/**
283
	 * Returns a component for displaying a single foreign object (manyToOne relation), (from DataTable)
284
	 *
285
	 * @param string $member
286
	 * @param string $className
287
	 * @param object $object
288
	 * @return \Ajax\common\html\BaseHtml
289
	 */
290
	public function getFkElementDetails($member, $className, $object) {
291
		return $this->jquery->semantic ()->htmlLabel ( "element-" . $className . "." . $member, $object . "" );
292
	}
293
294
	/**
295
	 * Returns a list component for displaying a collection of foreign objects (*ToMany relations), (from DataTable)
296
	 *
297
	 * @param string $member
298
	 * @param string $className
299
	 * @param array|\Traversable $list
300
	 * @return \Ajax\common\html\HtmlCollection
301
	 */
302
	public function getFkListDetails($member, $className, $list) {
1 ignored issue
show
Unused Code introduced by
The parameter $list is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

302
	public function getFkListDetails($member, $className, /** @scrutinizer ignore-unused */ $list) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
303
		$element = $this->jquery->semantic ()->htmlList ( "list-" . $className . "." . $member );
304
		$element->setMaxVisible ( 15 );
305
306
		return $element->addClass ( "animated divided celled" );
307
	}
308
309
	/**
310
	 * Returns a component for displaying a foreign object (from DataTable)
311
	 *
312
	 * @param string $memberFK
313
	 * @param mixed $objectFK
314
	 * @param string $fkClass
315
	 * @param string $fkTable
316
	 * @return string|NULL
317
	 */
318
	public function getFkMemberElementDetails($memberFK, $objectFK, $fkClass, $fkTable) {
1 ignored issue
show
Unused Code introduced by
The parameter $fkTable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

318
	public function getFkMemberElementDetails($memberFK, $objectFK, $fkClass, /** @scrutinizer ignore-unused */ $fkTable) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
319
		$_fkClass = str_replace ( "\\", ".", $fkClass );
320
		$header = new HtmlHeader ( "", 4, $memberFK, "content" );
321
		if (is_array ( $objectFK ) || $objectFK instanceof \Traversable) {
322
			$header = $this->getFkHeaderListDetails ( $memberFK, $fkClass, $objectFK );
323
			$element = $this->getFkListDetails ( $memberFK, $fkClass, $objectFK );
324
			foreach ( $objectFK as $oItem ) {
325
				if (method_exists ( $oItem, "__toString" )) {
326
					$id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $oItem );
327
					$item = $element->addItem ( $oItem . "" );
328
					$item->setProperty ( "data-ajax", $_fkClass . "||" . $id );
329
					$item->addClass ( "showTable" );
330
					$this->onDisplayFkElementListDetails ( $item, $memberFK, $fkClass, $oItem );
331
				}
332
			}
333
		} else {
334
			if (method_exists ( $objectFK, "__toString" )) {
335
				$header = $this->getFkHeaderElementDetails ( $memberFK, $fkClass, $objectFK );
336
				$id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $objectFK );
337
				$element = $this->getFkElementDetails ( $memberFK, $fkClass, $objectFK );
338
				$element->setProperty ( "data-ajax", $_fkClass . "||" . $id )->addClass ( "showTable" );
339
			}
340
		}
341
		if (isset ( $element )) {
342
			return [ $header,$element ];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($header, $element) returns the type array<integer,Ajax\seman...ments\HtmlHeader|mixed> which is incompatible with the documented return type null|string.
Loading history...
343
		}
344
		return null;
345
	}
346
347
	/**
348
	 * To modify for displaying an element in a list component of foreign objects (from DataTable)
349
	 *
350
	 * @param \Ajax\common\html\HtmlDoubleElement $element
351
	 * @param string $member
352
	 * @param string $className
353
	 * @param object $object
354
	 */
355
	public function onDisplayFkElementListDetails($element, $member, $className, $object) {
4 ignored issues
show
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

355
	public function onDisplayFkElementListDetails($element, $member, /** @scrutinizer ignore-unused */ $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

355
	public function onDisplayFkElementListDetails($element, $member, $className, /** @scrutinizer ignore-unused */ $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $element is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

355
	public function onDisplayFkElementListDetails(/** @scrutinizer ignore-unused */ $element, $member, $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

355
	public function onDisplayFkElementListDetails($element, /** @scrutinizer ignore-unused */ $member, $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
356
	}
357
358
	/**
359
	 * Returns a component for displaying a foreign object (from DataElement)
360
	 *
361
	 * @param string $memberFK
362
	 * @param mixed $objectFK
363
	 * @param string $fkClass
364
	 * @param string $fkTable
365
	 * @return string|NULL
366
	 */
367
	public function getFkMemberElement($memberFK, $objectFK, $fkClass, $fkTable) {
1 ignored issue
show
Unused Code introduced by
The parameter $fkTable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

367
	public function getFkMemberElement($memberFK, $objectFK, $fkClass, /** @scrutinizer ignore-unused */ $fkTable) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
368
		$element = "";
369
		$_fkClass = str_replace ( "\\", ".", $fkClass );
370
		if (is_array ( $objectFK ) || $objectFK instanceof \Traversable) {
371
			$element = $this->getFkList ( $memberFK, $objectFK );
372
			foreach ( $objectFK as $oItem ) {
373
				if (method_exists ( $oItem, "__toString" )) {
374
					$id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $oItem );
375
					$item = $element->addItem ( $oItem . "" );
376
					$item->setProperty ( "data-ajax", $_fkClass . "||" . $id );
377
					$item->addClass ( "showTable" );
378
					$this->displayFkElementList ( $item, $memberFK, $fkClass, $oItem );
379
				}
380
			}
381
		} else {
382
			if (method_exists ( $objectFK, "__toString" )) {
383
				$id = (CRUDHelper::getIdentifierFunction ( $fkClass )) ( 0, $objectFK );
384
				$element = $this->getFkElement ( $memberFK, $fkClass, $objectFK );
385
				$element->setProperty ( "data-ajax", $_fkClass . "||" . $id )->addClass ( "showTable" );
386
			}
387
		}
388
		return $element;
389
	}
390
391
	/**
392
	 * Returns a list component for displaying a collection of foreign objects (*ToMany relations), (from DataElement)
393
	 *
394
	 * @param string $member
395
	 * @param string $className
396
	 * @param array|\Traversable $list
397
	 * @return \Ajax\common\html\HtmlCollection
398
	 */
399
	public function getFkList($member, $list) {
1 ignored issue
show
Unused Code introduced by
The parameter $list is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

399
	public function getFkList($member, /** @scrutinizer ignore-unused */ $list) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
400
		$element = $this->jquery->semantic ()->htmlList ( "list-" . $member );
401
		$element->setMaxVisible ( 10 );
402
		return $element->addClass ( "animated" );
403
	}
404
405
	/**
406
	 * To modify for displaying an element in a list component of foreign objects, (from DataElement)
407
	 *
408
	 * @param \Ajax\common\html\HtmlDoubleElement $element
409
	 * @param string $member
410
	 * @param string $className
411
	 * @param object $object
412
	 */
413
	public function displayFkElementList($element, $member, $className, $object) {
4 ignored issues
show
Unused Code introduced by
The parameter $element is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

413
	public function displayFkElementList(/** @scrutinizer ignore-unused */ $element, $member, $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $object is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

413
	public function displayFkElementList($element, $member, $className, /** @scrutinizer ignore-unused */ $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $member is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

413
	public function displayFkElementList($element, /** @scrutinizer ignore-unused */ $member, $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

413
	public function displayFkElementList($element, $member, /** @scrutinizer ignore-unused */ $className, $object) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
414
	}
415
416
	/**
417
	 * Returns a component for displaying a single foreign object (manyToOne relation), (from DataElement)
418
	 *
419
	 * @param string $member
420
	 * @param string $className
421
	 * @param object $object
422
	 * @return \Ajax\common\html\BaseHtml
423
	 */
424
	public function getFkElement($member, $className, $object) {
425
		return $this->jquery->semantic ()->htmlLabel ( "element-" . $className . "." . $member, $object . "" );
1 ignored issue
show
Bug introduced by
Are you sure $object of type object can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

425
		return $this->jquery->semantic ()->htmlLabel ( "element-" . $className . "." . $member, /** @scrutinizer ignore-type */ $object . "" );
Loading history...
426
	}
427
428
	/**
429
	 * To override to make sure that the detail of a clicked object is displayed or not
430
	 *
431
	 * @return boolean Return true if you want to see details
432
	 */
433
	public function showDetailsOnDataTableClick() {
434
		return true;
435
	}
436
}
437
438