ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBasicSkillLevelDBRepository.php
Go to the documentation of this file.
1<?php
2
7{
11 protected $db;
12
13 public function __construct(ilDBInterface $db = null)
14 {
15 global $DIC;
16
17 $this->db = ($db)
18 ? $db
19 : $DIC->database();
20 }
21
25 public function deleteLevelsOfSkill(int $skill_id)
26 {
28
29 $ilDB->manipulate("DELETE FROM skl_level WHERE "
30 . " skill_id = " . $ilDB->quote($skill_id, "integer")
31 );
32 }
33
37 public function addLevel(int $skill_id, string $a_title, string $a_description, string $a_import_id = "")
38 {
40
41 $nr = $this->getMaxLevelNr($skill_id);
42 $nid = $ilDB->nextId("skl_level");
43 $ilDB->insert("skl_level", array(
44 "id" => array("integer", $nid),
45 "skill_id" => array("integer", $skill_id),
46 "nr" => array("integer", $nr + 1),
47 "title" => array("text", $a_title),
48 "description" => array("clob", $a_description),
49 "import_id" => array("text", $a_import_id),
50 "creation_date" => array("timestamp", ilUtil::now())
51 ));
52
53 }
54
59 protected function getMaxLevelNr(int $skill_id) : int
60 {
62
63 $set = $ilDB->query("SELECT MAX(nr) mnr FROM skl_level WHERE " .
64 " skill_id = " . $ilDB->quote($skill_id, "integer")
65 );
66 $rec = $ilDB->fetchAssoc($set);
67 return (int) $rec["mnr"];
68 }
69
73 public function getLevelData(int $skill_id, int $a_id = 0) : array
74 {
76
77 if ($a_id > 0) {
78 $and = " AND id = " . $ilDB->quote($a_id, "integer");
79 }
80
81 $set = $ilDB->query("SELECT * FROM skl_level WHERE " .
82 " skill_id = " . $ilDB->quote($skill_id, "integer") .
83 $and .
84 " ORDER BY nr"
85 );
86 $levels = array();
87 while ($rec = $ilDB->fetchAssoc($set)) {
88 if ($a_id > 0) {
89 return $rec;
90 }
91 $levels[] = $rec;
92 }
93 return $levels;
94 }
95
102 protected function lookupLevelProperty(int $a_id, string $a_prop)
103 {
105
106 $set = $ilDB->query("SELECT $a_prop FROM skl_level WHERE " .
107 " id = " . $ilDB->quote($a_id, "integer")
108 );
109 $rec = $ilDB->fetchAssoc($set);
110 return $rec[$a_prop];
111 }
112
116 public function lookupLevelTitle(int $a_id) : string
117 {
118 return $this->lookupLevelProperty($a_id, "title");
119 }
120
124 public function lookupLevelDescription(int $a_id) : string
125 {
126 return $this->lookupLevelProperty($a_id, "description");
127 }
128
132 public function lookupLevelSkillId(int $a_id) : int
133 {
134 return $this->lookupLevelProperty($a_id, "skill_id");
135 }
136
144 protected function writeLevelProperty(int $a_id, string $a_prop, $a_value, string $a_type)
145 {
147
148 $ilDB->update("skl_level", array(
149 $a_prop => array($a_type, $a_value),
150 ), array(
151 "id" => array("integer", $a_id),
152 ));
153 }
154
158 public function writeLevelTitle(int $a_id, string $a_title)
159 {
160 $this->writeLevelProperty($a_id, "title", $a_title, "text");
161 }
162
166 public function writeLevelDescription(int $a_id, string $a_description)
167 {
168 $this->writeLevelProperty($a_id, "description", $a_description, "clob");
169 }
170
174 public function updateLevelOrder(array $order)
175 {
177
178 $cnt = 1;
179 foreach ($order as $id => $o) {
180 $ilDB->manipulate("UPDATE skl_level SET " .
181 " nr = " . $ilDB->quote($cnt, "integer") .
182 " WHERE id = " . $ilDB->quote($id, "integer")
183 );
184 $cnt++;
185 }
186 }
187
191 public function deleteLevel(int $a_id)
192 {
194
195 $ilDB->manipulate("DELETE FROM skl_level WHERE "
196 . " id = " . $ilDB->quote($a_id, "integer")
197 );
198
199 }
200
204 public function fixLevelNumbering(int $skill_id)
205 {
207
208 $set = $ilDB->query("SELECT id, nr FROM skl_level WHERE " .
209 " skill_id = " . $ilDB->quote($skill_id, "integer") .
210 " ORDER BY nr ASC"
211 );
212 $cnt = 1;
213 while ($rec = $ilDB->fetchAssoc($set)) {
214 $ilDB->manipulate("UPDATE skl_level SET " .
215 " nr = " . $ilDB->quote($cnt, "integer") .
216 " WHERE id = " . $ilDB->quote($rec["id"], "integer")
217 );
218 $cnt++;
219 }
220 }
221
225 public function getSkillForLevelId(int $a_level_id)
226 {
228
229 $set = $ilDB->query("SELECT * FROM skl_level WHERE " .
230 " id = " . $ilDB->quote($a_level_id, "integer")
231 );
232 $skill = null;
233 if ($rec = $ilDB->fetchAssoc($set)) {
234 if (ilSkillTreeNode::isInTree($rec["skill_id"])) {
235 $skill = new ilBasicSkill($rec["skill_id"]);
236 }
237 }
238 return $skill;
239 }
240}
An exception for terminatinating execution or to throw for unit testing.
Class ilBasicSkillLevelDBRepository.
getMaxLevelNr(int $skill_id)
Get maximum level nr.
lookupLevelProperty(int $a_id, string $a_prop)
Lookup level property.
writeLevelProperty(int $a_id, string $a_prop, $a_value, string $a_type)
Write level property.
getLevelData(int $skill_id, int $a_id=0)
@inheritDoc
addLevel(int $skill_id, string $a_title, string $a_description, string $a_import_id="")
@inheritDoc
writeLevelDescription(int $a_id, string $a_description)
@inheritDoc
writeLevelTitle(int $a_id, string $a_title)
@inheritDoc
static isInTree($a_id)
Is id in tree?
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: goto.php:24
Interface ilBasicSkillLevelRepository.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $ilDB