ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ContainerMemberSkillDBRepository.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 $user_id, int $skill_id, int $tref_id, int $level_id): void
40  {
41  $this->db->replace(
42  "cont_member_skills",
43  [
44  "obj_id" => ["integer", $cont_obj_id],
45  "user_id" => ["integer", $user_id],
46  "skill_id" => ["integer", $skill_id],
47  "tref_id" => ["integer", $tref_id]
48  ],
49  [
50  "level_id" => ["integer", $level_id],
51  "published" => ["integer", 0]
52  ]
53  );
54  }
55 
56  public function remove(int $cont_obj_id, int $user_id, int $skill_id, int $tref_id): void
57  {
58  $this->db->manipulate("DELETE FROM cont_member_skills " .
59  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
60  " AND user_id = " . $this->db->quote($user_id, "integer") .
61  " AND skill_id = " . $this->db->quote($skill_id, "integer") .
62  " AND tref_id = " . $this->db->quote($tref_id, "integer"));
63  }
64 
65  public function removeAll(int $cont_obj_id, int $user_id): void
66  {
67  $this->db->manipulate("DELETE FROM cont_member_skills " .
68  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
69  " AND user_id = " . $this->db->quote($user_id, "integer"));
70  }
71 
72  public function removeForSkill(int $skill_node_id, bool $is_reference): void
73  {
74  if (!$is_reference) {
75  $this->db->manipulate("DELETE FROM cont_member_skills " .
76  " WHERE skill_id = " . $this->db->quote($skill_node_id, "integer"));
77  } else {
78  $this->db->manipulate("DELETE FROM cont_member_skills " .
79  " WHERE tref_id = " . $this->db->quote($skill_node_id, "integer"));
80  }
81  }
82 
83  public function publish(int $cont_obj_id, int $user_id): void
84  {
85  $this->db->manipulate("UPDATE cont_member_skills SET " .
86  " published = " . $this->db->quote(1, "integer") .
87  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
88  " AND user_id = " . $this->db->quote($user_id, "integer"));
89  }
90 
91  public function getPublished(int $cont_obj_id, int $user_id): bool
92  {
93  $set = $this->db->query(
94  "SELECT published FROM cont_member_skills " .
95  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
96  " AND user_id = " . $this->db->quote($user_id, "integer")
97  );
98  while ($rec = $this->db->fetchAssoc($set)) {
99  if ((bool) $rec["published"] === true) { // this is a little weak, but the value should be the same for all save skills
100  return true;
101  }
102  }
103  return false;
104  }
105 
109  public function getAll(int $cont_obj_id, int $user_id): array
110  {
111  $mem_skills = [];
112  $set = $this->db->query(
113  "SELECT * FROM cont_member_skills " .
114  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
115  " AND user_id = " . $this->db->quote($user_id, "integer")
116  );
117  while ($rec = $this->db->fetchAssoc($set)) {
118  $mem_skills[] = $this->getContainerMemberSkillFromRecord($rec);
119  }
120  return $mem_skills;
121  }
122 
123  public function getLevel(int $cont_obj_id, int $user_id, int $skill_id, int $tref_id): ?int
124  {
125  $set = $this->db->query(
126  "SELECT * FROM cont_member_skills " .
127  " WHERE obj_id = " . $this->db->quote($cont_obj_id, "integer") .
128  " AND user_id = " . $this->db->quote($user_id, "integer") .
129  " AND skill_id = " . $this->db->quote($skill_id, "integer") .
130  " AND tref_id = " . $this->db->quote($tref_id, "integer")
131  );
132  if ($rec = $this->db->fetchAssoc($set)) {
133  return (int) $rec["level_id"];
134  }
135  return null;
136  }
137 
139  {
140  $rec["obj_id"] = (int) $rec["obj_id"];
141  $rec["user_id"] = (int) $rec["user_id"];
142  $rec["skill_id"] = (int) $rec["skill_id"];
143  $rec["tref_id"] = (int) $rec["tref_id"];
144  $rec["level_id"] = (int) $rec["level_id"];
145  $rec["published"] = (bool) $rec["published"];
146 
147  return $this->factory_service->containerSkill()->memberSkill(
148  $rec["obj_id"],
149  $rec["user_id"],
150  $rec["skill_id"],
151  $rec["tref_id"],
152  $rec["level_id"],
153  $rec["published"]
154  );
155  }
156 }
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 $user_id, int $skill_id, int $tref_id, int $level_id)
__construct(\ilDBInterface $db=null, SkillInternalFactoryService $factory_service=null,)
getLevel(int $cont_obj_id, int $user_id, int $skill_id, int $tref_id)