ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSkillLevelDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected ilDBInterface $db;
28
30 {
31 global $DIC;
32
33 $this->tree_repo = $tree_repo;
34 $this->db = ($db)
35 ?: $DIC->database();
36 }
37
38 public function deleteLevelsOfSkill(int $skill_id): void
39 {
41
42 $ilDB->manipulate(
43 "DELETE FROM skl_level WHERE "
44 . " skill_id = " . $ilDB->quote($skill_id, "integer")
45 );
46 }
47
48 public function addLevel(int $skill_id, string $a_title, string $a_description, string $a_import_id = ""): void
49 {
51
52 $nr = $this->getMaxLevelNr($skill_id);
53 $nid = $ilDB->nextId("skl_level");
54 $ilDB->insert("skl_level", array(
55 "id" => array("integer", $nid),
56 "skill_id" => array("integer", $skill_id),
57 "nr" => array("integer", $nr + 1),
58 "title" => array("text", $a_title),
59 "description" => array("clob", $a_description),
60 "import_id" => array("text", $a_import_id),
61 "creation_date" => array("timestamp", ilUtil::now())
62 ));
63 }
64
65 protected function getMaxLevelNr(int $skill_id): int
66 {
68
69 $set = $ilDB->query(
70 "SELECT MAX(nr) mnr FROM skl_level WHERE " .
71 " skill_id = " . $ilDB->quote($skill_id, "integer")
72 );
73 $rec = $ilDB->fetchAssoc($set);
74 return (int) ($rec["mnr"] ?? 0);
75 }
76
80 public function getLevelData(int $skill_id, int $a_id = 0): array
81 {
83
84 $and = "";
85 if ($a_id > 0) {
86 $and = " AND id = " . $ilDB->quote($a_id, "integer");
87 }
88
89 $set = $ilDB->query(
90 "SELECT * FROM skl_level WHERE " .
91 " skill_id = " . $ilDB->quote($skill_id, "integer") .
92 $and .
93 " ORDER BY nr"
94 );
95 $levels = [];
96 while ($rec = $ilDB->fetchAssoc($set)) {
97 if ($a_id > 0) {
98 return $rec ?? [];
99 }
100 $levels[] = $rec;
101 }
102 return $levels;
103 }
104
105 protected function lookupLevelProperty(int $a_id, string $a_prop): ?string
106 {
108
109 $set = $ilDB->query(
110 "SELECT $a_prop FROM skl_level WHERE " .
111 " id = " . $ilDB->quote($a_id, "integer")
112 );
113 $rec = $ilDB->fetchAssoc($set);
114
115 return isset($rec[$a_prop]) ? (string) $rec[$a_prop] : null;
116 }
117
118 public function lookupLevelTitle(int $a_id): string
119 {
120 return $this->lookupLevelProperty($a_id, "title") ?? "";
121 }
122
123 public function lookupLevelDescription(int $a_id): string
124 {
125 return $this->lookupLevelProperty($a_id, "description") ?? "";
126 }
127
128 public function lookupLevelSkillId(int $a_id): int
129 {
130 return (int) ($this->lookupLevelProperty($a_id, "skill_id") ?? 0);
131 }
132
133 public function lookupLevelNumber(int $a_id): int
134 {
135 return (int) ($this->lookupLevelProperty($a_id, "nr") ?? 0);
136 }
137
138 protected function writeLevelProperty(int $a_id, string $a_prop, ?string $a_value, string $a_type): void
139 {
141
142 $ilDB->update("skl_level", array(
143 $a_prop => array($a_type, $a_value),
144 ), array(
145 "id" => array("integer", $a_id),
146 ));
147 }
148
149 public function writeLevelTitle(int $a_id, string $a_title): void
150 {
151 $this->writeLevelProperty($a_id, "title", $a_title, "text");
152 }
153
154 public function writeLevelDescription(int $a_id, string $a_description): void
155 {
156 $this->writeLevelProperty($a_id, "description", $a_description, "clob");
157 }
158
159 public function updateLevelOrder(array $order): void
160 {
162
163 $cnt = 1;
164 foreach ($order as $id => $o) {
165 $ilDB->manipulate(
166 "UPDATE skl_level SET " .
167 " nr = " . $ilDB->quote($cnt, "integer") .
168 " WHERE id = " . $ilDB->quote($id, "integer")
169 );
170 $cnt++;
171 }
172 }
173
174 public function deleteLevel(int $a_id): void
175 {
177
178 $ilDB->manipulate(
179 "DELETE FROM skl_level WHERE "
180 . " id = " . $ilDB->quote($a_id, "integer")
181 );
182 }
183
184 public function fixLevelNumbering(int $skill_id): void
185 {
187
188 $set = $ilDB->query(
189 "SELECT id, nr FROM skl_level WHERE " .
190 " skill_id = " . $ilDB->quote($skill_id, "integer") .
191 " ORDER BY nr ASC"
192 );
193 $cnt = 1;
194 while ($rec = $ilDB->fetchAssoc($set)) {
195 $ilDB->manipulate(
196 "UPDATE skl_level SET " .
197 " nr = " . $ilDB->quote($cnt, "integer") .
198 " WHERE id = " . $ilDB->quote($rec["id"], "integer")
199 );
200 $cnt++;
201 }
202 }
203
204 public function getSkillForLevelId(int $a_level_id): ?ilBasicSkill
205 {
207
208 $set = $ilDB->query(
209 "SELECT * FROM skl_level WHERE " .
210 " id = " . $ilDB->quote($a_level_id, "integer")
211 );
212 $skill = null;
213 if ($rec = $ilDB->fetchAssoc($set)) {
214 if ($this->tree_repo->isInAnyTree((int) $rec["skill_id"])) {
215 $skill = new ilBasicSkill((int) $rec["skill_id"]);
216 }
217 }
218 return $skill;
219 }
220}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Class ilSkillLevelDBRepository.
addLevel(int $skill_id, string $a_title, string $a_description, string $a_import_id="")
getLevelData(int $skill_id, int $a_id=0)
Returns multiple rows when $a_id is 0 else one or [].
writeLevelProperty(int $a_id, string $a_prop, ?string $a_value, string $a_type)
lookupLevelProperty(int $a_id, string $a_prop)
writeLevelDescription(int $a_id, string $a_description)
writeLevelTitle(int $a_id, string $a_title)
__construct(ilSkillTreeRepository $tree_repo, ?ilDBInterface $db=null)
static now()
Return current timestamp in Y-m-d H:i:s format.
Interface ilDBInterface.
Interface ilSkillLevelRepository.
Interface ilSkillTreeRepository.
global $DIC
Definition: shib_login.php:26