ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilDBUpdateNewObjectType Class Reference

Helper class to create new object types (object_data, RBAC) More...

+ Collaboration diagram for ilDBUpdateNewObjectType:

Static Public Member Functions

static addNewType ($a_type_id, $a_type_title)
 Add new type to object data. More...
 
static addRBACOperations ($a_type_id, array $a_operations)
 Add RBAC operations for type. More...
 
static addRBACOperation ($a_type_id, $a_ops_id)
 Add RBAC operation. More...
 
static isRBACOperation ($a_type_id, $a_ops_id)
 Check if rbac operation exists. More...
 
static deleteRBACOperation ($a_type, $a_ops_id)
 Delete rbac operation. More...
 
static deleteRBACTemplateOperation ($a_type, $a_ops_id)
 Delete operation for type in templates. More...
 
static getCustomRBACOperationId ($a_operation)
 Get id of RBAC operation. More...
 
static addCustomRBACOperation ($a_id, $a_title, $a_class, $a_pos)
 Add custom RBAC operation. More...
 
static getObjectTypeId ($a_type)
 Get id for object data type entry. More...
 
static addRBACCreate ($a_id, $a_title, array $a_parent_types)
 Add create RBAC operations for parent object types. More...
 
static updateOperationOrder ($a_operation, $a_pos)
 Change order of operations. More...
 
static addAdminNode ($a_obj_type, $a_title)
 Create new admin object node. More...
 
static cloneOperation ($a_obj_type, $a_source_op_id, $a_target_op_id)
 Clone RBAC-settings between operations. More...
 
static varchar2text ($a_table_name, $a_column_name)
 Migrate varchar column to text/clob. More...
 
static addRBACTemplate ($a_obj_type, $a_id, $a_description, $a_op_ids)
 Add new RBAC template. More...
 

Data Fields

const RBAC_OP_EDIT_PERMISSIONS = 1
 
const RBAC_OP_VISIBLE = 2
 
const RBAC_OP_READ = 3
 
const RBAC_OP_WRITE = 4
 
const RBAC_OP_DELETE = 6
 
const RBAC_OP_COPY = 99
 

Static Protected Member Functions

static isValidRBACOperation ($a_ops_id)
 Check if given RBAC operation id is valid. More...
 

Detailed Description

Helper class to create new object types (object_data, RBAC)

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Id
class.ilObjFolderGUI.php 25134 2010-08-13 14:22:11Z smeyer

Definition at line 13 of file class.ilDBUpdateNewObjectType.php.

Member Function Documentation

◆ addAdminNode()

static ilDBUpdateNewObjectType::addAdminNode (   $a_obj_type,
  $a_title 
)
static

Create new admin object node.

Parameters
string$a_id
string$a_title

Definition at line 323 of file class.ilDBUpdateNewObjectType.php.

324 {
325 global $ilDB, $tree;
326
327 if(self::getObjectTypeId($a_obj_type))
328 {
329 return;
330 }
331
332 $obj_type_id = self::addNewType($a_obj_type, $a_title);
333
334 $obj_id = $ilDB->nextId('object_data');
335 $ilDB->manipulate("INSERT INTO object_data ".
336 "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
337 $ilDB->quote($obj_id, "integer").",".
338 $ilDB->quote($a_obj_type, "text").",".
339 $ilDB->quote($a_title, "text").",".
340 $ilDB->quote($a_title, "text").",".
341 $ilDB->quote(-1, "integer").",".
342 $ilDB->now().",".
343 $ilDB->now().
344 ")");
345
346 $ref_id = $ilDB->nextId('object_reference');
347 $ilDB->manipulate("INSERT INTO object_reference ".
348 "(obj_id, ref_id) VALUES (".
349 $ilDB->quote($obj_id, "integer").",".
350 $ilDB->quote($ref_id, "integer").
351 ")");
352
353 // put in tree
354 $tree = new ilTree(ROOT_FOLDER_ID);
355 $tree->insertNode($ref_id, SYSTEM_FOLDER_ID);
356
357 $rbac_ops = array(
358 self::RBAC_OP_EDIT_PERMISSIONS,
359 self::RBAC_OP_VISIBLE,
360 self::RBAC_OP_READ,
361 self::RBAC_OP_WRITE
362 );
363 self::addRBACOperations($obj_type_id, $rbac_ops);
364 }
static addRBACOperations($a_type_id, array $a_operations)
Add RBAC operations for type.
static addNewType($a_type_id, $a_type_title)
Add new type to object data.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: sahs_server.php:39
global $ilDB

References $ilDB, $ref_id, addNewType(), and addRBACOperations().

+ Here is the call graph for this function:

◆ addCustomRBACOperation()

static ilDBUpdateNewObjectType::addCustomRBACOperation (   $a_id,
  $a_title,
  $a_class,
  $a_pos 
)
static

Add custom RBAC operation.

Parameters
string$a_id
string$a_title
string$a_class
string$a_pos
Returns
int ops_id

Definition at line 228 of file class.ilDBUpdateNewObjectType.php.

229 {
230 global $ilDB;
231
232 // check if it already exists
233 $ops_id = self::getCustomRBACOperationId($a_id);
234 if($ops_id)
235 {
236 return $ops_id;
237 }
238
239 if(!in_array($a_class, array('create', 'object', 'general')))
240 {
241 return;
242 }
243 if($a_class == 'create')
244 {
245 $a_pos = 9999;
246 }
247
248 $ops_id = $ilDB->nextId('rbac_operations');
249
250 $fields = array(
251 'ops_id' => array('integer', $ops_id),
252 'operation' => array('text', $a_id),
253 'description' => array('text', $a_title),
254 'class' => array('text', $a_class),
255 'op_order' => array('integer', $a_pos),
256 );
257 $ilDB->insert('rbac_operations', $fields);
258
259 return $ops_id;
260 }
static getCustomRBACOperationId($a_operation)
Get id of RBAC operation.

References $ilDB, and getCustomRBACOperationId().

Referenced by addRBACCreate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addNewType()

static ilDBUpdateNewObjectType::addNewType (   $a_type_id,
  $a_type_title 
)
static

Add new type to object data.

Parameters
string$a_type_id
string$a_type_title
Returns
int insert id

Definition at line 29 of file class.ilDBUpdateNewObjectType.php.

30 {
31 global $ilDB;
32
33 // check if it already exists
34 $type_id = self::getObjectTypeId($a_type_id);
35 if($type_id)
36 {
37 return $type_id;
38 }
39
40 $type_id = $ilDB->nextId('object_data');
41
42 $fields = array(
43 'obj_id' => array('integer', $type_id),
44 'type' => array('text', 'typ'),
45 'title' => array('text', $a_type_id),
46 'description' => array('text', $a_type_title),
47 'owner' => array('integer', -1),
48 'create_date' => array('timestamp', ilUtil::now()),
49 'last_update' => array('timestamp', ilUtil::now())
50 );
51 $ilDB->insert('object_data', $fields);
52
53 return $type_id;
54 }
static getObjectTypeId($a_type)
Get id for object data type entry.
static now()
Return current timestamp in Y-m-d H:i:s format.

References $ilDB, getObjectTypeId(), and ilUtil\now().

Referenced by addAdminNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addRBACCreate()

static ilDBUpdateNewObjectType::addRBACCreate (   $a_id,
  $a_title,
array  $a_parent_types 
)
static

Add create RBAC operations for parent object types.

Parameters
string$a_id
string$a_title
array$a_parent_types

Definition at line 287 of file class.ilDBUpdateNewObjectType.php.

288 {
289 $ops_id = self::addCustomRBACOperation($a_id, $a_title, 'create', 9999);
290
291 foreach($a_parent_types as $type)
292 {
293 $type_id = self::getObjectTypeId($type);
294 if($type_id)
295 {
296 self::addRBACOperation($type_id, $ops_id);
297 }
298 }
299 }
static addCustomRBACOperation($a_id, $a_title, $a_class, $a_pos)
Add custom RBAC operation.
static addRBACOperation($a_type_id, $a_ops_id)
Add RBAC operation.

References addCustomRBACOperation(), addRBACOperation(), and getObjectTypeId().

+ Here is the call graph for this function:

◆ addRBACOperation()

static ilDBUpdateNewObjectType::addRBACOperation (   $a_type_id,
  $a_ops_id 
)
static

Add RBAC operation.

Parameters
int$a_type_id
int$a_ops_id

Definition at line 84 of file class.ilDBUpdateNewObjectType.php.

85 {
86 global $ilDB;
87
88 // check if it already exists
89 $set = $ilDB->query('SELECT * FROM rbac_ta'.
90 ' WHERE typ_id = '.$ilDB->quote($a_type_id, 'integer').
91 ' AND ops_id = '.$ilDB->quote($a_ops_id, 'integer'));
92 if($ilDB->numRows($set))
93 {
94 return;
95 }
96
97 $fields = array(
98 'typ_id' => array('integer', $a_type_id),
99 'ops_id' => array('integer', $a_ops_id)
100 );
101 return $ilDB->insert('rbac_ta', $fields);
102 }

References $ilDB.

Referenced by addRBACCreate(), and addRBACOperations().

+ Here is the caller graph for this function:

◆ addRBACOperations()

static ilDBUpdateNewObjectType::addRBACOperations (   $a_type_id,
array  $a_operations 
)
static

Add RBAC operations for type.

Parameters
int$a_type_id
array$a_operations

Definition at line 62 of file class.ilDBUpdateNewObjectType.php.

63 {
64 foreach($a_operations as $ops_id)
65 {
66 if(self::isValidRBACOperation($ops_id))
67 {
68 if($ops_id == self::RBAC_OP_COPY)
69 {
70 $ops_id = self::getCustomRBACOperationId('copy');
71 }
72
73 self::addRBACOperation($a_type_id, $ops_id);
74 }
75 }
76 }

References addRBACOperation(), and getCustomRBACOperationId().

Referenced by addAdminNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addRBACTemplate()

static ilDBUpdateNewObjectType::addRBACTemplate (   $a_obj_type,
  $a_id,
  $a_description,
  $a_op_ids 
)
static

Add new RBAC template.

Parameters
string$a_obj_type
string$a_id
string$a_description
int | array$a_op_ids

Definition at line 484 of file class.ilDBUpdateNewObjectType.php.

485 {
486 global $ilDB;
487
488 $new_tpl_id = $ilDB->nextId('object_data');
489
490 $ilDB->manipulateF("INSERT INTO object_data (obj_id, type, title, description,".
491 " owner, create_date, last_update) VALUES (%s, %s, %s, %s, %s, %s, %s)",
492 array("integer", "text", "text", "text", "integer", "timestamp", "timestamp"),
493 array($new_tpl_id, "rolt", $a_id, $a_description, -1, ilUtil::now(), ilUtil::now()));
494
495 $ilDB->manipulateF("INSERT INTO rbac_fa (rol_id, parent, assign, protected)".
496 " VALUES (%s, %s, %s, %s)",
497 array("integer", "integer", "text", "text"),
498 array($new_tpl_id, 8, "n", "n"));
499
500 if($a_op_ids)
501 {
502 if(!is_array($a_op_ids))
503 {
504 $a_op_ids = array($a_op_ids);
505 }
506 foreach($a_op_ids as $op_id)
507 {
508 $ilDB->manipulateF("INSERT INTO rbac_templates (rol_id, type, ops_id, parent)".
509 " VALUES (%s, %s, %s, %s)",
510 array("integer", "text", "integer", "integer"),
511 array($new_tpl_id, $a_obj_type, $op_id, 8));
512 }
513 }
514 }

References $ilDB, and ilUtil\now().

+ Here is the call graph for this function:

◆ cloneOperation()

static ilDBUpdateNewObjectType::cloneOperation (   $a_obj_type,
  $a_source_op_id,
  $a_target_op_id 
)
static

Clone RBAC-settings between operations.

Parameters
string$a_obj_type
int$a_source_op_id
int$a_target_op_id

Definition at line 373 of file class.ilDBUpdateNewObjectType.php.

374 {
375 global $ilDB;
376
377 // rbac_pa
378 $sql = "SELECT rpa.*".
379 " FROM rbac_pa rpa".
380 " JOIN object_reference ref ON (ref.ref_id = rpa.ref_id)".
381 " JOIN object_data od ON (od.obj_id = ref.obj_id AND od.type = ".$ilDB->quote($a_obj_type).")".
382 // see ilUtil::_getObjectsByOperations()
383 " WHERE (".$ilDB->like("ops_id", "text","%i:".$a_source_op_id."%").
384 " OR ".$ilDB->like("ops_id", "text", "%:\"".$a_source_op_id."\";%").")";
385 $set = $ilDB->query($sql);
386 while($row = $ilDB->fetchAssoc($set))
387 {
388 $ops = unserialize($row["ops_id"]);
389 // the query above could match by array KEY, we need extra checks
390 if(in_array($a_source_op_id, $ops) && !in_array($a_target_op_id, $ops))
391 {
392 $ops[] = $a_target_op_id;
393
394 $ilDB->manipulate("UPDATE rbac_pa".
395 " SET ops_id = ".$ilDB->quote(serialize($ops), "text").
396 " WHERE rol_id = ".$ilDB->quote($row["rol_id"], "integer").
397 " AND ref_id = ".$ilDB->quote($row["ref_id"], "integer"));
398 }
399 }
400
401 // rbac_templates
402 $tmp = array();
403 $sql = "SELECT rol_id, parent, ops_id".
404 " FROM rbac_templates".
405 " WHERE type = ".$ilDB->quote($a_obj_type, "text").
406 " AND (ops_id = ".$ilDB->quote($a_source_op_id, "integer").
407 " OR ops_id = ".$ilDB->quote($a_target_op_id).")";
408 $set = $ilDB->query($sql);
409 while($row = $ilDB->fetchAssoc($set))
410 {
411 $tmp[$row["rol_id"]][$row["parent"]][] = $row["ops_id"];
412 }
413
414 foreach($tmp as $role_id => $parents)
415 {
416 foreach($parents as $parent_id => $ops_ids)
417 {
418 // only if the target op is missing
419 if(sizeof($ops_ids) < 2 && in_array($a_source_op_id, $ops_ids))
420 {
421 $ilDB->manipulate("INSERT INTO rbac_templates".
422 " (rol_id, type, ops_id, parent)".
423 " VALUES ".
424 "(".$ilDB->quote($role_id, "integer").
425 ",".$ilDB->quote($a_obj_type, "text").
426 ",".$ilDB->quote($a_target_op_id, "integer").
427 ",".$ilDB->quote($parent_id, "integer").
428 ")");
429 }
430 }
431 }
432 }

References $ilDB, and $row.

◆ deleteRBACOperation()

static ilDBUpdateNewObjectType::deleteRBACOperation (   $a_type,
  $a_ops_id 
)
static

Delete rbac operation.

Parameters
int$a_type
int$a_ops_id

Definition at line 132 of file class.ilDBUpdateNewObjectType.php.

133 {
134 global $ilDB;
135
136 if(!$a_type || !$a_ops_id)
137 {
138 return;
139 }
140
141 $type_id = self::getObjectTypeId($a_type);
142 if(!$type_id)
143 {
144 return;
145 }
146
147 $query = 'DELETE FROM rbac_ta WHERE '.
148 'typ_id = '.$ilDB->quote($type_id,'integer').' AND '.
149 'ops_id = '.$ilDB->quote($a_ops_id,'integer');
150 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
151 $ilDB->manipulate($query);
152
153 self::deleteRBACTemplateOperation($a_type, $a_ops_id);
154 }
static deleteRBACTemplateOperation($a_type, $a_ops_id)
Delete operation for type in templates.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

References $GLOBALS, $ilDB, $query, deleteRBACTemplateOperation(), and getObjectTypeId().

+ Here is the call graph for this function:

◆ deleteRBACTemplateOperation()

static ilDBUpdateNewObjectType::deleteRBACTemplateOperation (   $a_type,
  $a_ops_id 
)
static

Delete operation for type in templates.

Parameters
string$a_type
int$a_ops_id

Definition at line 162 of file class.ilDBUpdateNewObjectType.php.

163 {
164 global $ilDB;
165
166 if(!$a_type || !$a_ops_id)
167 {
168 return;
169 }
170
171 $query = 'DELETE FROM rbac_templates WHERE '.
172 'type = '.$ilDB->quote($a_type,'text').' AND '.
173 'ops_id = '.$ilDB->quote($a_ops_id,'integer');
174 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
175 $ilDB->manipulate($query);
176 }

References $GLOBALS, $ilDB, and $query.

Referenced by deleteRBACOperation().

+ Here is the caller graph for this function:

◆ getCustomRBACOperationId()

static ilDBUpdateNewObjectType::getCustomRBACOperationId (   $a_operation)
static

Get id of RBAC operation.

Parameters
string$a_operation
Returns
int

Definition at line 207 of file class.ilDBUpdateNewObjectType.php.

208 {
209 global $ilDB;
210
211 $sql = 'SELECT ops_id'.
212 ' FROM rbac_operations'.
213 ' WHERE operation = '.$ilDB->quote($a_operation, 'text');
214 $res = $ilDB->query($sql);
215 $row = $ilDB->fetchAssoc($res);
216 return $row['ops_id'];
217 }

References $ilDB, $res, and $row.

Referenced by addCustomRBACOperation(), and addRBACOperations().

+ Here is the caller graph for this function:

◆ getObjectTypeId()

static ilDBUpdateNewObjectType::getObjectTypeId (   $a_type)
static

Get id for object data type entry.

Parameters
string$a_type
Returns
int

Definition at line 268 of file class.ilDBUpdateNewObjectType.php.

269 {
270 global $ilDB;
271
272 $sql = 'SELECT obj_id FROM object_data'.
273 ' WHERE type = '.$ilDB->quote('typ', 'text').
274 ' AND title = '.$ilDB->quote($a_type, 'text');
275 $res = $ilDB->query($sql);
276 $row = $ilDB->fetchAssoc($res);
277 return $row['obj_id'];
278 }

References $ilDB, $res, and $row.

Referenced by addNewType(), addRBACCreate(), and deleteRBACOperation().

+ Here is the caller graph for this function:

◆ isRBACOperation()

static ilDBUpdateNewObjectType::isRBACOperation (   $a_type_id,
  $a_ops_id 
)
static

Check if rbac operation exists.

Parameters
int$a_type_idtype id
int$a_ops_idoperation id
Returns
bool

Definition at line 111 of file class.ilDBUpdateNewObjectType.php.

112 {
113 global $ilDB;
114
115 // check if it already exists
116 $set = $ilDB->query('SELECT * FROM rbac_ta' .
117 ' WHERE typ_id = ' . $ilDB->quote($a_type_id, 'integer') .
118 ' AND ops_id = ' . $ilDB->quote($a_ops_id, 'integer'));
119 if ($ilDB->numRows($set))
120 {
121 return true;
122 }
123 return false;
124 }

References $ilDB.

◆ isValidRBACOperation()

static ilDBUpdateNewObjectType::isValidRBACOperation (   $a_ops_id)
staticprotected

Check if given RBAC operation id is valid.

Parameters
int$a_ops_id
Returns
bool

Definition at line 184 of file class.ilDBUpdateNewObjectType.php.

185 {
186 $valid = array(
187 self::RBAC_OP_EDIT_PERMISSIONS,
188 self::RBAC_OP_VISIBLE,
189 self::RBAC_OP_READ,
190 self::RBAC_OP_WRITE,
191 self::RBAC_OP_DELETE,
192 self::RBAC_OP_COPY
193 );
194 if(in_array($a_ops_id, $valid))
195 {
196 return true;
197 }
198 return false;
199 }
$valid

References $valid.

◆ updateOperationOrder()

static ilDBUpdateNewObjectType::updateOperationOrder (   $a_operation,
  $a_pos 
)
static

Change order of operations.

Parameters
string$a_operation
int$a_pos

Definition at line 307 of file class.ilDBUpdateNewObjectType.php.

308 {
309 global $ilDB;
310
311 $ilDB->update('rbac_operations',
312 array('op_order' => array('integer', $a_pos)),
313 array('operation' => array('text', $a_operation))
314 );
315 }

References $ilDB.

◆ varchar2text()

static ilDBUpdateNewObjectType::varchar2text (   $a_table_name,
  $a_column_name 
)
static

Migrate varchar column to text/clob.

Parameters
string$a_table_name
string$a_column_name
Returns
bool

Definition at line 441 of file class.ilDBUpdateNewObjectType.php.

442 {
443 global $ilDB;
444
445 $tmp_column_name = $a_column_name."_tmp_clob";
446
447 if(!$ilDB->tableColumnExists($a_table_name, $a_column_name) ||
448 $ilDB->tableColumnExists($a_table_name, $tmp_column_name))
449 {
450 return false;
451 }
452
453 // oracle does not support ALTER TABLE varchar2 to CLOB
454
455 $ilDB->lockTables(array(
456 array('name'=> $a_table_name, 'type'=>ilDB::LOCK_WRITE)
457 ));
458
459 $def = array(
460 'type' => 'clob',
461 'notnull' => false
462 );
463 $ilDB->addTableColumn($a_table_name, $tmp_column_name, $def);
464
465 $ilDB->manipulate('UPDATE '.$a_table_name.' SET '.$tmp_column_name.' = '.$a_column_name);
466
467 $ilDB->dropTableColumn($a_table_name, $a_column_name);
468
469 $ilDB->renameTableColumn($a_table_name, $tmp_column_name, $a_column_name);
470
471 $ilDB->unlockTables();
472
473 return true;
474 }
const LOCK_WRITE
Definition: class.ilDB.php:30

References $ilDB, and ilDB\LOCK_WRITE.

Field Documentation

◆ RBAC_OP_COPY

const ilDBUpdateNewObjectType::RBAC_OP_COPY = 99

Definition at line 20 of file class.ilDBUpdateNewObjectType.php.

◆ RBAC_OP_DELETE

const ilDBUpdateNewObjectType::RBAC_OP_DELETE = 6

Definition at line 19 of file class.ilDBUpdateNewObjectType.php.

◆ RBAC_OP_EDIT_PERMISSIONS

const ilDBUpdateNewObjectType::RBAC_OP_EDIT_PERMISSIONS = 1

Definition at line 15 of file class.ilDBUpdateNewObjectType.php.

◆ RBAC_OP_READ

const ilDBUpdateNewObjectType::RBAC_OP_READ = 3

Definition at line 17 of file class.ilDBUpdateNewObjectType.php.

◆ RBAC_OP_VISIBLE

const ilDBUpdateNewObjectType::RBAC_OP_VISIBLE = 2

Definition at line 16 of file class.ilDBUpdateNewObjectType.php.

◆ RBAC_OP_WRITE

const ilDBUpdateNewObjectType::RBAC_OP_WRITE = 4

Definition at line 18 of file class.ilDBUpdateNewObjectType.php.


The documentation for this class was generated from the following file: