ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSkillResources.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
18{
22 protected $db;
23
27 protected $tree;
28
29 protected $base_skill_id; // base skill id
30 protected $tref_id; // template reference id (if no template involved: 0)
31
32 // The resources array has the following keys (int)
33 // first dimension is "level_id" (int): the skill level id
34 // second dimension is "rep_ref_id" (int): the ref id of the repository resource
35 //
36 // The values of the array are associatives arrays with the following key value pairs:
37 // level_id (int): the skill level id
38 // rep_ref_id (int): the ref id of the repository resource
39 // trigger: 1, if the resource triggers the skill level (0 otherwise)
40 // imparting: 1, if the resource imparts knowledge of the skill level (0 otherwise)
41 protected $resources = array();
42
49 public function __construct($a_skill_id = 0, $a_tref_id = 0)
50 {
51 global $DIC;
52
53 $this->db = $DIC->database();
54 $this->tree = $DIC->repositoryTree();
55 $this->setBaseSkillId($a_skill_id);
56 $this->setTemplateRefId($a_tref_id);
57
58 if ($a_skill_id > 0) {
59 $this->readResources();
60 }
61 }
62
68 public function setBaseSkillId($a_val)
69 {
70 $this->base_skill_id = (int) $a_val;
71 }
72
78 public function getBaseSkillId()
79 {
81 }
82
88 public function setTemplateRefId($a_val)
89 {
90 $this->tref_id = (int) $a_val;
91 }
92
98 public function getTemplateRefId()
99 {
100 return $this->tref_id;
101 }
102
109 public function readResources()
110 {
113
114 $set = $ilDB->query(
115 "SELECT * FROM skl_skill_resource " .
116 " WHERE base_skill_id = " . $ilDB->quote($this->getBaseSkillId(), "integer") .
117 " AND tref_id = " . $ilDB->quote($this->getTemplateRefId(), "integer")
118 );
119 while ($rec = $ilDB->fetchAssoc($set)) {
120 if ($tree->isInTree($rec["rep_ref_id"])) {
121 $this->resources[$rec["level_id"]][$rec["rep_ref_id"]] = array(
122 "level_id" => $rec["level_id"],
123 "rep_ref_id" => $rec["rep_ref_id"],
124 "trigger" => $rec["ltrigger"],
125 "imparting" => $rec["imparting"]
126 );
127 }
128 }
129 }
130
134 public function save()
135 {
137
138 $ilDB->manipulate(
139 "DELETE FROM skl_skill_resource WHERE " .
140 " base_skill_id = " . $ilDB->quote((int) $this->getBaseSkillId(), "integer") .
141 " AND tref_id = " . $ilDB->quote((int) $this->getTemplateRefId(), "integer")
142 );
143 foreach ($this->getResources() as $level_id => $l) {
144 foreach ($l as $ref_id => $r) {
145 if ($r["imparting"] || $r["trigger"]) {
146 $ilDB->manipulate("INSERT INTO skl_skill_resource " .
147 "(base_skill_id, tref_id, level_id, rep_ref_id, imparting, ltrigger) VALUES (" .
148 $ilDB->quote((int) $this->getBaseSkillId(), "integer") . "," .
149 $ilDB->quote((int) $this->getTemplateRefId(), "integer") . "," .
150 $ilDB->quote((int) $level_id, "integer") . "," .
151 $ilDB->quote((int) $ref_id, "integer") . "," .
152 $ilDB->quote((int) $r["imparting"], "integer") . "," .
153 $ilDB->quote((int) $r["trigger"], "integer") .
154 ")");
155 }
156 }
157 }
158 }
159
165 public function getResources()
166 {
167 return $this->resources;
168 }
169
176 public function getResourcesOfLevel($a_level_id)
177 {
178 $ret = (is_array($this->resources[$a_level_id]))
179 ? $this->resources[$a_level_id]
180 : array();
181
182 return $ret;
183 }
184
192 public function setResourceAsTrigger($a_level_id, $a_rep_ref_id, $a_trigger = true)
193 {
194 if (!is_array($this->resources[$a_level_id])) {
195 $this->resources[$a_level_id] = array();
196 }
197 if (!is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
198 $this->resources[$a_level_id][$a_rep_ref_id] = array();
199 }
200
201 $this->resources[$a_level_id][$a_rep_ref_id]["trigger"] = $a_trigger;
202 }
203
211 public function setResourceAsImparting($a_level_id, $a_rep_ref_id, $a_imparting = true)
212 {
213 if (!is_array($this->resources[$a_level_id])) {
214 $this->resources[$a_level_id] = array();
215 }
216 if (!is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
217 $this->resources[$a_level_id][$a_rep_ref_id] = array();
218 }
219
220 $this->resources[$a_level_id][$a_rep_ref_id]["imparting"] = $a_imparting;
221 }
222
229 public static function getUsageInfo($a_cskill_ids, &$a_usages)
230 {
232 $a_cskill_ids,
233 $a_usages,
235 "skl_skill_resource",
236 "rep_ref_id",
237 "base_skill_id"
238 );
239 }
240
247 public static function getTriggerLevelsForRefId($a_ref_id)
248 {
249 global $DIC;
250
251 $db = $DIC->database();
252
253 $set = $db->query("SELECT * FROM skl_skill_resource " .
254 " WHERE rep_ref_id = " . $db->quote($a_ref_id, "integer") .
255 " AND ltrigger = " . $db->quote(1, "integer"));
256
257 $skill_levels = array();
258 while ($rec = $db->fetchAssoc($set)) {
259 $skill_levels[] = array(
260 "base_skill_id" => $rec["base_skill_id"],
261 "tref_id" => $rec["tref_id"],
262 "level_id" => $rec["level_id"]
263 );
264 }
265 return $skill_levels;
266 }
267}
An exception for terminatinating execution or to throw for unit testing.
Manages resources for skills.
readResources()
Read resources.
getResources()
Get resources.
getResourcesOfLevel($a_level_id)
Get resoures for level id.
static getTriggerLevelsForRefId($a_ref_id)
Get levels for trigger per ref id.
setTemplateRefId($a_val)
Set template reference id.
setResourceAsTrigger($a_level_id, $a_rep_ref_id, $a_trigger=true)
Set resource as trigger.
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
__construct($a_skill_id=0, $a_tref_id=0)
Constructor.
getTemplateRefId()
Get template reference id.
setResourceAsImparting($a_level_id, $a_rep_ref_id, $a_imparting=true)
Set resource as imparting resource.
getBaseSkillId()
Get base skill id.
setBaseSkillId($a_val)
Set base skill id.
static getUsageInfoGeneric( $a_cskill_ids, &$a_usages, $a_usage_type, $a_table, $a_key_field, $a_skill_field="skill_id", $a_tref_field="tref_id")
Get standard usage query.
global $DIC
Definition: goto.php:24
Get info on usages of skills.
$ret
Definition: parser.php:6
global $ilDB