ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 325 of file class.ilDBUpdateNewObjectType.php.

326 {
327 global $ilDB, $tree;
328
329 if(self::getObjectTypeId($a_obj_type))
330 {
331 return;
332 }
333
334 $obj_type_id = self::addNewType($a_obj_type, $a_title);
335
336 $obj_id = $ilDB->nextId('object_data');
337 $ilDB->manipulate("INSERT INTO object_data ".
338 "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
339 $ilDB->quote($obj_id, "integer").",".
340 $ilDB->quote($a_obj_type, "text").",".
341 $ilDB->quote($a_title, "text").",".
342 $ilDB->quote($a_title, "text").",".
343 $ilDB->quote(-1, "integer").",".
344 $ilDB->now().",".
345 $ilDB->now().
346 ")");
347
348 $ref_id = $ilDB->nextId('object_reference');
349 $ilDB->manipulate("INSERT INTO object_reference ".
350 "(obj_id, ref_id) VALUES (".
351 $ilDB->quote($obj_id, "integer").",".
352 $ilDB->quote($ref_id, "integer").
353 ")");
354
355 // put in tree
356 require_once("Services/Tree/classes/class.ilTree.php");
357 $tree = new ilTree(ROOT_FOLDER_ID);
358 $tree->insertNode($ref_id, SYSTEM_FOLDER_ID);
359
360 $rbac_ops = array(
361 self::RBAC_OP_EDIT_PERMISSIONS,
362 self::RBAC_OP_VISIBLE,
363 self::RBAC_OP_READ,
364 self::RBAC_OP_WRITE
365 );
366 self::addRBACOperations($obj_type_id, $rbac_ops);
367 }
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 230 of file class.ilDBUpdateNewObjectType.php.

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

290 {
291 $ops_id = self::addCustomRBACOperation($a_id, $a_title, 'create', 9999);
292
293 foreach($a_parent_types as $type)
294 {
295 $type_id = self::getObjectTypeId($type);
296 if($type_id)
297 {
298 self::addRBACOperation($type_id, $ops_id);
299 }
300 }
301 }
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
Returns
bool

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

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

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 491 of file class.ilDBUpdateNewObjectType.php.

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

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 376 of file class.ilDBUpdateNewObjectType.php.

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

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 134 of file class.ilDBUpdateNewObjectType.php.

135 {
136 global $ilDB;
137
138 if(!$a_type || !$a_ops_id)
139 {
140 return;
141 }
142
143 $type_id = self::getObjectTypeId($a_type);
144 if(!$type_id)
145 {
146 return;
147 }
148
149 $query = 'DELETE FROM rbac_ta WHERE '.
150 'typ_id = '.$ilDB->quote($type_id,'integer').' AND '.
151 'ops_id = '.$ilDB->quote($a_ops_id,'integer');
152 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
153 $ilDB->manipulate($query);
154
156 }
static deleteRBACTemplateOperation($a_type, $a_ops_id)
Delete operation for type in templates.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$a_type
Definition: workflow.php:93

References $a_type, $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 164 of file class.ilDBUpdateNewObjectType.php.

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

References $a_type, $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 209 of file class.ilDBUpdateNewObjectType.php.

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

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 270 of file class.ilDBUpdateNewObjectType.php.

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

References $a_type, $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 113 of file class.ilDBUpdateNewObjectType.php.

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

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 186 of file class.ilDBUpdateNewObjectType.php.

187 {
188 $valid = array(
189 self::RBAC_OP_EDIT_PERMISSIONS,
190 self::RBAC_OP_VISIBLE,
191 self::RBAC_OP_READ,
192 self::RBAC_OP_WRITE,
193 self::RBAC_OP_DELETE,
194 self::RBAC_OP_COPY
195 );
196 if(in_array($a_ops_id, $valid))
197 {
198 return true;
199 }
200 return false;
201 }
$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 309 of file class.ilDBUpdateNewObjectType.php.

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

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 444 of file class.ilDBUpdateNewObjectType.php.

445 {
446 global $ilDB;
447
448 $tmp_column_name = $a_column_name."_tmp_clob";
449
450 if(!$ilDB->tableColumnExists($a_table_name, $a_column_name) ||
451 $ilDB->tableColumnExists($a_table_name, $tmp_column_name))
452 {
453 return false;
454 }
455
456 // oracle does not support ALTER TABLE varchar2 to CLOB
457
458 $ilAtomQuery = $ilDB->buildAtomQuery();
459 $ilAtomQuery->addTableLock($a_table_name);
460
461 $ilAtomQuery->addQueryCallable(
462 function(ilDBInterface $ilDB) use ($a_table_name, $a_column_name, $tmp_column_name)
463 {
464 $def = array(
465 'type' => 'clob',
466 'notnull' => false
467 );
468 $ilDB->addTableColumn($a_table_name, $tmp_column_name, $def);
469
470 $ilDB->manipulate('UPDATE '.$a_table_name.' SET '.$tmp_column_name.' = '.$a_column_name);
471
472 $ilDB->dropTableColumn($a_table_name, $a_column_name);
473
474 $ilDB->renameTableColumn($a_table_name, $tmp_column_name, $a_column_name);
475
476 });
477
478 $ilAtomQuery->run();
479
480 return true;
481 }
Interface ilDBInterface.

References $ilDB.

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: