ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
TutorFeedbackFileRepository.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 public function createCollection(int $ass_id, int $user_id): void
43 {
44 /*
45 if ($ass_id === 12) {
46 debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
47 exit;
48 }*/
49 $new_id = $this->wrapper->createEmptyCollection();
50 $this->db->update(
51 "exc_mem_ass_status",
52 [
53 "feedback_rcid" => ["text", $new_id]
54 ],
55 [ // where
56 "ass_id" => ["integer", $ass_id],
57 "usr_id" => ["integer", $user_id]
58 ]
59 );
60 }
61
62 public function createCollectionIfMissing(int $ass_id, int $user_id): void
63 {
64 if (!$this->hasCollection($ass_id, $user_id)) {
65 $this->createCollection($ass_id, $user_id);
66 }
67 }
68
69 public function getIdStringForAssIdAndUserId(int $ass_id, int $user_id): string
70 {
71 $set = $this->db->queryF(
72 "SELECT feedback_rcid FROM exc_mem_ass_status " .
73 " WHERE ass_id = %s AND usr_id = %s",
74 ["integer", "integer"],
76 );
77 $rec = $this->db->fetchAssoc($set);
78 return ($rec["feedback_rcid"] ?? "");
79 }
80
81 public function hasCollection(int $ass_id, int $user_id): bool
82 {
83 $rcid = $this->getIdStringForAssIdAndUserId($ass_id, $user_id);
84 return ($rcid !== "");
85 }
86
88 {
89 $rcid = $this->getIdStringForAssIdAndUserId($ass_id, $user_id);
90 if ($rcid !== "") {
91 // 93fd5322-6a06-464d-b233-1f20da4b596f
92 return $this->wrapper->getCollectionForIdString($rcid);
93 }
94 return null;
95 }
96
97 public function count(int $ass_id, int $user_id): int
98 {
99 if (!is_null($collection = $this->getCollection($ass_id, $user_id))) {
100 return $collection->count();
101 }
102 return 0;
103 }
104
105 public function deliverFile($ass_id, $participant_id, $file): void
106 {
108 foreach ($this->getCollectionResourcesInfo($ass_id, $participant_id) as $info) {
109 if ($file === $info->getTitle()) {
110 $this->wrapper->deliverFile($info->getRid());
111 }
112 }
113 throw new \ilExerciseException("Resource $file not found.");
114 }
115
116 public function getFilenameForRid(int $ass_id, int $part_id, string $rid): string
117 {
118 foreach ($this->getCollectionResourcesInfo($ass_id, $part_id) as $info) {
119 if ($rid === $info->getRid()) {
120 return $info->getTitle();
121 }
122 }
123 return "";
124 }
125
126 public function getParticipantIdForRcid(int $ass_id, string $rcid): int
127 {
128 $set = $this->db->queryF(
129 "SELECT usr_id FROM exc_mem_ass_status " .
130 " WHERE ass_id = %s AND feedback_rcid = %s",
131 ["integer", "text"],
132 [$ass_id, $rcid]
133 );
134 $rec = $this->db->fetchAssoc($set);
135 return (int) ($rec["usr_id"] ?? 0);
136 }
137
142 int $ass_id,
143 int $user_id
144 ): \Generator {
146 return $this->wrapper->getCollectionResourcesInfo($collection);
147 }
148
149 public function deleteCollection(
150 int $ass_id,
151 int $user_id,
152 ResourceStakeholder $stakeholder
153 ): void {
154 $rcid = $this->getIdStringForAssIdAndUserId($ass_id, $user_id);
155 if ($rcid === "") {
156 return;
157 }
158 $this->wrapper->deleteCollectionForIdString(
159 $rcid,
160 $stakeholder
161 );
162 }
163}
deleteCollection(int $ass_id, int $user_id, ResourceStakeholder $stakeholder)
$info
Definition: entry_point.php:21
Interface ilDBInterface.