ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
23  protected $base_skill_id; // base skill id
24  protected $tref_id; // template reference id (if no template involved: 0)
25 
26  // The resources array has the following keys (int)
27  // first dimension is "level_id" (int): the skill level id
28  // second dimension is "rep_ref_id" (int): the ref id of the repository resource
29  //
30  // The values of the array are associatives arrays with the following key value pairs:
31  // level_id (int): the skill level id
32  // rep_ref_id (int): the ref id of the repository resource
33  // trigger: 1, if the resource triggers the skill level (0 otherwise)
34  // imparting: 1, if the resource imparts knowledge of the skill level (0 otherwise)
35  protected $resources = array();
36 
43  function __construct($a_skill_id = 0, $a_tref_id = 0)
44  {
45  $this->setBaseSkillId($a_skill_id);
46  $this->setTemplateRefId($a_tref_id);
47 
48  if ($a_skill_id > 0)
49  {
50  $this->readResources();
51  }
52  }
53 
59  function setBaseSkillId($a_val)
60  {
61  $this->base_skill_id = (int) $a_val;
62  }
63 
69  function getBaseSkillId()
70  {
71  return $this->base_skill_id;
72  }
73 
79  function setTemplateRefId($a_val)
80  {
81  $this->tref_id = (int) $a_val;
82  }
83 
89  function getTemplateRefId()
90  {
91  return $this->tref_id;
92  }
93 
100  function readResources()
101  {
102  global $ilDB, $tree;
103 
104  $set = $ilDB->query("SELECT * FROM skl_skill_resource ".
105  " WHERE base_skill_id = ".$ilDB->quote($this->getBaseSkillId(), "integer").
106  " AND tref_id = ".$ilDB->quote($this->getTemplateRefId(), "integer")
107  );
108  while ($rec = $ilDB->fetchAssoc($set))
109  {
110  if ($tree->isInTree($rec["rep_ref_id"]))
111  {
112  $this->resources[$rec["level_id"]][$rec["rep_ref_id"]] = array(
113  "level_id" => $rec["level_id"],
114  "rep_ref_id" => $rec["rep_ref_id"],
115  "trigger" => $rec["ltrigger"],
116  "imparting" => $rec["imparting"]
117  );
118  }
119  }
120  }
121 
125  function save()
126  {
127  global $ilDB;
128 
129  $ilDB->manipulate("DELETE FROM skl_skill_resource WHERE ".
130  " base_skill_id = ".$ilDB->quote((int) $this->getBaseSkillId(), "integer").
131  " AND tref_id = ".$ilDB->quote((int) $this->getTemplateRefId(), "integer")
132  );
133  foreach ($this->getResources() as $level_id => $l)
134  {
135  foreach ($l as $ref_id => $r)
136  {
137  if ($r["imparting"] || $r["trigger"])
138  {
139  $ilDB->manipulate("INSERT INTO skl_skill_resource ".
140  "(base_skill_id, tref_id, level_id, rep_ref_id, imparting, ltrigger) VALUES (".
141  $ilDB->quote((int) $this->getBaseSkillId(), "integer").",".
142  $ilDB->quote((int) $this->getTemplateRefId(), "integer").",".
143  $ilDB->quote((int) $level_id, "integer").",".
144  $ilDB->quote((int) $ref_id, "integer").",".
145  $ilDB->quote((int) $r["imparting"], "integer").",".
146  $ilDB->quote((int) $r["trigger"], "integer").
147  ")");
148  }
149  }
150  }
151  }
152 
158  function getResources()
159  {
160  return $this->resources;
161  }
162 
169  function getResourcesOfLevel($a_level_id)
170  {
171  $ret = (is_array($this->resources[$a_level_id]))
172  ? $this->resources[$a_level_id]
173  : array();
174 
175  return $ret;
176  }
177 
185  function setResourceAsTrigger($a_level_id, $a_rep_ref_id, $a_trigger = true)
186  {
187  if (!is_array($this->resources[$a_level_id]))
188  {
189  $this->resources[$a_level_id] = array();
190  }
191  if (!is_array($this->resources[$a_level_id][$a_rep_ref_id]))
192  {
193  $this->resources[$a_level_id][$a_rep_ref_id] = array();
194  }
195 
196  $this->resources[$a_level_id][$a_rep_ref_id]["trigger"] = $a_trigger;
197  }
198 
206  function setResourceAsImparting($a_level_id, $a_rep_ref_id, $a_imparting = true)
207  {
208  if (!is_array($this->resources[$a_level_id]))
209  {
210  $this->resources[$a_level_id] = array();
211  }
212  if (!is_array($this->resources[$a_level_id][$a_rep_ref_id]))
213  {
214  $this->resources[$a_level_id][$a_rep_ref_id] = array();
215  }
216 
217  $this->resources[$a_level_id][$a_rep_ref_id]["imparting"] = $a_imparting;
218  }
219 
226  static public function getUsageInfo($a_cskill_ids, &$a_usages)
227  {
228  global $ilDB;
229 
230  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
232  "skl_skill_resource", "rep_ref_id", "base_skill_id");
233  }
234 
235 }
236 
237 ?>