1 |
<?php |
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
class DA_Default extends SGL_Manager |
---|
49 |
{ |
---|
50 |
|
---|
51 |
* Constructor - set default resources. |
---|
52 |
* |
---|
53 |
* @return DA_Default |
---|
54 |
*/ |
---|
55 |
function DA_Default() |
---|
56 |
{ |
---|
57 |
parent::SGL_Manager(); |
---|
58 |
} |
---|
59 |
|
---|
60 |
|
---|
61 |
* Returns a singleton DA_Default instance. |
---|
62 |
* |
---|
63 |
* example usage: |
---|
64 |
* $da = & DA_Default::singleton(); |
---|
65 |
* warning: in order to work correctly, the DA |
---|
66 |
* singleton must be instantiated statically and |
---|
67 |
* by reference |
---|
68 |
* |
---|
69 |
* @access public |
---|
70 |
* @static |
---|
71 |
* @return DA_Default reference to DA_Default object |
---|
72 |
*/ |
---|
73 |
function &singleton() |
---|
74 |
{ |
---|
75 |
static $instance; |
---|
76 |
|
---|
77 |
|
---|
78 |
if (!isset($instance)) { |
---|
79 |
$instance = new DA_Default(); |
---|
80 |
} |
---|
81 |
return $instance; |
---|
82 |
} |
---|
83 |
|
---|
84 |
|
---|
85 |
/** |
---|
86 |
* Returns true if module record exists in db. |
---|
87 |
* |
---|
88 |
* @return boolean |
---|
89 |
* @deprecated use SGL::moduleIsEnabled($moduleName) instead |
---|
90 |
*/ |
---|
91 |
function moduleIsRegistered($moduleName) |
---|
92 |
{ |
---|
93 |
$query = " |
---|
94 |
SELECT module_id |
---|
95 |
FROM {$this->conf['table']['module']} |
---|
96 |
WHERE name = '$moduleName'"; |
---|
97 |
|
---|
98 |
$exists = $this->dbh->getOne($query); |
---|
99 |
|
---|
100 |
return ! is_null($exists); |
---|
101 |
} |
---|
102 |
|
---|
103 |
|
---|
104 |
* Returns an array of all modules. |
---|
105 |
* |
---|
106 |
* @param integer $type |
---|
107 |
* @return array |
---|
108 |
*/ |
---|
109 |
function getModuleHash($type = '') |
---|
110 |
{ |
---|
111 |
SGL::logMessage(null, PEAR_LOG_DEBUG); |
---|
112 |
|
---|
113 |
switch ($type) { |
---|
114 |
case SGL_RET_ID_VALUE: |
---|
115 |
$query = " SELECT module_id, title |
---|
116 |
FROM {$this->conf['table']['module']} |
---|
117 |
ORDER BY module_id"; |
---|
118 |
$aMods = $this->dbh->getAssoc($query); |
---|
119 |
break; |
---|
120 |
|
---|
121 |
case SGL_RET_NAME_VALUE: |
---|
122 |
default: |
---|
123 |
$query = " SELECT name, title |
---|
124 |
FROM {$this->conf['table']['module']} |
---|
125 |
ORDER BY name"; |
---|
126 |
$aModules = $this->dbh->getAll($query); |
---|
127 |
foreach ($aModules as $k => $oVal) { |
---|
128 |
if ($oVal->name == 'documentor') { |
---|
129 |
continue; |
---|
130 |
} |
---|
131 |
$aMods[$oVal->name] = $oVal->title; |
---|
132 |
} |
---|
133 |
break; |
---|
134 |
} |
---|
135 |
return $aMods; |
---|
136 |
} |
---|
137 |
|
---|
138 |
function getAllModules() |
---|
139 |
{ |
---|
140 |
$query = " |
---|
141 |
SELECT module_id, is_configurable, name, title, description, admin_uri, icon |
---|
142 |
FROM {$this->conf['table']['module']} |
---|
143 |
ORDER BY module_id"; |
---|
144 |
$aModules = $this->dbh->getAll($query); |
---|
145 |
return $aModules; |
---|
146 |
} |
---|
147 |
|
---|
148 |
|
---|
149 |
* Returns module id by perm id. |
---|
150 |
* |
---|
151 |
* @param integer $permId |
---|
152 |
* @return integer |
---|
153 |
*/ |
---|
154 |
function getModuleIdByPermId($permId = null) |
---|
155 |
{ |
---|
156 |
SGL::logMessage(null, PEAR_LOG_DEBUG); |
---|
157 |
|
---|
158 |
$permId = ($permId === null) ? 0 : $permId; |
---|
159 |
$query = " |
---|
160 |
SELECT module_id |
---|
161 |
FROM {$this->conf['table']['permission']} |
---|
162 |
WHERE permission_id = $permId |
---|
163 |
"; |
---|
164 |
$moduleId = $this->dbh->getOne($query); |
---|
165 |
return $moduleId; |
---|
166 |
} |
---|
167 |
|
---|
168 |
|
---|
169 |
* Give the module ID, delete relevant perms. |
---|
170 |
* |
---|
171 |
* @param integer $moduleId |
---|
172 |
* @return boolean |
---|
173 |
* |
---|
174 |
* @todo move to DA_User |
---|
175 |
*/ |
---|
176 |
function deletePermsByModuleId($moduleId) |
---|
177 |
{ |
---|
178 |
$query = " |
---|
179 |
DELETE |
---|
180 |
FROM {$this->conf['table']['permission']} |
---|
181 |
WHERE module_id = " . $moduleId; |
---|
182 |
$ok = $this->dbh->query($query); |
---|
183 |
return $ok; |
---|
184 |
} |
---|
185 |
|
---|
186 |
function getPermNamesByModuleId($moduleId) |
---|
187 |
{ |
---|
188 |
SGL::logMessage(null, PEAR_LOG_DEBUG); |
---|
189 |
|
---|
190 |
$query = " |
---|
191 |
SELECT name |
---|
192 |
FROM {$this->conf['table']['permission']} |
---|
193 |
WHERE module_id = $moduleId |
---|
194 |
"; |
---|
195 |
$aPermNames = $this->dbh->getCol($query); |
---|
196 |
return $aPermNames; |
---|
197 |
} |
---|
198 |
|
---|
199 |
function getPackagesByChannel($channel='phpkitchen') |
---|
200 |
{ |
---|
201 |
require_once 'PEAR/Registry.php'; |
---|
202 |
$registry = new PEAR_Registry('/usr/local/lib/php'); |
---|
203 |
|
---|
204 |
$aSglModules = $registry->_listPackages($channel); |
---|
205 |
return $aSglModules; |
---|
206 |
} |
---|
207 |
|
---|
208 |
|
---|
209 |
* Returns a DataObjects Module object. |
---|
210 |
* |
---|
211 |
* @param integer $id optional module id |
---|
212 |
* @return object A DataObjects module object |
---|
213 |
*/ |
---|
214 |
function getModuleById($id = null) |
---|
215 |
{ |
---|
216 |
require_once 'DB/DataObject.php'; |
---|
217 |
$oModule = DB_DataObject::factory($this->conf['table']['module']); |
---|
218 |
if (!is_null($id)) { |
---|
219 |
$oModule->get($id); |
---|
220 |
} |
---|
221 |
return $oModule; |
---|
222 |
} |
---|
223 |
|
---|
224 |
function getModuleByName($name = null) |
---|
225 |
{ |
---|
226 |
require_once 'DB/DataObject.php'; |
---|
227 |
$oModule = DB_DataObject::factory($this->conf['table']['module']); |
---|
228 |
if (!is_null($name)) { |
---|
229 |
$oModule->get('name', $name); |
---|
230 |
} |
---|
231 |
return $oModule; |
---|
232 |
} |
---|
233 |
|
---|
234 |
function addModule($oModule) |
---|
235 |
{ |
---|
236 |
SGL_DB::setConnection(); |
---|
237 |
if (!isset($oModule->module_id)) { |
---|
238 |
$oModule->module_id = $this->dbh->nextId($this->conf['table']['module']); |
---|
239 |
} |
---|
240 |
$oModule->is_configurable = 1; |
---|
241 |
$oModule->title = ucfirst($oModule->name); |
---|
242 |
$ok = $oModule->insert(); |
---|
243 |
return $ok; |
---|
244 |
} |
---|
245 |
|
---|
246 |
|
---|
247 |
* Given the perm name, return the perm ID. |
---|
248 |
* |
---|
249 |
* @param string $permName |
---|
250 |
* @return integer |
---|
251 |
* |
---|
252 |
* @todo move to DA_User |
---|
253 |
*/ |
---|
254 |
function getPermissionIdByPermName($permName) |
---|
255 |
{ |
---|
256 |
$query = " |
---|
257 |
SELECT permission_id |
---|
258 |
FROM {$this->conf['table']['permission']} |
---|
259 |
WHERE name = '$permName' |
---|
260 |
"; |
---|
261 |
$permId = $this->dbh->getOne($query); |
---|
262 |
return $permId; |
---|
263 |
} |
---|
264 |
|
---|
265 |
|
---|
266 |
* Given the perm ID, delete the relevant record from role_permission. |
---|
267 |
* |
---|
268 |
* @param integer $permId |
---|
269 |
* @return mixed |
---|
270 |
* |
---|
271 |
* @todo move to DA_User |
---|
272 |
*/ |
---|
273 |
function deleteRolePermissionByPermId($permId) |
---|
274 |
{ |
---|
275 |
$query = " |
---|
276 |
DELETE FROM {$this->conf['table']['role_permission']} |
---|
277 |
WHERE permission_id = $permId |
---|
278 |
"; |
---|
279 |
return $this->dbh->query($query); |
---|
280 |
} |
---|
281 |
} |
---|