1
|
|
|
<?php |
2
|
|
|
namespace Ubiquity\controllers\crud; |
3
|
|
|
use Ubiquity\orm\DAO; |
4
|
|
|
use Ubiquity\orm\OrmUtils; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* The base class for displaying datas in CRUD controllers |
8
|
|
|
* @author jc |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
class CRUDDatas { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Returns the table names to display in the left admin menu |
15
|
|
|
*/ |
16
|
|
|
public function getTableNames(){ |
17
|
|
|
return DAO::$db->getTablesName(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Returns the fields to display in the showModel action for $model (DataTable) |
22
|
|
|
* @param string $model |
23
|
|
|
*/ |
24
|
2 |
|
public function getFieldNames($model){ |
25
|
2 |
|
return OrmUtils::getSerializableFields($model); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the fields to update in the edit an new action for $model |
30
|
|
|
* @param string $model |
31
|
|
|
* @param object $instance |
32
|
|
|
*/ |
33
|
2 |
|
public function getFormFieldNames($model,$instance){ |
34
|
2 |
|
return OrmUtils::getFormAllFields($model); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns the fields to use in search queries |
39
|
|
|
* @param string $model |
40
|
|
|
*/ |
41
|
|
|
public function getSearchFieldNames($model){ |
42
|
|
|
return OrmUtils::getSerializableFields($model); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns the fields for displaying an instance of $model (DataElement) |
47
|
|
|
* @param string $model |
48
|
|
|
*/ |
49
|
|
|
public function getElementFieldNames($model){ |
50
|
|
|
return OrmUtils::getMembers($model); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns a (filtered) list of $fkClass objects to display in an html list |
55
|
|
|
* @param string $fkClass |
56
|
|
|
* @param object $instance |
57
|
|
|
* @param string $member The member associated with a manyToMany relation |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function getManyToManyDatas($fkClass,$instance,$member){ |
61
|
|
|
return DAO::getAll($fkClass,"",false); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns a list (filtered) of $fkClass objects to display in an html list |
66
|
|
|
* @param string $fkClass |
67
|
|
|
* @param object $instance |
68
|
|
|
* @param string $member The member associated with a manyToOne relation |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
1 |
|
public function getManyToOneDatas($fkClass,$instance,$member){ |
72
|
1 |
|
return DAO::getAll($fkClass,"",false); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns a list (filtered) of $fkClass objects to display in an html list |
77
|
|
|
* @param string $fkClass |
78
|
|
|
* @param object $instance |
79
|
|
|
* @param string $member The member associated with a oneToMany relation |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getOneToManyDatas($fkClass,$instance,$member){ |
83
|
|
|
return DAO::getAll($fkClass,"",false); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return boolean |
88
|
|
|
*/ |
89
|
|
|
public function getUpdateOneToManyInForm() { |
90
|
|
|
return false; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return boolean |
95
|
|
|
*/ |
96
|
|
|
public function getUpdateManyToManyInForm() { |
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return boolean |
102
|
|
|
*/ |
103
|
|
|
public function getUpdateManyToOneInForm() { |
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Defines whether the refresh is partial or complete after an instance update |
109
|
|
|
* @return boolean |
110
|
|
|
*/ |
111
|
1 |
|
public function refreshPartialInstance(){ |
112
|
1 |
|
return true; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Adds a condition for filtering the instances displayed in dataTable |
117
|
|
|
* Return 1=1 by default |
118
|
|
|
* @param string $model |
119
|
|
|
* @return string |
120
|
|
|
*/ |
121
|
2 |
|
public function _getInstancesFilter($model){ |
122
|
2 |
|
return "1=1"; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|