ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 67 of file class.ilAccessCustomRBACOperationAddedObjective.php.

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

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

+ Here is the call graph for this function:

◆ getHash()

ilAccessCustomRBACOperationAddedObjective::getHash ( )

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

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

◆ getLabel()

ilAccessCustomRBACOperationAddedObjective::getLabel ( )

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

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

References $types.

◆ getPreconditions()

ilAccessCustomRBACOperationAddedObjective::getPreconditions ( Environment  $environment)

◆ initEnvironment()

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

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

168 {
169 $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
170
171 // ATTENTION: This is a total abomination. It only exists to allow various
172 // subcomponents of the various readers to run. This is a memento to the
173 // fact, that dependency injection is something we want. Currently, every
174 // component could just service locate the whole world via the global $DIC.
176 if (array_key_exists('DIC', $GLOBALS)) {
177 $DIC = $GLOBALS['DIC'];
178 }
179 $GLOBALS['DIC'] = new DI\Container();
180 $GLOBALS['DIC']['ilDB'] = $db;
181
182 if (!defined('ILIAS_ABSOLUTE_PATH')) {
183 define('ILIAS_ABSOLUTE_PATH', dirname(__FILE__, 6));
184 }
185
186 return $DIC;
187 }
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54

References $DIC, $GLOBALS, and NO_DIC_FOUND.

Referenced by achieve(), and isApplicable().

+ Here is the caller graph for this function:

◆ isApplicable()

ilAccessCustomRBACOperationAddedObjective::isApplicable ( Environment  $environment)

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

133 : bool
134 {
135 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
136
137 $dic = $this->initEnvironment($environment);
138
139 $ops_id = ilRbacReview::_getCustomRBACOperationId($this->id, $db);
140 if (!$ops_id) {
141 return true;
142 }
143
144 foreach ($this->types as $key => $type) {
145 $type_id = ilObject::_getObjectTypeIdByTitle($type, $db);
146 if (is_null($type_id)) {
147 return true;
148 }
149
150 $sql =
151 "SELECT typ_id, ops_id " . PHP_EOL
152 . "FROM rbac_ta" . PHP_EOL
153 . "WHERE typ_id = " . $db->quote($type_id, "integer") . PHP_EOL
154 . "AND ops_id = " . $db->quote($ops_id, 'integer') . PHP_EOL
155 ;
156
157 $result = $db->query($sql);
158 if ($db->numRows($result)) {
159 unset($this->types[$key]);
160 }
161 }
162
163 $this->resetDIC($dic);
164 return count($this->types) && in_array($this->class, ['create', 'object', 'general']);
165 }

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

+ Here is the call graph for this function:

◆ isNotable()

ilAccessCustomRBACOperationAddedObjective::isNotable ( )

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

55 : bool
56 {
57 return true;
58 }

◆ resetDIC()

ilAccessCustomRBACOperationAddedObjective::resetDIC (   $dic)
protected

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

189 : void
190 {
191 if ($dic !== self::NO_DIC_FOUND) {
192 $GLOBALS['DIC'] = $dic;
193 return;
194 }
195 unset($GLOBALS['DIC']);
196 }

References $dic, and $GLOBALS.

Referenced by achieve(), and isApplicable().

+ Here is the caller graph for this function:

Field Documentation

◆ $class

string ilAccessCustomRBACOperationAddedObjective::$class
protected

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

Referenced by achieve().

◆ $id

◆ $pos

int ilAccessCustomRBACOperationAddedObjective::$pos
protected

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

Referenced by __construct(), and achieve().

◆ $title

◆ $types

array ilAccessCustomRBACOperationAddedObjective::$types
protected

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

Referenced by __construct(), and getLabel().

◆ NO_DIC_FOUND

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

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

Referenced by initEnvironment().


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