ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilTreeAdminNodeAddedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
24
26{
27 protected const RBAC_OP_EDIT_PERMISSIONS = 1;
28 protected const RBAC_OP_VISIBLE = 2;
29 protected const RBAC_OP_READ = 3;
30 protected const RBAC_OP_WRITE = 4;
31
32 protected array $rbac_ops = [
36 ];
37
38 protected string $type;
39 protected string $title;
40 protected string $parent_type;
41
42 public function __construct(string $type, string $title, string $parent_type = "")
43 {
44 $this->type = $type;
45 $this->title = $title;
46 $this->parent_type = $parent_type;
47 }
48
49 public function getHash(): string
50 {
51 return hash("sha256", self::class . "::" . $this->type);
52 }
53
54 public function getLabel(): string
55 {
56 return "Add new admin node to tree (type=$this->type;title=$this->title)";
57 }
58
59 public function isNotable(): bool
60 {
61 return true;
62 }
63
64 public function getPreconditions(Environment $environment): array
65 {
66 return [
69 ];
70 }
71
72 public function achieve(Environment $environment): Environment
73 {
74 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
75 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
76
77 // ATTENTION: This is a total abomination. It only exists to allow various
78 // sub components of the various readers to run. This is a memento to the
79 // fact, that dependency injection is something we want. Currently, every
80 // component could just service locate the whole world via the global $DIC.
81 $PREVIOUS_DIC = $GLOBALS["DIC"] ?? null;
82 $GLOBALS["DIC"] = new Container();
83 $GLOBALS["DIC"]["ilDB"] = $db;
84
85 try {
86 if (!defined("ROOT_FOLDER_ID")) {
87 define("ROOT_FOLDER_ID", (int) $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
88 }
89 if (!defined("SYSTEM_FOLDER_ID")) {
90 define("SYSTEM_FOLDER_ID", $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
91 }
92 if (!defined("ILIAS_LOG_ENABLED")) {
93 define("ILIAS_LOG_ENABLED", false);
94 }
95
96 $obj_type_id = $db->nextId("object_data");
97 $values = [
98 'obj_id' => ['integer', $obj_type_id],
99 'type' => ['text', 'typ'],
100 'title' => ['text', $this->type],
101 'description' => ['text', $this->title],
102 'owner' => ['integer', -1],
103 'create_date' => ['timestamp', date("Y-m-d H:i:s")],
104 'last_update' => ['timestamp', date("Y-m-d H:i:s")]
105 ];
106 $db->insert("object_data", $values);
107
108 $obj_id = $db->nextId("object_data");
109 $values = [
110 'obj_id' => ['integer', $obj_id],
111 'type' => ['text', $this->type],
112 'title' => ['text', $this->title],
113 'description' => ['text', $this->title],
114 'owner' => ['integer', -1],
115 'create_date' => ['timestamp', date("Y-m-d H:i:s")],
116 'last_update' => ['timestamp', date("Y-m-d H:i:s")]
117 ];
118 $db->insert("object_data", $values);
119
120 $ref_id = $db->nextId("object_reference");
121 $values = [
122 "obj_id" => ["integer", $obj_id],
123 "ref_id" => ["integer", $ref_id]
124 ];
125 $db->insert("object_reference", $values);
126
127 $tree = new ilTree(
129 0,
130 $db
131 );
132 if ($this->parent_type) {
133 $set = $db->queryF(
134 "SELECT * FROM object_data " .
135 " WHERE type = %s ",
136 ["text"],
137 [$this->parent_type]
138 );
139 $rec = $db->fetchAssoc($set);
140
141 $set = $db->queryF(
142 "SELECT * FROM object_reference " .
143 " WHERE obj_id = %s ",
144 ["integer"],
145 [$rec["obj_id"]]
146 );
147 $rec = $db->fetchAssoc($set);
148 $parent_type_ref_id = $rec["ref_id"];
149
150 $tree->insertNode((int) $ref_id, (int) $parent_type_ref_id);
151 } else {
152 $tree->insertNode((int) $ref_id, (int) SYSTEM_FOLDER_ID);
153 }
154
155 foreach ($this->rbac_ops as $ops_id) {
156 if (ilRbacReview::_isRBACOperation($obj_type_id, $ops_id, $db)) {
157 continue;
158 }
159 $values = [
160 "typ_id" => ["integer", $obj_type_id],
161 "ops_id" => ["integer", $ops_id]
162 ];
163 $db->insert("rbac_ta", $values);
164 }
165 } finally {
166 // reset the abomination again so we don't make objectives flaky.
167 $GLOBALS["DIC"] = $PREVIOUS_DIC;
168 }
169
170 return $environment;
171 }
172
173 public function isApplicable(Environment $environment): bool
174 {
175 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
176 return !((bool) ilObject::_getObjectTypeIdByTitle($this->type, $db));
177 }
178}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
static _getObjectTypeIdByTitle(string $type, ?\ilDBInterface $ilDB=null)
static _isRBACOperation(int $type_id, int $ops_id, ?\ilDBInterface $ilDB=null)
__construct(string $type, string $title, string $parent_type="")
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const SYSTEM_FOLDER_ID
Definition: constants.php:35
const ROOT_FOLDER_ID
Definition: constants.php:32
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.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$GLOBALS["DIC"]
Definition: wac.php:54