ILIAS  release_8 Revision v8.24
class.ilStyleClassCopiedObjective.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 $orig_class;
13 protected string $class;
14 protected string $type;
15 protected string $tag;
16 protected int $hide;
17
18 public function __construct(string $orig_class, string $class, string $type, string $tag, int $hide = 0)
19 {
20 $this->orig_class = $orig_class;
21 $this->class = $class;
22 $this->type = $type;
23 $this->tag = $tag;
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 "Copy 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
59 $result = $db->query($sql);
60
61 while ($row = $db->fetchAssoc($result)) {
62 $sql =
63 "SELECT style_id, type, characteristic, hide" . PHP_EOL
64 . "FROM style_char" . PHP_EOL
65 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
66 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
67 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
68 ;
69 $res = $db->query($sql);
70
71 if (!$db->fetchAssoc($res)) {
72 $values = [
73 "style_id" => ["integer", $row["obj_id"]],
74 "type" => ["text", $this->type],
75 "characteristic" => ["text", $this->class],
76 "hide" => ["integer", $this->hide]
77 ];
78 $db->insert("style_char", $values);
79
80 $sql =
81 "SELECT id, style_id, tag, class, parameter, value, type, mq_id, custom" . PHP_EOL
82 . "FROM style_parameter" . PHP_EOL
83 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
84 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
85 . "AND class = " . $db->quote($this->orig_class, "text") . PHP_EOL
86 . "AND tag = " . $db->quote($this->tag, "text") . PHP_EOL
87 ;
88
89 $res = $db->query($sql);
90
91 while ($row_2 = $db->fetchAssoc($res)) {
92 $spid = $db->nextId("style_parameter");
93 $values = [
94 "id" => ["integer", $spid],
95 "style_id" => ["integer", $row["obj_id"]],
96 "tag" => ["text", $this->tag],
97 "class" => ["text", $this->class],
98 "parameter" => ["text", $row_2["parameter"]],
99 "value" => ["text", $row_2["value"]],
100 "type" => ["text", $row_2["type"]]
101 ];
102 $db->insert("style_parameter", $values);
103 }
104 }
105 }
106
107 return $environment;
108 }
109
110 public function isApplicable(Environment $environment): bool
111 {
112 $db = $environment->getResource(Environment::RESOURCE_DATABASE);
113
114 $sql =
115 "SELECT obj_id" . PHP_EOL
116 . "FROM object_data" . PHP_EOL
117 . "WHERE type = 'sty'" . PHP_EOL
118 ;
119 $result = $db->query($sql);
120
121 if ($db->numRows($result) == 0) {
122 return false;
123 }
124
125 while ($row = $db->fetchAssoc($result)) {
126 $sql =
127 "SELECT style_id, type, characteristic, hide" . PHP_EOL
128 . "FROM style_char" . PHP_EOL
129 . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
130 . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
131 . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
132 ;
133
134 $res = $db->query($sql);
135
136 if ($db->numRows($res)) {
137 return false;
138 }
139 }
140 return true;
141 }
142}
__construct(string $orig_class, string $class, string $type, string $tag, 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...