ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSkillResources.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Skill/interfaces/interface.ilSkillUsageInfo.php");
6 
22 {
26  protected $db;
27 
31  protected $tree;
32 
33  protected $base_skill_id; // base skill id
34  protected $tref_id; // template reference id (if no template involved: 0)
35 
36  // The resources array has the following keys (int)
37  // first dimension is "level_id" (int): the skill level id
38  // second dimension is "rep_ref_id" (int): the ref id of the repository resource
39  //
40  // The values of the array are associatives arrays with the following key value pairs:
41  // level_id (int): the skill level id
42  // rep_ref_id (int): the ref id of the repository resource
43  // trigger: 1, if the resource triggers the skill level (0 otherwise)
44  // imparting: 1, if the resource imparts knowledge of the skill level (0 otherwise)
45  protected $resources = array();
46 
53  public function __construct($a_skill_id = 0, $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 
72  public function setBaseSkillId($a_val)
73  {
74  $this->base_skill_id = (int) $a_val;
75  }
76 
82  public function getBaseSkillId()
83  {
84  return $this->base_skill_id;
85  }
86 
92  public function setTemplateRefId($a_val)
93  {
94  $this->tref_id = (int) $a_val;
95  }
96 
102  public function getTemplateRefId()
103  {
104  return $this->tref_id;
105  }
106 
113  public function readResources()
114  {
115  $ilDB = $this->db;
116  $tree = $this->tree;
117 
118  $set = $ilDB->query(
119  "SELECT * FROM skl_skill_resource " .
120  " WHERE base_skill_id = " . $ilDB->quote($this->getBaseSkillId(), "integer") .
121  " AND tref_id = " . $ilDB->quote($this->getTemplateRefId(), "integer")
122  );
123  while ($rec = $ilDB->fetchAssoc($set)) {
124  if ($tree->isInTree($rec["rep_ref_id"])) {
125  $this->resources[$rec["level_id"]][$rec["rep_ref_id"]] = array(
126  "level_id" => $rec["level_id"],
127  "rep_ref_id" => $rec["rep_ref_id"],
128  "trigger" => $rec["ltrigger"],
129  "imparting" => $rec["imparting"]
130  );
131  }
132  }
133  }
134 
138  public function save()
139  {
140  $ilDB = $this->db;
141 
142  $ilDB->manipulate(
143  "DELETE FROM skl_skill_resource WHERE " .
144  " base_skill_id = " . $ilDB->quote((int) $this->getBaseSkillId(), "integer") .
145  " AND tref_id = " . $ilDB->quote((int) $this->getTemplateRefId(), "integer")
146  );
147  foreach ($this->getResources() as $level_id => $l) {
148  foreach ($l as $ref_id => $r) {
149  if ($r["imparting"] || $r["trigger"]) {
150  $ilDB->manipulate("INSERT INTO skl_skill_resource " .
151  "(base_skill_id, tref_id, level_id, rep_ref_id, imparting, ltrigger) VALUES (" .
152  $ilDB->quote((int) $this->getBaseSkillId(), "integer") . "," .
153  $ilDB->quote((int) $this->getTemplateRefId(), "integer") . "," .
154  $ilDB->quote((int) $level_id, "integer") . "," .
155  $ilDB->quote((int) $ref_id, "integer") . "," .
156  $ilDB->quote((int) $r["imparting"], "integer") . "," .
157  $ilDB->quote((int) $r["trigger"], "integer") .
158  ")");
159  }
160  }
161  }
162  }
163 
169  public function getResources()
170  {
171  return $this->resources;
172  }
173 
180  public function getResourcesOfLevel($a_level_id)
181  {
182  $ret = (is_array($this->resources[$a_level_id]))
183  ? $this->resources[$a_level_id]
184  : array();
185 
186  return $ret;
187  }
188 
196  public function setResourceAsTrigger($a_level_id, $a_rep_ref_id, $a_trigger = true)
197  {
198  if (!is_array($this->resources[$a_level_id])) {
199  $this->resources[$a_level_id] = array();
200  }
201  if (!is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
202  $this->resources[$a_level_id][$a_rep_ref_id] = array();
203  }
204 
205  $this->resources[$a_level_id][$a_rep_ref_id]["trigger"] = $a_trigger;
206  }
207 
215  public function setResourceAsImparting($a_level_id, $a_rep_ref_id, $a_imparting = true)
216  {
217  if (!is_array($this->resources[$a_level_id])) {
218  $this->resources[$a_level_id] = array();
219  }
220  if (!is_array($this->resources[$a_level_id][$a_rep_ref_id])) {
221  $this->resources[$a_level_id][$a_rep_ref_id] = array();
222  }
223 
224  $this->resources[$a_level_id][$a_rep_ref_id]["imparting"] = $a_imparting;
225  }
226 
233  public static function getUsageInfo($a_cskill_ids, &$a_usages)
234  {
235  global $DIC;
236 
237  $ilDB = $DIC->database();
238 
239  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
241  $a_cskill_ids,
242  $a_usages,
244  "skl_skill_resource",
245  "rep_ref_id",
246  "base_skill_id"
247  );
248  }
249 
256  public static function getTriggerLevelsForRefId($a_ref_id)
257  {
258  global $DIC;
259 
260  $db = $DIC->database();
261 
262  $set = $db->query("SELECT * FROM skl_skill_resource " .
263  " WHERE rep_ref_id = " . $db->quote($a_ref_id, "integer") .
264  " AND ltrigger = " . $db->quote(1, "integer"));
265 
266  $skill_levels = array();
267  while ($rec = $db->fetchAssoc($set)) {
268  $skill_levels[] = array(
269  "base_skill_id" => $rec["base_skill_id"],
270  "tref_id" => $rec["tref_id"],
271  "level_id" => $rec["level_id"]
272  );
273  }
274  return $skill_levels;
275  }
276 }
Get info on usages of skills.
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.
global $DIC
Definition: saml.php:7
static getUsageInfo($a_cskill_ids, &$a_usages)
Get usage info.
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.
setResourceAsTrigger($a_level_id, $a_rep_ref_id, $a_trigger=true)
Set resource as trigger.
readResources()
Read resources.
$r
Definition: example_031.php:79
Manages resources for skills.
setTemplateRefId($a_val)
Set template reference id.
getResources()
Get resources.
global $l
Definition: afr.php:30
global $ilDB
$ret
Definition: parser.php:6
save()
Save resources.
getResourcesOfLevel($a_level_id)
Get resoures for level id.
__construct($a_skill_id=0, $a_tref_id=0)
Constructor.
static getTriggerLevelsForRefId($a_ref_id)
Get levels for trigger per ref id.