ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ContainerSkillDBRepository.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 namespace ILIAS\Container\Skills;
23 
25 {
26  protected \ilDBInterface $db;
28 
29  public function __construct(
30  \ilDBInterface $db = null,
31  SkillInternalFactoryService $factory_service = null,
32  ) {
33  global $DIC;
34 
35  $this->db = ($db) ?: $DIC->database();
36  $this->factory_service = ($factory_service) ?: $DIC->skills()->internalContainer()->factory();
37  }
38 
39  public function add(int $cont_obj_id, int $skill_id, int $tref_id): void
40  {
41  $this->db->replace(
42  "cont_skills",
43  [
44  "id" => ["integer", $cont_obj_id],
45  "skill_id" => ["integer", $skill_id],
46  "tref_id" => ["integer", $tref_id]
47  ],
48  []
49  );
50  }
51 
52  public function remove(int $cont_obj_id, int $skill_id, int $tref_id): void
53  {
54  $this->db->manipulate(
55  "DELETE FROM cont_skills WHERE " .
56  " id = " . $this->db->quote($cont_obj_id, "integer") .
57  " AND skill_id = " . $this->db->quote($skill_id, "integer") .
58  " AND tref_id = " . $this->db->quote($tref_id, "integer")
59  );
60  }
61 
62  public function removeForSkill(int $skill_node_id, bool $is_reference): void
63  {
64  if (!$is_reference) {
65  $this->db->manipulate("DELETE FROM cont_skills " .
66  " WHERE skill_id = " . $this->db->quote($skill_node_id, "integer"));
67  } else {
68  $this->db->manipulate("DELETE FROM cont_skills " .
69  " WHERE tref_id = " . $this->db->quote($skill_node_id, "integer"));
70  }
71  }
72 
76  public function getAll(int $cont_obj_id): array
77  {
78  $skills = [];
79  $set = $this->db->query(
80  "SELECT * FROM cont_skills " .
81  " WHERE id = " . $this->db->quote($cont_obj_id, "integer")
82  );
83 
84  while ($rec = $this->db->fetchAssoc($set)) {
85  $skills[] = $this->getContainerSkillFromRecord($rec);
86  }
87  return $skills;
88  }
89 
90  protected function getContainerSkillFromRecord(array $rec): ContainerSkill
91  {
92  $rec["skill_id"] = (int) $rec["skill_id"];
93  $rec["tref_id"] = (int) $rec["tref_id"];
94  $rec["id"] = (int) $rec["id"];
95 
96  return $this->factory_service->containerSkill()->skill(
97  $rec["skill_id"],
98  $rec["tref_id"],
99  $rec["id"]
100  );
101  }
102 }
__construct(\ilDBInterface $db=null, SkillInternalFactoryService $factory_service=null,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
add(int $cont_obj_id, int $skill_id, int $tref_id)