ILIAS  release_8 Revision v8.23
class.ilContainerSkills.php
Go to the documentation of this file.
1 <?php
2 
21 
28 {
29  protected ilDBInterface $db;
31  protected array $skills = [];
32  protected int $id = 0;
33 
34  public function __construct(int $a_obj_id)
35  {
36  global $DIC;
37 
38  $this->db = $DIC->database();
39  $this->tree_service = $DIC->skills()->tree();
40 
41  $this->setId($a_obj_id);
42  if ($a_obj_id > 0) {
43  $this->read();
44  }
45  }
46 
47  public function setId(int $a_val): void
48  {
49  $this->id = $a_val;
50  }
51 
52  public function getId(): int
53  {
54  return $this->id;
55  }
56 
57  public function resetSkills(): void
58  {
59  $this->skills = [];
60  }
61 
62  public function addSkill(int $a_skill_id, int $a_tref_id): void
63  {
64  $this->skills[$a_skill_id . "-" . $a_tref_id] = [
65  "skill_id" => $a_skill_id,
66  "tref_id" => $a_tref_id
67  ];
68  }
69 
70  public function removeSkill(int $a_skill_id, int $a_tref_id): void
71  {
72  unset($this->skills[$a_skill_id . "-" . $a_tref_id]);
73  }
74 
75  public function getSkills(): array
76  {
77  return $this->skills;
78  }
79 
83  public function getOrderedSkills(): array
84  {
85  $vtree = $this->tree_service->getGlobalVirtualSkillTree();
86  return $vtree->getOrderedNodeset($this->getSkills(), "skill_id", "tref_id");
87  }
88 
89  public function read(): void
90  {
91  $db = $this->db;
92 
93  $this->skills = [];
94  $set = $db->query("SELECT * FROM cont_skills " .
95  " WHERE id = " . $db->quote($this->getId(), "integer"));
96  while ($rec = $db->fetchAssoc($set)) {
97  $this->skills[$rec["skill_id"] . "-" . $rec["tref_id"]] = $rec;
98  }
99  }
100 
101  public function delete(): void
102  {
103  $db = $this->db;
104 
105  $db->manipulate("DELETE FROM cont_skills WHERE " .
106  " id = " . $db->quote($this->getId(), "integer"));
107  }
108 
109  public function save(): void
110  {
111  $db = $this->db;
112 
113  $this->delete();
114  foreach ($this->skills as $s) {
115  $db->manipulate("INSERT INTO cont_skills " .
116  "(id, skill_id, tref_id) VALUES (" .
117  $db->quote($this->getId(), "integer") . "," .
118  $db->quote($s["skill_id"], "integer") . "," .
119  $db->quote($s["tref_id"], "integer") . ")");
120  }
121  }
122 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetchAssoc(ilDBStatement $statement)
Skills of a container.
quote($value, string $type)
removeSkill(int $a_skill_id, int $a_tref_id)
global $DIC
Definition: feed.php:28
addSkill(int $a_skill_id, int $a_tref_id)
query(string $query)
Run a (read-only) Query on the database.
manipulate(string $query)
Run a (write) Query on the database.
SkillTreeService $tree_service