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