ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
TeamDBRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
30 {
32  protected \ilDBInterface $db;
33 
34  public function __construct(
35  \ilDBInterface $db,
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,
69  $user_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 
94  public function getTeamForMember(int $ass_id, int $user_id): ?int
95  {
96  $set = $this->db->queryF(
97  "SELECT id FROM il_exc_team " .
98  " WHERE ass_id = %s AND user_id = %s",
99  ["integer", "integer"],
100  [$ass_id, $user_id]
101  );
102  $rec = $this->db->fetchAssoc($set);
103  if (isset($rec["id"])) {
104  return (int) $rec["id"];
105  }
106  return null;
107  }
108 
109  public function getAllMemberIdsOfAssignment(int $assignment_id): \Generator
110  {
111  $set = $this->db->queryF(
112  "SELECT DISTINCT user_id FROM il_exc_team " .
113  " WHERE ass_id = %s ",
114  ["integer"],
115  [$assignment_id]
116  );
117  while ($rec = $this->db->fetchAssoc($set)) {
118  yield (int) $rec["user_id"];
119  }
120  }
121 
122  public function getUserTeamMap(int $assignment_id): array
123  {
124  $map = [];
125  $set = $this->db->queryF(
126  "SELECT * FROM il_exc_team " .
127  " WHERE ass_id = %s ",
128  ["integer"],
129  [$assignment_id]
130  );
131  while ($rec = $this->db->fetchAssoc($set)) {
132  $map[(int) $rec["user_id"]] = (int) $rec["id"];
133  }
134  return $map;
135  }
136 
137  public function getAssignmentForTeam(int $team_id): int
138  {
139  $set = $this->db->queryF(
140  "SELECT ass_id FROM il_exc_team " .
141  " WHERE id = %s ",
142  ["integer"],
143  [$team_id]
144  );
145  $rec = $this->db->fetchAssoc($set);
146  return (int) ($rec["ass_id"] ?? 0);
147  }
148 
149  public function getTeamIdsOfAssignment(int $ass_id): array
150  {
151  $set = $this->db->queryF(
152  "SELECT DISTINCT(id) FROM il_exc_team " .
153  " WHERE ass_id = %s ",
154  ["integer"],
155  [$ass_id]
156  );
157  $team_ids = [];
158  while ($rec = $this->db->fetchAssoc($set)) {
159  $team_ids[] = (int) $rec["id"];
160  }
161  return $team_ids;
162  }
163 
164  public function deleteTeam(int $team_id): void
165  {
166  $this->db->manipulateF(
167  "DELETE FROM il_exc_team WHERE " .
168  " id = %s ",
169  ["integer"],
170  [
171  $team_id
172  ]
173  );
174  $this->db->manipulateF(
175  "DELETE FROM exc_team_data WHERE " .
176  " id = %s ",
177  ["integer"],
178  [
179  $team_id
180  ]
181  );
182  }
183 
184  public function deleteTeamLog(int $team_id): void
185  {
186  $this->db->manipulateF(
187  "DELETE FROM il_exc_team_log WHERE " .
188  " team_id = %s ",
189  ["integer"],
190  [
191  $team_id
192  ]
193  );
194  }
195 
196 }
removeUser(int $team_id, int $ass_id, int $user_id)
Internal factory for data objects.
Table exc_team_data: Team Table il_exc_team: Team participants (holds the sequence due to historic re...
getTeamForMember(int $ass_id, int $user_id)
__construct(\ilDBInterface $db, InternalDataService $data)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getAllMemberIdsOfAssignment(int $assignment_id)
addUser(int $team_id, int $ass_id, int $user_id)