ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilStyleClassAddedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
23
25{
26 protected string $class;
27 protected string $type;
28 protected string $tag;
29 protected array $parameters;
30 protected int $hide;
31
32 public function __construct(string $class, string $type, string $tag, array $parameters = [], int $hide = 0)
33 {
34 $this->class = $class;
35 $this->type = $type;
36 $this->tag = $tag;
37 $this->parameters = $parameters;
38 $this->hide = $hide;
39 }
40
41 public function getHash(): string
42 {
43 return hash("sha256", self::class);
44 }
45
46 public function getLabel(): string
47 {
48 return "Add style class";
49 }
50
51 public function isNotable(): bool
52 {
53 return true;
54 }
55
56 public function getPreconditions(Environment $environment): array
57 {
58 return [
60 ];
61 }
62
63 public function achieve(Environment $environment): Environment
64 {
65 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
66
67 $sql =
68 "SELECT obj_id" . PHP_EOL
69 . "FROM object_data" . PHP_EOL
70 . "WHERE type = 'sty'" . PHP_EOL
71 ;
72 $result = $db->query($sql);
73
74 while ($row = $db->fetchAssoc($result)) {
75 $sql =
76 "SELECT style_id, type, characteristic, hide" . PHP_EOL
77 . "FROM style_char" . PHP_EOL
78 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
79 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
80 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
81 ;
82 $res = $db->query($sql);
83
84 if (!$db->fetchAssoc($res)) {
85 $values = [
86 "style_id" => ["integer", $row["obj_id"]],
87 "type" => ["text", $this->type],
88 "characteristic" => ["text", $this->class],
89 "hide" => ["integer", $this->hide]
90 ];
91 $db->insert("style_char", $values);
92
93 foreach ($this->parameters as $k => $v) {
94 $spid = $db->nextId("style_parameter");
95 $values = [
96 "id" => ["integer", $spid],
97 "style_id" => ["integer", $row["obj_id"]],
98 "tag" => ["text", $this->tag],
99 "class" => ["text", $this->class],
100 "parameter" => ["text", $k],
101 "value" => ["text", $v],
102 "type" => ["text", $this->type]
103 ];
104 $db->insert("style_parameter", $values);
105 }
106 }
107 }
108
109 return $environment;
110 }
111
112 public function isApplicable(Environment $environment): bool
113 {
114 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
115
116 $sql =
117 "SELECT obj_id" . PHP_EOL
118 . "FROM object_data" . PHP_EOL
119 . "WHERE type = 'sty'" . PHP_EOL
120 ;
121
122 $result = $db->query($sql);
123
124 while ($row = $db->fetchAssoc($result)) {
125 $sql =
126 "SELECT style_id, type, characteristic, hide" . PHP_EOL
127 . "FROM style_char" . PHP_EOL
128 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
129 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
130 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL;
131 $res = $db->query($sql);
132
133 // return true if no entry exists in style_char for obj_id from object_data
134 if ($db->numRows($res) == 0) {
135 return true;
136 }
137 }
138
139 return false;
140 }
141}
__construct(string $class, string $type, string $tag, array $parameters=[], int $hide=0)
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
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...