Passed
Push — master ( efc4e2...b40ff0 )
by Jean-Christophe
18:17
created

CRUDDatas::getSearchFieldNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ubiquity\controllers\crud;
4
5
use Ubiquity\orm\DAO;
6
use Ubiquity\orm\OrmUtils;
7
8
/**
9
 * The base class for displaying datas in CRUD controllers
10
 * Ubiquity\controllers\crud$CRUDDatas
11
 * This class is part of Ubiquity
12
 *
13
 * @author jc
14
 * @version 1.0.0
15
 *
16
 */
17
class CRUDDatas {
18
	
19
	protected $controller;
20
	
21 8
	public function __construct($controller) {
22 8
		$this->controller = $controller;
23
	}
24
25
	/**
26
	 * Returns the table names to display in the left admin menu
27
	 */
28
	public function getTableNames():array {
29
		return DAO::$db->getTablesName ();
30
	}
31
32
	/**
33
	 * Returns the fields to display in the showModel action for $model (DataTable)
34
	 *
35
	 * @param string $model
36
	 * @return array
37
	 */
38 8
	public function getFieldNames(string $model): array {
39 8
		return OrmUtils::getSerializableMembers ( $model );
40
	}
41
42
	/**
43
	 * Returns the fields to update in the edit an new action for $model
44
	 *
45
	 * @param string $model
46
	 * @param object $instance
47
	 * @return array
48
	 */
49 3
	public function getFormFieldNames(string $model, $instance): array {
1 ignored issue
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

49
	public function getFormFieldNames(string $model, /** @scrutinizer ignore-unused */ $instance): array {

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...
50 3
		return OrmUtils::getFormAllFields ( $model );
51
	}
52
53
	/**
54
	 * Returns the fields to use in search queries
55
	 *
56
	 * @param string $model
57
	 * @return array
58
	 */
59 1
	public function getSearchFieldNames(string $model): array {
60 1
		return OrmUtils::getSerializableFields ( $model );
61
	}
62
63
	/**
64
	 * Returns the fields for displaying an instance of $model (DataElement)
65
	 *
66
	 * @param string $model
67
	 * @return array
68
	 */
69 2
	public function getElementFieldNames(string $model): array {
70 2
		return OrmUtils::getMembers ( $model );
71
	}
72
73
	/**
74
	 * Returns a (filtered) list of $fkClass objects to display in an html list
75
	 *
76
	 * @param string $fkClass
77
	 * @param object $instance
78
	 * @param string $member The member associated with a manyToMany relation
79
	 * @return array
80
	 */
81
	public function getManyToManyDatas($fkClass, $instance, $member): array {
82
		return DAO::getAll ( $fkClass, "", false );
83
	}
84
85
	/**
86
	 * Returns a list (filtered) of $fkClass objects to display in an html list
87
	 *
88
	 * @param string $fkClass
89
	 * @param object $instance
90
	 * @param string $member The member associated with a manyToOne relation
91
	 * @return array
92
	 */
93 1
	public function getManyToOneDatas($fkClass, $instance, $member):array {
94 1
		return DAO::getAll ( $fkClass, "", false );
95
	}
96
97
	/**
98
	 * Returns a list (filtered) of $fkClass objects to display in an html list
99
	 *
100
	 * @param string $fkClass
101
	 * @param object $instance
102
	 * @param string $member The member associated with a oneToMany relation
103
	 * @return array
104
	 */
105
	public function getOneToManyDatas($fkClass, $instance, $member):array {
106
		return DAO::getAll ( $fkClass, "", false );
107
	}
108
109
	/**
110
	 *
111
	 * @return boolean
112
	 */
113
	public function getUpdateOneToManyInForm(): bool {
114
		return false;
115
	}
116
117
	/**
118
	 *
119
	 * @return boolean
120
	 */
121
	public function getUpdateManyToManyInForm(): bool {
122
		return true;
123
	}
124
125
	/**
126
	 *
127
	 * @return boolean
128
	 */
129
	public function getUpdateManyToOneInForm(): bool {
130
		return true;
131
	}
132
133
	/**
134
	 * Defines whether the refresh is partial or complete after an instance update
135
	 *
136
	 * @return boolean
137
	 */
138 2
	public function refreshPartialInstance(): bool {
139 2
		return true;
140
	}
141
142
	/**
143
	 * Adds a condition for filtering the instances displayed in dataTable
144
	 * Return 1=1 by default
145
	 *
146
	 * @param string $model
147
	 * @return string
148
	 */
149 8
	public function _getInstancesFilter(string $model): string {
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

149
	public function _getInstancesFilter(/** @scrutinizer ignore-unused */ string $model): string {

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...
150 8
		return "1=1";
151
	}
152
}
153