ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilContainerMemberSkills.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
11 {
12 
16  protected $db;
17 
21  protected $skills = array();
22 
26  protected $obj_id;
27 
31  protected $user_id;
32 
36  protected $skill_levels = array();
37 
41  protected $published = false;
42 
48  public function __construct($a_obj_id, $a_user_id)
49  {
50  global $DIC;
51 
52  $this->db = $DIC->database();
53 
54  $this->setObjId($a_obj_id);
55  $this->setUserId($a_user_id);
56  if ($a_obj_id > 0 && $a_user_id > 0) {
57  $this->read();
58  }
59  }
60 
66  public function setObjId($a_val)
67  {
68  $this->obj_id = $a_val;
69  }
70 
76  public function getObjId()
77  {
78  return $this->obj_id;
79  }
80 
86  public function setUserId($a_val)
87  {
88  $this->user_id = $a_val;
89  }
90 
96  public function getUserId()
97  {
98  return $this->user_id;
99  }
100 
104  public function read()
105  {
106  $db = $this->db;
107 
108  $set = $db->query(
109  "SELECT * FROM cont_member_skills " .
110  " WHERE obj_id = " . $db->quote($this->getObjId(), "integer") .
111  " AND user_id = " . $db->quote($this->getUserId(), "integer")
112  );
113  $this->skill_levels = array();
114  while ($rec = $this->db->fetchAssoc($set)) {
115  $this->skill_levels[$rec["skill_id"] . ":" . $rec["tref_id"]] = $rec["level_id"];
116  $this->published = $rec["published"]; // this is a little weak, but the value should be the same for all save skills
117  }
118  }
119 
125  public function getSkillLevels()
126  {
127  return $this->skill_levels;
128  }
129 
135  public function getOrderedSkillLevels()
136  {
137  $skill_levels = array_map(function ($a, $k) {
138  $s = explode(":", $k);
139  return array("level_id" => $a, "skill_id" => $s[0], "tref_id" => $s[1]);
140  }, $this->getSkillLevels(), array_keys($this->getSkillLevels()));
141 
142  include_once("./Services/Skill/classes/class.ilVirtualSkillTree.php");
143  $vtree = new ilVirtualSkillTree();
144  return $vtree->getOrderedNodeset($skill_levels, "skill_id", "tref_id");
145  }
146 
147 
153  public function getPublished()
154  {
155  return $this->published;
156  }
157 
163  public function saveLevelForSkills($a_level_data)
164  {
165  $db = $this->db;
166 
167  $this->delete();
168  foreach ($a_level_data as $k => $v) {
169  $sk = explode(":", $k);
170  $db->manipulate("INSERT INTO cont_member_skills " .
171  "(obj_id, user_id, skill_id, tref_id, level_id, published) VALUES (" .
172  $db->quote($this->getObjId(), "integer") . "," .
173  $db->quote($this->getUserId(), "integer") . "," .
174  $db->quote($sk[0], "integer") . "," .
175  $db->quote($sk[1], "integer") . "," .
176  $db->quote($v, "integer") . "," .
177  $db->quote(0, "integer") .
178  ")");
179  }
180 
181  $this->skill_levels = $a_level_data;
182  }
183 
189  public function delete()
190  {
191  $db = $this->db;
192 
193  $db->manipulate("DELETE FROM cont_member_skills WHERE " .
194  " obj_id = " . $db->quote($this->getObjId(), "integer") .
195  " AND user_id = " . $db->quote($this->getUserId(), "integer"));
196  }
197 
201  public function publish($a_ref_id)
202  {
203  $db = $this->db;
204 
206  $this->getUserId(),
207  $this->getObjId(),
208  false,
209  $this->getObjId()
210  );
211 
212  foreach ($this->skill_levels as $sk => $l) {
213  $changed = true;
214  $sk = explode(":", $sk);
216  $l,
217  $this->user_id,
218  $a_ref_id,
219  $sk[1],
221  false,
222  false,
223  $this->obj_id
224  );
225  }
226 
227  $db->manipulate("UPDATE cont_member_skills SET " .
228  " published = " . $db->quote(1, "integer") .
229  " WHERE obj_id = " . $db->quote($this->getObjId(), "integer") .
230  " AND user_id = " . $db->quote($this->getUserId(), "integer"));
231 
232  return $changed;
233  }
234 
235 
239  public function removeAllSkillLevels()
240  {
242  $this->getUserId(),
243  $this->getObjId(),
244  false,
245  $this->getObjId()
246  );
247 
248  $this->delete();
249  }
250 }
__construct($a_obj_id, $a_user_id)
Constrictor.
global $DIC
Definition: saml.php:7
$s
Definition: pwgen.php:45
saveLevelForSkills($a_level_data)
Save levels for skills.
static removeAllUserSkillLevelStatusOfObject($a_user_id, $a_trigger_obj_id, $a_self_eval=false, $a_unique_identifier="")
Remove a user skill completely.
global $l
Definition: afr.php:30
static writeUserSkillLevelStatus( $a_level_id, $a_user_id, $a_trigger_ref_id, $a_tref_id=0, $a_status=ilBasicSkill::ACHIEVED, $a_force=false, $a_self_eval=false, $a_unique_identifier="")
Write skill level status.
removeAllSkillLevels()
Remove all skill levels.
getOrderedSkillLevels()
Get ordered skill levels.