ILIAS  release_8 Revision v8.24
class.ilSkillResources.php
Go to the documentation of this file.
1<?php
2
33{
34 protected ilDBInterface $db;
35 protected ilTree $tree;
36 protected int $base_skill_id = 0;
37 protected int $tref_id = 0;
38
39 // The resources array has the following keys (int)
40 // first dimension is "level_id" (int): the skill level id
41 // second dimension is "rep_ref_id" (int): the ref id of the repository resource
42 //
43 // The values of the array are associatives arrays with the following key value pairs:
44 // level_id (int): the skill level id
45 // rep_ref_id (int): the ref id of the repository resource
46 // trigger: 1, if the resource triggers the skill level (0 otherwise)
47 // imparting: 1, if the resource imparts knowledge of the skill level (0 otherwise)
51 protected array $resources = [];
52
53 public function __construct(int $a_skill_id = 0, int $a_tref_id = 0)
54 {
55 global $DIC;
56
57 $this->db = $DIC->database();
58 $this->tree = $DIC->repositoryTree();
59 $this->setBaseSkillId($a_skill_id);
60 $this->setTemplateRefId($a_tref_id);
61
62 if ($a_skill_id > 0) {
63 $this->readResources();
64 }
65 }
66
67 public function setBaseSkillId(int $a_val): void
68 {
69 $this->base_skill_id = $a_val;
70 }
71
72 public function getBaseSkillId(): int
73 {
75 }
76
77 public function setTemplateRefId(int $a_val): void
78 {
79 $this->tref_id = $a_val;
80 }
81
82 public function getTemplateRefId(): int
83 {
84 return $this->tref_id;
85 }
86
87 public function readResources(): void
88 {
91
92 $set = $ilDB->query(
93 "SELECT * FROM skl_skill_resource " .
94 " WHERE base_skill_id = " . $ilDB->quote($this->getBaseSkillId(), "integer") .
95 " AND tref_id = " . $ilDB->quote($this->getTemplateRefId(), "integer")
96 );
97 while ($rec = $ilDB->fetchAssoc($set)) {
98 if ($tree->isInTree($rec["rep_ref_id"])) {
99 $this->resources[(int) $rec["level_id"]][(int) $rec["rep_ref_id"]] = array(
100 "level_id" => (int) $rec["level_id"],
101 "rep_ref_id" => (int) $rec["rep_ref_id"],
102 "trigger" => (int) $rec["ltrigger"],
103 "imparting" => (int) $rec["imparting"]
104 );
105 }
106 }
107 }
108
109 public function save(): void
110 {
112
113 $ilDB->manipulate(
114 "DELETE FROM skl_skill_resource WHERE " .
115 " base_skill_id = " . $ilDB->quote($this->getBaseSkillId(), "integer") .
116 " AND tref_id = " . $ilDB->quote($this->getTemplateRefId(), "integer")
117 );
118 foreach ($this->getResources() as $level_id => $l) {
119 foreach ($l as $ref_id => $r) {
120 if ($r["imparting"] || $r["trigger"]) {
121 $ilDB->manipulate("INSERT INTO skl_skill_resource " .
122 "(base_skill_id, tref_id, level_id, rep_ref_id, imparting, ltrigger) VALUES (" .
123 $ilDB->quote($this->getBaseSkillId(), "integer") . "," .
124 $ilDB->quote($this->getTemplateRefId(), "integer") . "," .
125 $ilDB->quote($level_id, "integer") . "," .
126 $ilDB->quote($ref_id, "integer") . "," .
127 $ilDB->quote((int) $r["imparting"], "integer") . "," .
128 $ilDB->quote((int) $r["trigger"], "integer") .
129 ")");
130 }
131 }
132 }
133 }
134
138 public function getResources(): array
139 {
140 return $this->resources;
141 }
142
146 public function getResourcesOfLevel(int $a_level_id): array
147 {
148 $ret = (isset($this->resources[$a_level_id]) && is_array($this->resources[$a_level_id]))
149 ? $this->resources[$a_level_id]
150 : [];
151
152 return $ret;
153 }
154
155 public function setResourceAsTrigger(int $a_level_id, int $a_rep_ref_id, bool $a_trigger = true): void
156 {
157 if (!isset($this->resources[$a_level_id]) || !is_array($this->resources[$a_level_id])) {
158 $this->resources[$a_level_id] = [];
159 }
160 if (!isset($this->resources[$a_level_id][$a_rep_ref_id]) || !is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
161 $this->resources[$a_level_id][$a_rep_ref_id] = [];
162 }
163
164 $this->resources[$a_level_id][$a_rep_ref_id]["trigger"] = $a_trigger;
165 }
166
167 public function setResourceAsImparting(int $a_level_id, int $a_rep_ref_id, bool $a_imparting = true): void
168 {
169 if (!isset($this->resources[$a_level_id]) || !is_array($this->resources[$a_level_id])) {
170 $this->resources[$a_level_id] = [];
171 }
172 if (!isset($this->resources[$a_level_id][$a_rep_ref_id]) || !is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
173 $this->resources[$a_level_id][$a_rep_ref_id] = [];
174 }
175
176 $this->resources[$a_level_id][$a_rep_ref_id]["imparting"] = $a_imparting;
177 }
178
184 public static function getUsageInfo(array $a_cskill_ids): array
185 {
187 $a_cskill_ids,
189 "skl_skill_resource",
190 "rep_ref_id",
191 "base_skill_id"
192 );
193 }
194
198 public static function getTriggerLevelsForRefId(int $a_ref_id): array
199 {
200 global $DIC;
201
202 $db = $DIC->database();
203
204 $set = $db->query("SELECT * FROM skl_skill_resource " .
205 " WHERE rep_ref_id = " . $db->quote($a_ref_id, "integer") .
206 " AND ltrigger = " . $db->quote(1, "integer"));
207
208 $skill_levels = [];
209 while ($rec = $db->fetchAssoc($set)) {
210 $skill_levels[] = array(
211 "base_skill_id" => (int) $rec["base_skill_id"],
212 "tref_id" => (int) $rec["tref_id"],
213 "level_id" => (int) $rec["level_id"]
214 );
215 }
216 return $skill_levels;
217 }
218}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getResourcesOfLevel(int $a_level_id)
setResourceAsImparting(int $a_level_id, int $a_rep_ref_id, bool $a_imparting=true)
static getUsageInfo(array $a_cskill_ids)
setResourceAsTrigger(int $a_level_id, int $a_rep_ref_id, bool $a_trigger=true)
__construct(int $a_skill_id=0, int $a_tref_id=0)
static getTriggerLevelsForRefId(int $a_ref_id)
static getUsageInfoGeneric(array $a_cskill_ids, string $a_usage_type, string $a_table, string $a_key_field, string $a_skill_field="skill_id", string $a_tref_field="tref_id")
Get standard usage query.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isInTree(?int $a_node_id)
get all information of a node.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
Get info on usages of skills.
$ref_id
Definition: ltiauth.php:67