ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TutorFeedbackFileTeamRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
32 protected \ilDBInterface $db;
33
34 public function __construct(
37 ) {
38 $this->db = $db;
39 $this->wrapper = $wrapper;
40 }
41
42 protected function getTeamId(int $ass_id, int $user_id): int
43 {
44 $set = $this->db->queryF(
45 "SELECT id FROM il_exc_team " .
46 " WHERE ass_id = %s AND user_id = %s",
47 ["integer", "integer"],
49 );
50 if ($rec = $this->db->fetchAssoc($set)) {
51 return (int) $rec["id"];
52 }
53 return 0;
54 }
55
56 public function createCollection(int $ass_id, int $user_id): void
57 {
58 $team_id = $this->getTeamId($ass_id, $user_id);
59 if ($team_id === 0) {
60 return;
61 }
62 $new_id = $this->wrapper->createEmptyCollection();
63 $this->db->update(
64 "exc_team_data",
65 [
66 "feedback_rcid" => ["text", $new_id]
67 ],
68 [ // where
69 "id" => ["integer", $team_id]
70 ]
71 );
72 }
73
74 public function getParticipantIdForRcid(int $ass_id, string $rcid): int
75 {
76 $set = $this->db->queryF(
77 "SELECT id FROM exc_team_data " .
78 " WHERE feedback_rcid = %s",
79 ["text"],
80 [$rcid]
81 );
82 $rec = $this->db->fetchAssoc($set);
83 return (int) ($rec["id"] ?? 0);
84 }
85
86
87 public function getIdStringForAssIdAndUserId(int $ass_id, int $user_id): string
88 {
89 $team_id = $this->getTeamId($ass_id, $user_id);
90 if ($team_id === 0) {
91 return "";
92 }
93 $set = $this->db->queryF(
94 "SELECT feedback_rcid FROM exc_team_data " .
95 " WHERE id = %s",
96 ["integer"],
97 [$team_id]
98 );
99 $rec = $this->db->fetchAssoc($set);
100 return ($rec["if_rcid"] ?? "");
101 }
102
103 public function hasCollection(int $ass_id, int $user_id): bool
104 {
105 $rcid = $this->getIdStringForAssIdAndUserId($ass_id, $user_id);
106 return ($rcid !== "");
107 }
108
110 {
111 $rcid = $this->getIdStringForAssIdAndUserId($ass_id, $user_id);
112 if ($rcid !== "") {
113 return $this->wrapper->getCollectionForIdString($rcid);
114 }
115 return null;
116 }
117
118 public function count(int $ass_id, int $user_id): int
119 {
120 if (!is_null($collection = $this->getCollection($ass_id, $user_id))) {
121 return $collection->count();
122 }
123 return 0;
124 }
125
126 public function deliverFile($ass_id, $participant_id, $file): void
127 {
129 foreach ($this->getCollectionResourcesInfo($ass_id, $participant_id) as $info) {
130 if ($file === $info->getTitle()) {
131 $this->wrapper->deliverFile($info->getRid());
132 }
133 }
134 throw new \ilExerciseException("Resource $file not found.");
135 }
136
137 public function getFilenameForRid(int $ass_id, int $part_id, string $rid): string
138 {
139 foreach ($this->getCollectionResourcesInfo($ass_id, $part_id) as $info) {
140 if ($rid === $info->getRid()) {
141 $this->wrapper->deliverFile($info->getRid());
142 return $info->getTitle();
143 }
144 }
145 return "";
146 }
147
149 int $ass_id,
150 int $user_id
151 ): \Generator {
153 return $this->wrapper->getCollectionResourcesInfo($collection);
154 }
155
156 public function deleteCollection(
157 int $ass_id,
158 int $user_id,
159 ResourceStakeholder $stakeholder
160 ): void {
161 throw new \ilExerciseException("Collection cannot be deleted for user in team assignment $ass_id.");
162 }
163
164 public function deleteTeamCollection(
165 int $team_id,
166 ResourceStakeholder $stakeholder
167 ): void {
168 $set = $this->db->queryF(
169 "SELECT feedback_rcid FROM exc_team_data " .
170 " WHERE id = %s",
171 ["integer"],
172 [$team_id]
173 );
174 $rec = $this->db->fetchAssoc($set);
175 $rcid = $rec["feedback_rcid"] ?? "";
176 if ($rcid !== "") {
177 $this->wrapper->deleteCollectionForIdString($rcid, $stakeholder);
178 }
179 }
180
181}
deleteCollection(int $ass_id, int $user_id, ResourceStakeholder $stakeholder)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$info
Definition: entry_point.php:21
Interface ilDBInterface.