ILIAS  release_8 Revision v8.24
class.ilStyleClassAddedObjective.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 $class;
13 protected string $type;
14 protected string $tag;
15 protected array $parameters;
16 protected int $hide;
17
18 public function __construct(string $class, string $type, string $tag, array $parameters = [], int $hide = 0)
19 {
20 $this->class = $class;
21 $this->type = $type;
22 $this->tag = $tag;
23 $this->parameters = $parameters;
24 $this->hide = $hide;
25 }
26
27 public function getHash(): string
28 {
29 return hash("sha256", self::class);
30 }
31
32 public function getLabel(): string
33 {
34 return "Add style class";
35 }
36
37 public function isNotable(): bool
38 {
39 return true;
40 }
41
42 public function getPreconditions(Environment $environment): array
43 {
44 return [
46 ];
47 }
48
49 public function achieve(Environment $environment): Environment
50 {
51 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
52
53 $sql =
54 "SELECT obj_id" . PHP_EOL
55 . "FROM object_data" . PHP_EOL
56 . "WHERE type = 'sty'" . PHP_EOL
57 ;
58 $result = $db->query($sql);
59
60 while ($row = $db->fetchAssoc($result)) {
61 $sql =
62 "SELECT style_id, type, characteristic, hide" . PHP_EOL
63 . "FROM style_char" . PHP_EOL
64 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
65 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
66 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
67 ;
68 $res = $db->query($sql);
69
70 if (!$db->fetchAssoc($res)) {
71 $values = [
72 "style_id" => ["integer", $row["obj_id"]],
73 "type" => ["text", $this->type],
74 "characteristic" => ["text", $this->class],
75 "hide" => ["integer", $this->hide]
76 ];
77 $db->insert("style_char", $values);
78
79 foreach ($this->parameters as $k => $v) {
80 $spid = $db->nextId("style_parameter");
81 $values = [
82 "id" => ["integer", $spid],
83 "style_id" => ["integer", $row["obj_id"]],
84 "tag" => ["text", $this->tag],
85 "class" => ["text", $this->class],
86 "parameter" => ["text", $k],
87 "value" => ["text", $v],
88 "type" => ["text", $this->type]
89 ];
90 $db->insert("style_parameter", $values);
91 }
92 }
93 }
94
95 return $environment;
96 }
97
98 public function isApplicable(Environment $environment): bool
99 {
100 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
101
102 $sql =
103 "SELECT obj_id" . PHP_EOL
104 . "FROM object_data" . PHP_EOL
105 . "WHERE type = 'sty'" . PHP_EOL
106 ;
107
108 $result = $db->query($sql);
109
110 while ($row = $db->fetchAssoc($result)) {
111 $sql =
112 "SELECT style_id, type, characteristic, hide" . PHP_EOL
113 . "FROM style_char" . PHP_EOL
114 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
115 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
116 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL;
117 $res = $db->query($sql);
118
119 // return true if no entry exists in style_char for obj_id from object_data
120 if ($db->numRows($res) == 0) {
121 return true;
122 }
123 }
124
125 return false;
126 }
127}
__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...