ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilContainerMemberSkills.php
Go to the documentation of this file.
1 <?php
2 
22 
29 {
30  protected ilDBInterface $db;
33  protected array $skills = [];
34  protected int $obj_id = 0;
35  protected int $user_id = 0;
36  protected array $skill_levels = [];
37  protected bool $published = false;
38 
39  public function __construct(int $a_obj_id, int $a_user_id)
40  {
41  global $DIC;
42 
43  $this->db = $DIC->database();
44  $this->tree_service = $DIC->skills()->tree();
45  $this->profile_service = $DIC->skills()->profile();
46 
47  $this->setObjId($a_obj_id);
48  $this->setUserId($a_user_id);
49  if ($a_obj_id > 0 && $a_user_id > 0) {
50  $this->read();
51  }
52  }
53 
54  public function setObjId(int $a_val): void
55  {
56  $this->obj_id = $a_val;
57  }
58 
59  public function getObjId(): int
60  {
61  return $this->obj_id;
62  }
63 
64  public function setUserId(int $a_val): void
65  {
66  $this->user_id = $a_val;
67  }
68 
69  public function getUserId(): int
70  {
71  return $this->user_id;
72  }
73 
74  public function read(): void
75  {
76  $db = $this->db;
77 
78  $set = $db->query(
79  "SELECT * FROM cont_member_skills " .
80  " WHERE obj_id = " . $db->quote($this->getObjId(), "integer") .
81  " AND user_id = " . $db->quote($this->getUserId(), "integer")
82  );
83  $this->skill_levels = [];
84  while ($rec = $this->db->fetchAssoc($set)) {
85  $this->skill_levels[$rec["skill_id"] . ":" . $rec["tref_id"]] = $rec["level_id"];
86  $this->published = $rec["published"]; // this is a little weak, but the value should be the same for all save skills
87  }
88  }
89 
93  public function getSkillLevels(): array
94  {
95  return $this->skill_levels;
96  }
97 
101  public function getOrderedSkillLevels(): array
102  {
103  $skill_levels = array_map(static function ($a, $k): array {
104  $s = explode(":", $k);
105  return ["level_id" => $a, "skill_id" => $s[0], "tref_id" => $s[1]];
106  }, $this->getSkillLevels(), array_keys($this->getSkillLevels()));
107 
108  $vtree = $this->tree_service->getGlobalVirtualSkillTree();
109  return $vtree->getOrderedNodeset($skill_levels, "skill_id", "tref_id");
110  }
111 
112  public function getPublished(): bool
113  {
114  return $this->published;
115  }
116 
120  public function saveLevelForSkills(array $a_level_data): void
121  {
122  $db = $this->db;
123 
124  $this->delete();
125  foreach ($a_level_data as $k => $v) {
126  $sk = explode(":", $k);
127  $db->manipulate("INSERT INTO cont_member_skills " .
128  "(obj_id, user_id, skill_id, tref_id, level_id, published) VALUES (" .
129  $db->quote($this->getObjId(), "integer") . "," .
130  $db->quote($this->getUserId(), "integer") . "," .
131  $db->quote($sk[0], "integer") . "," .
132  $db->quote($sk[1], "integer") . "," .
133  $db->quote($v, "integer") . "," .
134  $db->quote(0, "integer") .
135  ")");
136  }
137 
138  $this->skill_levels = $a_level_data;
139  }
140 
144  public function delete(): void
145  {
146  $db = $this->db;
147 
148  $db->manipulate("DELETE FROM cont_member_skills WHERE " .
149  " obj_id = " . $db->quote($this->getObjId(), "integer") .
150  " AND user_id = " . $db->quote($this->getUserId(), "integer"));
151  }
152 
153  public function publish(int $a_ref_id): bool
154  {
155  $db = $this->db;
156 
158  $this->getUserId(),
159  $this->getObjId(),
160  false,
161  (string) $this->getObjId()
162  );
163 
164  foreach ($this->skill_levels as $sk => $l) {
165  $changed = true;
166  $sk = explode(":", $sk);
168  $l,
169  $this->user_id,
170  $a_ref_id,
171  $sk[1],
173  false,
174  false,
175  $this->obj_id
176  );
177 
178  if ($sk[1] > 0) {
180  } else {
182  }
183  }
184 
185  //write profile completion entries if fulfilment status has changed
186  $this->profile_service->writeCompletionEntryForAllProfiles($this->getUserId());
187 
188  $db->manipulate("UPDATE cont_member_skills SET " .
189  " published = " . $db->quote(1, "integer") .
190  " WHERE obj_id = " . $db->quote($this->getObjId(), "integer") .
191  " AND user_id = " . $db->quote($this->getUserId(), "integer"));
192 
193  return $changed;
194  }
195 
196  public function removeAllSkillLevels(): void
197  {
199  $this->getUserId(),
200  $this->getObjId(),
201  false,
202  (string) $this->getObjId()
203  );
204 
205  $this->delete();
206  }
207 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
quote($value, string $type)
static removeAllUserSkillLevelStatusOfObject(int $a_user_id, int $a_trigger_obj_id, bool $a_self_eval=false, string $a_unique_identifier="")
global $DIC
Definition: feed.php:28
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, string $trigger_user_id="")
__construct(int $a_obj_id, int $a_user_id)
query(string $query)
Run a (read-only) Query on the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static addPersonalSkill(int $a_user_id, int $a_skill_node_id)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
manipulate(string $query)
Run a (write) Query on the database.