ILIAS  release_8 Revision v8.24
class.ilAccessRBACTemplateAddedObjective.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2021 - Daniel Weise <daniel.weise@concepts-and-training.de> - Extended GPL, see LICENSE */
6
9
11{
12 protected string $type;
13 protected string $id;
14 protected string $description;
15 protected array $op_ids;
16
17 public function __construct(string $type, string $id, string $description, array $op_ids = [])
18 {
19 $this->type = $type;
20 $this->id = $id;
21 $this->description = $description;
22 $this->op_ids = $op_ids;
23 }
24
25 public function getHash(): string
26 {
27 return hash("sha256", self::class);
28 }
29
30 public function getLabel(): string
31 {
32 $op_ids = implode(",", $this->op_ids);
33 return "Add rbac template (type=$this->type;id=$this->id;description=$this->description;op_ids=$op_ids)";
34 }
35
36 public function isNotable(): bool
37 {
38 return true;
39 }
40
41 public function getPreconditions(Environment $environment): array
42 {
43 return [
45 ];
46 }
47
48 public function achieve(Environment $environment): Environment
49 {
50 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
51
52 $tpl_id = $db->nextId("object_data");
53 $values = [
54 "obj_id" => ["integer", $tpl_id],
55 "type" => ["text", "rolt"],
56 "title" => ["text", $this->id],
57 "description" => ["text", $this->description],
58 "owner" => ["integer", -1],
59 "create_date" => ["timestamp", date("Y-m-d H:i:s")],
60 "last_update" => ["timestamp", date("Y-m-d H:i:s")]
61 ];
62 $db->insert("object_data", $values);
63
64 $values = [
65 "rol_id" => ["integer", $tpl_id],
66 "parent" => ["integer", 8],
67 "assign" => ["text", "n"],
68 "protected" => ["text", "n"]
69 ];
70 $db->insert("rbac_fa", $values);
71
72 foreach ($this->op_ids as $op_id) {
73 $values = [
74 "rol_id" => ["integer", $tpl_id],
75 "type" => ["text", $this->type],
76 "ops_id" => ["integer", $op_id],
77 "parent" => ["integer", 8]
78 ];
79 $db->insert("rbac_templates", $values);
80 }
81
82 return $environment;
83 }
84
85 public function isApplicable(Environment $environment): bool
86 {
87 return (bool) count($this->op_ids);
88 }
89}
__construct(string $type, string $id, string $description, array $op_ids=[])
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...