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 { |
|
|
|
|
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 { |
|
|
|
|
150
|
8 |
|
return "1=1"; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.