ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilStyleClassCopiedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
23 
24 class ilStyleClassCopiedObjective implements Setup\Objective
25 {
26  protected string $orig_class;
27  protected string $class;
28  protected string $type;
29  protected string $tag;
30  protected int $hide;
31 
32  public function __construct(string $orig_class, string $class, string $type, string $tag, int $hide = 0)
33  {
34  $this->orig_class = $orig_class;
35  $this->class = $class;
36  $this->type = $type;
37  $this->tag = $tag;
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 "Copy 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 
73  $result = $db->query($sql);
74 
75  while ($row = $db->fetchAssoc($result)) {
76  $sql =
77  "SELECT style_id, type, characteristic, hide" . PHP_EOL
78  . "FROM style_char" . PHP_EOL
79  . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
80  . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
81  . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
82  ;
83  $res = $db->query($sql);
84 
85  if (!$db->fetchAssoc($res)) {
86  $values = [
87  "style_id" => ["integer", $row["obj_id"]],
88  "type" => ["text", $this->type],
89  "characteristic" => ["text", $this->class],
90  "hide" => ["integer", $this->hide]
91  ];
92  $db->insert("style_char", $values);
93 
94  $sql =
95  "SELECT id, style_id, tag, class, parameter, value, type, mq_id, custom" . PHP_EOL
96  . "FROM style_parameter" . PHP_EOL
97  . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
98  . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
99  . "AND class = " . $db->quote($this->orig_class, "text") . PHP_EOL
100  . "AND tag = " . $db->quote($this->tag, "text") . PHP_EOL
101  ;
102 
103  $res = $db->query($sql);
104 
105  while ($row_2 = $db->fetchAssoc($res)) {
106  $spid = $db->nextId("style_parameter");
107  $values = [
108  "id" => ["integer", $spid],
109  "style_id" => ["integer", $row["obj_id"]],
110  "tag" => ["text", $this->tag],
111  "class" => ["text", $this->class],
112  "parameter" => ["text", $row_2["parameter"]],
113  "value" => ["text", $row_2["value"]],
114  "type" => ["text", $row_2["type"]]
115  ];
116  $db->insert("style_parameter", $values);
117  }
118  }
119  }
120 
121  return $environment;
122  }
123 
124  public function isApplicable(Environment $environment): bool
125  {
126  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
127 
128  $sql =
129  "SELECT obj_id" . PHP_EOL
130  . "FROM object_data" . PHP_EOL
131  . "WHERE type = 'sty'" . PHP_EOL
132  ;
133  $result = $db->query($sql);
134 
135  if ($db->numRows($result) == 0) {
136  return false;
137  }
138 
139  while ($row = $db->fetchAssoc($result)) {
140  $sql =
141  "SELECT style_id, type, characteristic, hide" . PHP_EOL
142  . "FROM style_char" . PHP_EOL
143  . "WHERE style_id = " . $db->quote($row["obj_id"], "integer") . PHP_EOL
144  . "AND characteristic = " . $db->quote($this->class, "text") . PHP_EOL
145  . "AND type = " . $db->quote($this->type, "text") . PHP_EOL
146  ;
147 
148  $res = $db->query($sql);
149 
150  if ($db->numRows($res)) {
151  return false;
152  }
153  }
154  return true;
155  }
156 }
__construct(string $orig_class, string $class, string $type, string $tag, int $hide=0)
$res
Definition: ltiservices.php:66
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