ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $vtree = new ilVirtualSkillTree();
143 return $vtree->getOrderedNodeset($skill_levels, "skill_id", "tref_id");
144 }
145
146
152 public function getPublished()
153 {
154 return $this->published;
155 }
156
162 public function saveLevelForSkills($a_level_data)
163 {
164 $db = $this->db;
165
166 $this->delete();
167 foreach ($a_level_data as $k => $v) {
168 $sk = explode(":", $k);
169 $db->manipulate("INSERT INTO cont_member_skills " .
170 "(obj_id, user_id, skill_id, tref_id, level_id, published) VALUES (" .
171 $db->quote($this->getObjId(), "integer") . "," .
172 $db->quote($this->getUserId(), "integer") . "," .
173 $db->quote($sk[0], "integer") . "," .
174 $db->quote($sk[1], "integer") . "," .
175 $db->quote($v, "integer") . "," .
176 $db->quote(0, "integer") .
177 ")");
178 }
179
180 $this->skill_levels = $a_level_data;
181 }
182
188 public function delete()
189 {
190 $db = $this->db;
191
192 $db->manipulate("DELETE FROM cont_member_skills WHERE " .
193 " obj_id = " . $db->quote($this->getObjId(), "integer") .
194 " AND user_id = " . $db->quote($this->getUserId(), "integer"));
195 }
196
200 public function publish($a_ref_id)
201 {
202 $db = $this->db;
203
205 $this->getUserId(),
206 $this->getObjId(),
207 false,
208 $this->getObjId()
209 );
210
211 foreach ($this->skill_levels as $sk => $l) {
212 $changed = true;
213 $sk = explode(":", $sk);
215 $l,
216 $this->user_id,
217 $a_ref_id,
218 $sk[1],
220 false,
221 false,
222 $this->obj_id
223 );
224
225 if ($sk[1] > 0) {
227 } else {
229 }
230 }
231
232 $db->manipulate("UPDATE cont_member_skills SET " .
233 " published = " . $db->quote(1, "integer") .
234 " WHERE obj_id = " . $db->quote($this->getObjId(), "integer") .
235 " AND user_id = " . $db->quote($this->getUserId(), "integer"));
236
237 return $changed;
238 }
239
240
244 public function removeAllSkillLevels()
245 {
247 $this->getUserId(),
248 $this->getObjId(),
249 false,
250 $this->getObjId()
251 );
252
253 $this->delete();
254 }
255}
An exception for terminatinating execution or to throw for unit testing.
static removeAllUserSkillLevelStatusOfObject(int $a_user_id, int $a_trigger_obj_id, bool $a_self_eval=false, string $a_unique_identifier="")
static writeUserSkillLevelStatus(int $a_level_id, int $a_user_id, int $a_trigger_ref_id, int $a_tref_id=0, int $a_status=ilBasicSkill::ACHIEVED, bool $a_force=false, bool $a_self_eval=false, string $a_unique_identifier="", float $a_next_level_fulfilment=0.0)
getOrderedSkillLevels()
Get ordered skill levels.
saveLevelForSkills($a_level_data)
Save levels for skills.
removeAllSkillLevels()
Remove all skill levels.
__construct($a_obj_id, $a_user_id)
Constrictor.
static addPersonalSkill($a_user_id, $a_skill_node_id)
Add personal skill.
global $DIC
Definition: goto.php:24
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples