ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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 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 varchar2text ($a_table_name, $a_column_name)
 Migrate varchar column to text/clob. 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 301 of file class.ilDBUpdateNewObjectType.php.

References $ref_id.

302  {
303  global $ilDB, $tree;
304 
305  if(self::getObjectTypeId($a_obj_type))
306  {
307  return;
308  }
309 
310  $obj_type_id = self::addNewType($a_obj_type, $a_title);
311 
312  $obj_id = $ilDB->nextId('object_data');
313  $ilDB->manipulate("INSERT INTO object_data ".
314  "(obj_id, type, title, description, owner, create_date, last_update) VALUES (".
315  $ilDB->quote($obj_id, "integer").",".
316  $ilDB->quote($a_obj_type, "text").",".
317  $ilDB->quote($a_title, "text").",".
318  $ilDB->quote($a_title, "text").",".
319  $ilDB->quote(-1, "integer").",".
320  $ilDB->now().",".
321  $ilDB->now().
322  ")");
323 
324  $ref_id = $ilDB->nextId('object_reference');
325  $ilDB->manipulate("INSERT INTO object_reference ".
326  "(obj_id, ref_id) VALUES (".
327  $ilDB->quote($obj_id, "integer").",".
328  $ilDB->quote($ref_id, "integer").
329  ")");
330 
331  // put in tree
332  $tree = new ilTree(ROOT_FOLDER_ID);
333  $tree->insertNode($ref_id, SYSTEM_FOLDER_ID);
334 
335  $rbac_ops = array(
336  self::RBAC_OP_EDIT_PERMISSIONS,
337  self::RBAC_OP_VISIBLE,
338  self::RBAC_OP_READ,
339  self::RBAC_OP_WRITE
340  );
341  self::addRBACOperations($obj_type_id, $rbac_ops);
342  }
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: sahs_server.php:39

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

207  {
208  global $ilDB;
209 
210  // check if it already exists
211  $ops_id = self::getCustomRBACOperationId($a_id);
212  if($ops_id)
213  {
214  return $ops_id;
215  }
216 
217  if(!in_array($a_class, array('create', 'object', 'general')))
218  {
219  return;
220  }
221  if($a_class == 'create')
222  {
223  $a_pos = 9999;
224  }
225 
226  $ops_id = $ilDB->nextId('rbac_operations');
227 
228  $fields = array(
229  'ops_id' => array('integer', $ops_id),
230  'operation' => array('text', $a_id),
231  'description' => array('text', $a_title),
232  'class' => array('text', $a_class),
233  'op_order' => array('integer', $a_pos),
234  );
235  $ilDB->insert('rbac_operations', $fields);
236 
237  return $ops_id;
238  }

◆ 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.

References ilUtil\now().

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 now()
Return current timestamp in Y-m-d H:i:s format.
+ Here is the call 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 265 of file class.ilDBUpdateNewObjectType.php.

266  {
267  $ops_id = self::addCustomRBACOperation($a_id, $a_title, 'create', 9999);
268 
269  foreach($a_parent_types as $type)
270  {
271  $type_id = self::getObjectTypeId($type);
272  if($type_id)
273  {
274  self::addRBACOperation($type_id, $ops_id);
275  }
276  }
277  }

◆ 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  }

◆ 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  }

◆ deleteRBACOperation()

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

Delete rbac operation.

Parameters
int$a_type
int$a_ops_id

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

References $GLOBALS, and $query.

111  {
112  global $ilDB;
113 
114  if(!$a_type || !$a_ops_id)
115  {
116  return;
117  }
118 
119  $type_id = self::getObjectTypeId($a_type);
120  if(!$type_id)
121  {
122  return;
123  }
124 
125  $query = 'DELETE FROM rbac_ta WHERE '.
126  'typ_id = '.$ilDB->quote($type_id,'integer').' AND '.
127  'ops_id = '.$ilDB->quote($a_ops_id,'integer');
128  $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
129  $ilDB->manipulate($query);
130 
131  self::deleteRBACTemplateOperation($a_type, $a_ops_id);
132  }
$GLOBALS['ct_recipient']

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

References $GLOBALS, and $query.

141  {
142  global $ilDB;
143 
144  if(!$a_type || !$a_ops_id)
145  {
146  return;
147  }
148 
149  $query = 'DELETE FROM rbac_templates WHERE '.
150  'type = '.$ilDB->quote($a_type,'text').' AND '.
151  'ops_id = '.$ilDB->quote($a_ops_id,'integer');
152  $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
153  $ilDB->manipulate($query);
154  }
$GLOBALS['ct_recipient']

◆ getCustomRBACOperationId()

static ilDBUpdateNewObjectType::getCustomRBACOperationId (   $a_operation)
static

Get id of RBAC operation.

Parameters
string$a_operation
Returns
int

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

References $res, and $row.

186  {
187  global $ilDB;
188 
189  $sql = 'SELECT ops_id'.
190  ' FROM rbac_operations'.
191  ' WHERE operation = '.$ilDB->quote($a_operation, 'text');
192  $res = $ilDB->query($sql);
193  $row = $ilDB->fetchAssoc($res);
194  return $row['ops_id'];
195  }

◆ getObjectTypeId()

static ilDBUpdateNewObjectType::getObjectTypeId (   $a_type)
static

Get id for object data type entry.

Parameters
string$a_type
Returns
int

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

References $res, and $row.

247  {
248  global $ilDB;
249 
250  $sql = 'SELECT obj_id FROM object_data'.
251  ' WHERE type = '.$ilDB->quote('typ', 'text').
252  ' AND title = '.$ilDB->quote($a_type, 'text');
253  $res = $ilDB->query($sql);
254  $row = $ilDB->fetchAssoc($res);
255  return $row['obj_id'];
256  }

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

References $valid.

163  {
164  $valid = array(
165  self::RBAC_OP_EDIT_PERMISSIONS,
166  self::RBAC_OP_VISIBLE,
167  self::RBAC_OP_READ,
168  self::RBAC_OP_WRITE,
169  self::RBAC_OP_DELETE,
170  self::RBAC_OP_COPY
171  );
172  if(in_array($a_ops_id, $valid))
173  {
174  return true;
175  }
176  return false;
177  }
$valid

◆ updateOperationOrder()

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

Change order of operations.

Parameters
string$a_operation
int$a_pos

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

286  {
287  global $ilDB;
288 
289  $ilDB->update('rbac_operations',
290  array('op_order' => array('integer', $a_pos)),
291  array('operation' => array('text', $a_operation))
292  );
293  }

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

References ilDB\LOCK_WRITE.

352  {
353  global $ilDB;
354 
355  $tmp_column_name = $a_column_name."_tmp_clob";
356 
357  if(!$ilDB->tableColumnExists($a_table_name, $a_column_name) ||
358  $ilDB->tableColumnExists($a_table_name, $tmp_column_name))
359  {
360  return false;
361  }
362 
363  // oracle does not support ALTER TABLE varchar2 to CLOB
364 
365  $ilDB->lockTables(array(
366  array('name'=> $a_table_name, 'type'=>ilDB::LOCK_WRITE)
367  ));
368 
369  $def = array(
370  'type' => 'clob',
371  'notnull' => false
372  );
373  $ilDB->addTableColumn($a_table_name, $tmp_column_name, $def);
374 
375  $ilDB->manipulate('UPDATE '.$a_table_name.' SET '.$tmp_column_name.' = '.$a_column_name);
376 
377  $ilDB->dropTableColumn($a_table_name, $a_column_name);
378 
379  $ilDB->renameTableColumn($a_table_name, $tmp_column_name, $a_column_name);
380 
381  $ilDB->unlockTables();
382 
383  return true;
384  }
const LOCK_WRITE
Definition: class.ilDB.php:30

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: