ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TeamDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
30{
32 protected \ilDBInterface $db;
33
34 public function __construct(
37 ) {
38 $this->db = $db;
39 $this->data = $data;
40 }
41
42 public function create(): int
43 {
44 $id = $this->db->nextId("il_exc_team");
45 $this->db->insert("exc_team_data", [
46 "id" => ["integer", $id]
47 ]);
48 return $id;
49 }
50
51 public function addUser(int $team_id, int $ass_id, int $user_id): void
52 {
53 $this->db->insert("il_exc_team", [
54 "id" => ["integer", $team_id],
55 "ass_id" => ["integer", $ass_id],
56 "user_id" => ["integer", $user_id]
57 ]);
58 }
59
60 public function removeUser(int $team_id, int $ass_id, int $user_id): void
61 {
62 $this->db->manipulateF(
63 "DELETE FROM il_exc_team WHERE " .
64 " id = %s AND ass_id = %s AND user_id = %s",
65 ["integer", "integer", "integer"],
66 [
67 $team_id,
68 $ass_id,
70 ]
71 );
72 }
73
77 public function getMembers(int $team_id): \Generator
78 {
79 $set = $this->db->queryF(
80 "SELECT * FROM il_exc_team " .
81 " WHERE id = %s ",
82 ["integer"],
83 [$team_id]
84 );
85 while ($rec = $this->db->fetchAssoc($set)) {
86 yield $this->data->teamMember(
87 (int) $rec["id"],
88 (int) $rec["ass_id"],
89 (int) $rec["user_id"]
90 );
91 }
92 }
93
97 public function getMemberIds(int $team_id): array
98 {
99 $set = $this->db->queryF(
100 "SELECT user_id FROM il_exc_team " .
101 " WHERE id = %s ",
102 ["integer"],
103 [$team_id]
104 );
105 $ids = [];
106 while ($rec = $this->db->fetchAssoc($set)) {
107 $ids[] = (int) $rec["user_id"];
108 }
109 return $ids;
110 }
111
112
113 public function getTeamForMember(int $ass_id, int $user_id): ?int
114 {
115 $set = $this->db->queryF(
116 "SELECT id FROM il_exc_team " .
117 " WHERE ass_id = %s AND user_id = %s",
118 ["integer", "integer"],
120 );
121 $rec = $this->db->fetchAssoc($set);
122 if (isset($rec["id"])) {
123 return (int) $rec["id"];
124 }
125 return null;
126 }
127
128 public function getAllMemberIdsOfAssignment(int $assignment_id): \Generator
129 {
130 $set = $this->db->queryF(
131 "SELECT DISTINCT user_id FROM il_exc_team " .
132 " WHERE ass_id = %s ",
133 ["integer"],
134 [$assignment_id]
135 );
136 while ($rec = $this->db->fetchAssoc($set)) {
137 yield (int) $rec["user_id"];
138 }
139 }
140
141 public function getUserTeamMap(int $assignment_id): array
142 {
143 $map = [];
144 $set = $this->db->queryF(
145 "SELECT * FROM il_exc_team " .
146 " WHERE ass_id = %s ",
147 ["integer"],
148 [$assignment_id]
149 );
150 while ($rec = $this->db->fetchAssoc($set)) {
151 $map[(int) $rec["user_id"]] = (int) $rec["id"];
152 }
153 return $map;
154 }
155
156 public function getAssignmentForTeam(int $team_id): int
157 {
158 $set = $this->db->queryF(
159 "SELECT ass_id FROM il_exc_team " .
160 " WHERE id = %s ",
161 ["integer"],
162 [$team_id]
163 );
164 $rec = $this->db->fetchAssoc($set);
165 return (int) ($rec["ass_id"] ?? 0);
166 }
167
168 public function getTeamIdsOfAssignment(int $ass_id): array
169 {
170 $set = $this->db->queryF(
171 "SELECT DISTINCT(id) FROM il_exc_team " .
172 " WHERE ass_id = %s ",
173 ["integer"],
174 [$ass_id]
175 );
176 $team_ids = [];
177 while ($rec = $this->db->fetchAssoc($set)) {
178 $team_ids[] = (int) $rec["id"];
179 }
180 return $team_ids;
181 }
182
183 public function deleteTeam(int $team_id): void
184 {
185 $this->db->manipulateF(
186 "DELETE FROM il_exc_team WHERE " .
187 " id = %s ",
188 ["integer"],
189 [
190 $team_id
191 ]
192 );
193 $this->db->manipulateF(
194 "DELETE FROM exc_team_data WHERE " .
195 " id = %s ",
196 ["integer"],
197 [
198 $team_id
199 ]
200 );
201 }
202
203 public function deleteTeamLog(int $team_id): void
204 {
205 $this->db->manipulateF(
206 "DELETE FROM il_exc_team_log WHERE " .
207 " team_id = %s ",
208 ["integer"],
209 [
210 $team_id
211 ]
212 );
213 }
214
215}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Internal factory for data objects.
Table exc_team_data: Team Table il_exc_team: Team participants (holds the sequence due to historic re...
removeUser(int $team_id, int $ass_id, int $user_id)
__construct(\ilDBInterface $db, InternalDataService $data)
getAllMemberIdsOfAssignment(int $assignment_id)
getTeamForMember(int $ass_id, int $user_id)
addUser(int $team_id, int $ass_id, int $user_id)
Interface ilDBInterface.