ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTreeAdminNodeAddedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\Setup;
23 
24 class ilTreeAdminNodeAddedObjective implements Setup\Objective
25 {
26  protected const RBAC_OP_EDIT_PERMISSIONS = 1;
27  protected const RBAC_OP_VISIBLE = 2;
28  protected const RBAC_OP_READ = 3;
29  protected const RBAC_OP_WRITE = 4;
30 
31  protected array $rbac_ops = [
32  self::RBAC_OP_EDIT_PERMISSIONS,
33  self::RBAC_OP_VISIBLE,
34  self::RBAC_OP_READ,
35  self::RBAC_OP_WRITE
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  global $DIC;
75  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
76  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
77  $DIC['ilDB'] = $DIC['ilDB'] ?? $db;
78 
79  if (!defined("ROOT_FOLDER_ID")) {
80  define("ROOT_FOLDER_ID", (int) $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
81  }
82  if (!defined("SYSTEM_FOLDER_ID")) {
83  define("SYSTEM_FOLDER_ID", $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
84  }
85  if (!defined("ILIAS_LOG_ENABLED")) {
86  define("ILIAS_LOG_ENABLED", false);
87  }
88 
89  $obj_type_id = $db->nextId("object_data");
90  $values = [
91  'obj_id' => ['integer', $obj_type_id],
92  'type' => ['text', 'typ'],
93  'title' => ['text', $this->type],
94  'description' => ['text', $this->title],
95  'owner' => ['integer', -1],
96  'create_date' => ['timestamp', date("Y-m-d H:i:s")],
97  'last_update' => ['timestamp', date("Y-m-d H:i:s")]
98  ];
99  $db->insert("object_data", $values);
100 
101  $obj_id = $db->nextId("object_data");
102  $values = [
103  'obj_id' => ['integer', $obj_id],
104  'type' => ['text', $this->type],
105  'title' => ['text', $this->title],
106  'description' => ['text', $this->title],
107  'owner' => ['integer', -1],
108  'create_date' => ['timestamp', date("Y-m-d H:i:s")],
109  'last_update' => ['timestamp', date("Y-m-d H:i:s")]
110  ];
111  $db->insert("object_data", $values);
112 
113  $ref_id = $db->nextId("object_reference");
114  $values = [
115  "obj_id" => ["integer", $obj_id],
116  "ref_id" => ["integer", $ref_id]
117  ];
118  $db->insert("object_reference", $values);
119 
120  $tree = new ilTree(
122  0,
123  $db
124  );
125  if ($this->parent_type) {
126  $set = $db->queryF(
127  "SELECT * FROM object_data " .
128  " WHERE type = %s ",
129  ["text"],
130  [$this->parent_type]
131  );
132  $rec = $db->fetchAssoc($set);
133 
134  $set = $db->queryF(
135  "SELECT * FROM object_reference " .
136  " WHERE obj_id = %s ",
137  ["integer"],
138  [$rec["obj_id"]]
139  );
140  $rec = $db->fetchAssoc($set);
141  $parent_type_ref_id = $rec["ref_id"];
142 
143  $tree->insertNode((int) $ref_id, (int) $parent_type_ref_id);
144  } else {
145  $tree->insertNode((int) $ref_id, (int) SYSTEM_FOLDER_ID);
146  }
147 
148  foreach ($this->rbac_ops as $ops_id) {
149  if (ilRbacReview::_isRBACOperation($obj_type_id, $ops_id, $db)) {
150  continue;
151  }
152  $values = [
153  "typ_id" => ["integer", $obj_type_id],
154  "ops_id" => ["integer", $ops_id]
155  ];
156  $db->insert("rbac_ta", $values);
157  }
158  return $environment;
159  }
160 
161  public function isApplicable(Environment $environment): bool
162  {
163  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
164  return !((bool) ilObject::_getObjectTypeIdByTitle($this->type, $db));
165  }
166 }
const ROOT_FOLDER_ID
Definition: constants.php:32
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
static _isRBACOperation(int $type_id, int $ops_id, \ilDBInterface $ilDB=null)
static _getObjectTypeIdByTitle(string $type, \ilDBInterface $ilDB=null)
__construct(string $type, string $title, string $parent_type="")