ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAccessCustomRBACOperationAddedObjective Class Reference
+ Inheritance diagram for ilAccessCustomRBACOperationAddedObjective:
+ Collaboration diagram for ilAccessCustomRBACOperationAddedObjective:

Public Member Functions

 __construct (string $id, string $title, string $class, int $pos, array $types=[])
 
 getHash ()
 
 getLabel ()
 
 isNotable ()
 
 getPreconditions (Environment $environment)
 
 achieve (Environment $environment)
 
 isApplicable (Environment $environment)
 

Protected Member Functions

 initEnvironment (Setup\Environment $environment)
 
 resetDIC ($dic)
 

Protected Attributes

string $id
 
string $title
 
string $class
 
int $pos
 
array $types
 

Private Attributes

const NO_DIC_FOUND = 'There is no $DIC.'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccessCustomRBACOperationAddedObjective::__construct ( string  $id,
string  $title,
string  $class,
int  $pos,
array  $types = [] 
)

Member Function Documentation

◆ achieve()

ilAccessCustomRBACOperationAddedObjective::achieve ( Environment  $environment)

Definition at line 68 of file class.ilAccessCustomRBACOperationAddedObjective.php.

References $class, $dic, $id, $pos, $title, $type, ilRbacReview\_getCustomRBACOperationId(), ilObject\_getObjectTypeIdByTitle(), ILIAS\Setup\Environment\getResource(), initEnvironment(), and resetDIC().

68  : Environment
69  {
70  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
71 
72  $dic = $this->initEnvironment($environment);
73 
74  if ($this->class == "create") {
75  $this->pos = 9999;
76  }
77 
78  $ops_id = ilRbacReview::_getCustomRBACOperationId($this->id, $db);
79  if (is_null($ops_id)) {
80  $ops_id = $db->nextId("rbac_operations");
81 
82  $values = [
83  'ops_id' => ['integer', $ops_id],
84  'operation' => ['text', $this->id],
85  'description' => ['text', $this->title],
86  'class' => ['text', $this->class],
87  'op_order' => ['integer', $this->pos]
88  ];
89 
90  $db->insert("rbac_operations", $values);
91  }
92 
93  foreach ($this->types as $type) {
94  $type_id = ilObject::_getObjectTypeIdByTitle($type, $db);
95  if (!$type_id) {
96  $type_id = $db->nextId('object_data');
97 
98  $fields = [
99  'obj_id' => ['integer', $type_id],
100  'type' => ['text', 'typ'],
101  'title' => ['text', $type],
102  'description' => ['text', $this->title],
103  'owner' => ['integer', -1],
104  'create_date' => ['timestamp', $db->now()],
105  'last_update' => ['timestamp', $db->now()]
106  ];
107  $db->insert('object_data', $fields);
108  }
109 
110  $sql =
111  "SELECT typ_id, ops_id " . PHP_EOL
112  . "FROM rbac_ta" . PHP_EOL
113  . "WHERE typ_id = " . $db->quote($type_id, "integer") . PHP_EOL
114  . "AND ops_id = " . $db->quote($ops_id, 'integer') . PHP_EOL
115  ;
116 
117  $result = $db->query($sql);
118  if ($db->numRows($result)) {
119  continue;
120  }
121 
122  $values = [
123  "typ_id" => ["integer", $type_id],
124  "ops_id" => ["integer", $ops_id]
125  ];
126 
127  $db->insert("rbac_ta", $values);
128  }
129 
130  $this->resetDIC($dic);
131  return $environment;
132  }
$type
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
static _getCustomRBACOperationId(string $operation, \ilDBInterface $ilDB=null)
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$dic
Definition: result.php:32
static _getObjectTypeIdByTitle(string $type, \ilDBInterface $ilDB=null)
+ Here is the call graph for this function:

◆ getHash()

ilAccessCustomRBACOperationAddedObjective::getHash ( )

Definition at line 45 of file class.ilAccessCustomRBACOperationAddedObjective.php.

45  : string
46  {
47  return hash("sha256", self::class . "::" . $this->id);
48  }

◆ getLabel()

ilAccessCustomRBACOperationAddedObjective::getLabel ( )

Definition at line 50 of file class.ilAccessCustomRBACOperationAddedObjective.php.

50  : string
51  {
52  $types = implode(",", $this->types);
53  return "Add custom rbac operation (id=$this->id;title=$this->title;class=$this->class;pos=$this->pos;types=($types))";
54  }

◆ getPreconditions()

ilAccessCustomRBACOperationAddedObjective::getPreconditions ( Environment  $environment)

Definition at line 61 of file class.ilAccessCustomRBACOperationAddedObjective.php.

61  : array
62  {
63  return [
65  ];
66  }

◆ initEnvironment()

ilAccessCustomRBACOperationAddedObjective::initEnvironment ( Setup\Environment  $environment)
protected

Definition at line 168 of file class.ilAccessCustomRBACOperationAddedObjective.php.

References $DIC, and $GLOBALS.

Referenced by achieve(), and isApplicable().

169  {
170  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
171 
172  // ATTENTION: This is a total abomination. It only exists to allow various
173  // subcomponents of the various readers to run. This is a memento to the
174  // fact, that dependency injection is something we want. Currently, every
175  // component could just service locate the whole world via the global $DIC.
176  $DIC = self::NO_DIC_FOUND;
177  if (array_key_exists('DIC', $GLOBALS)) {
178  $DIC = $GLOBALS['DIC'];
179  }
180  $GLOBALS['DIC'] = new DI\Container();
181  $GLOBALS['DIC']['ilDB'] = $db;
182 
183  if (!defined('ILIAS_ABSOLUTE_PATH')) {
184  define('ILIAS_ABSOLUTE_PATH', dirname(__FILE__, 5));
185  }
186 
187  return $DIC;
188  }
global $DIC
Definition: feed.php:28
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
+ Here is the caller graph for this function:

◆ isApplicable()

ilAccessCustomRBACOperationAddedObjective::isApplicable ( Environment  $environment)

Definition at line 134 of file class.ilAccessCustomRBACOperationAddedObjective.php.

References $dic, ILIAS\LTI\ToolProvider\$key, $type, ilRbacReview\_getCustomRBACOperationId(), ilObject\_getObjectTypeIdByTitle(), ILIAS\Setup\Environment\getResource(), initEnvironment(), and resetDIC().

134  : bool
135  {
136  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
137 
138  $dic = $this->initEnvironment($environment);
139 
140  $ops_id = ilRbacReview::_getCustomRBACOperationId($this->id, $db);
141  if (!$ops_id) {
142  return true;
143  }
144 
145  foreach ($this->types as $key => $type) {
146  $type_id = ilObject::_getObjectTypeIdByTitle($type, $db);
147  if (is_null($type_id)) {
148  return true;
149  }
150 
151  $sql =
152  "SELECT typ_id, ops_id " . PHP_EOL
153  . "FROM rbac_ta" . PHP_EOL
154  . "WHERE typ_id = " . $db->quote($type_id, "integer") . PHP_EOL
155  . "AND ops_id = " . $db->quote($ops_id, 'integer') . PHP_EOL
156  ;
157 
158  $result = $db->query($sql);
159  if ($db->numRows($result)) {
160  unset($this->types[$key]);
161  }
162  }
163 
164  $this->resetDIC($dic);
165  return count($this->types) && in_array($this->class, ['create', 'object', 'general']);
166  }
$type
string $key
Consumer key/client ID value.
Definition: System.php:193
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
static _getCustomRBACOperationId(string $operation, \ilDBInterface $ilDB=null)
$dic
Definition: result.php:32
static _getObjectTypeIdByTitle(string $type, \ilDBInterface $ilDB=null)
+ Here is the call graph for this function:

◆ isNotable()

ilAccessCustomRBACOperationAddedObjective::isNotable ( )

Definition at line 56 of file class.ilAccessCustomRBACOperationAddedObjective.php.

56  : bool
57  {
58  return true;
59  }

◆ resetDIC()

ilAccessCustomRBACOperationAddedObjective::resetDIC (   $dic)
protected

Definition at line 190 of file class.ilAccessCustomRBACOperationAddedObjective.php.

References $dic, and $GLOBALS.

Referenced by achieve(), and isApplicable().

190  : void
191  {
192  if ($dic !== self::NO_DIC_FOUND) {
193  $GLOBALS['DIC'] = $dic;
194  return;
195  }
196  unset($GLOBALS['DIC']);
197  }
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$dic
Definition: result.php:32
+ Here is the caller graph for this function:

Field Documentation

◆ $class

string ilAccessCustomRBACOperationAddedObjective::$class
protected

Definition at line 32 of file class.ilAccessCustomRBACOperationAddedObjective.php.

Referenced by achieve().

◆ $id

string ilAccessCustomRBACOperationAddedObjective::$id
protected

Definition at line 30 of file class.ilAccessCustomRBACOperationAddedObjective.php.

Referenced by __construct(), and achieve().

◆ $pos

int ilAccessCustomRBACOperationAddedObjective::$pos
protected

Definition at line 33 of file class.ilAccessCustomRBACOperationAddedObjective.php.

Referenced by __construct(), and achieve().

◆ $title

string ilAccessCustomRBACOperationAddedObjective::$title
protected

Definition at line 31 of file class.ilAccessCustomRBACOperationAddedObjective.php.

Referenced by __construct(), and achieve().

◆ $types

array ilAccessCustomRBACOperationAddedObjective::$types
protected

Definition at line 34 of file class.ilAccessCustomRBACOperationAddedObjective.php.

Referenced by __construct().

◆ NO_DIC_FOUND

const ilAccessCustomRBACOperationAddedObjective::NO_DIC_FOUND = 'There is no $DIC.'
private

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