Skip to content

Commit f75f1e4

Browse files
committed
Renaming supplementary files to exercise files (preparing for supplementary/attachment files unification).
1 parent 2c420a9 commit f75f1e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+661
-434
lines changed

app/V1Module/presenters/ExerciseFilesPresenter.php

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
use App\Helpers\ExerciseConfig\ExerciseConfigChecker;
1616
use App\Helpers\ExercisesConfig;
1717
use App\Helpers\FileStorageManager;
18-
use App\Model\Entity\SupplementaryExerciseFile;
18+
use App\Model\Entity\Assignment;
19+
use App\Model\Entity\ExerciseFile;
1920
use App\Model\Entity\UploadedFile;
2021
use App\Model\Entity\AttachmentFile;
2122
use App\Model\Repository\Assignments;
2223
use App\Model\Repository\AttachmentFiles;
2324
use App\Model\Repository\Exercises;
2425
use App\Model\Entity\Exercise;
25-
use App\Model\Repository\SupplementaryExerciseFiles;
26+
use App\Model\Repository\ExerciseFiles;
2627
use App\Model\Repository\UploadedFiles;
2728
use App\Security\ACL\IExercisePermissions;
2829
use Exception;
@@ -52,10 +53,10 @@ class ExerciseFilesPresenter extends BasePresenter
5253
public $uploadedFiles;
5354

5455
/**
55-
* @var SupplementaryExerciseFiles
56+
* @var ExerciseFiles
5657
* @inject
5758
*/
58-
public $supplementaryFiles;
59+
public $exerciseFiles;
5960

6061
/**
6162
* @var AttachmentFiles
@@ -87,7 +88,7 @@ class ExerciseFilesPresenter extends BasePresenter
8788
*/
8889
public $configChecker;
8990

90-
public function checkUploadSupplementaryFiles(string $id)
91+
public function checkUploadExerciseFiles(string $id)
9192
{
9293
$exercise = $this->exercises->findOrThrow($id);
9394
if (!$this->exerciseAcl->canUpdate($exercise)) {
@@ -96,40 +97,40 @@ public function checkUploadSupplementaryFiles(string $id)
9697
}
9798

9899
/**
99-
* Associate supplementary files with an exercise and upload them to remote file server
100+
* Associate exercise files with an exercise and upload them to remote file server
100101
* @POST
101102
* @throws ForbiddenRequestException
102103
* @throws InvalidApiArgumentException
103104
* @throws SubmissionFailedException
104105
*/
105-
#[Post("files", new VMixed(), "Identifiers of supplementary files", nullable: true)]
106+
#[Post("files", new VMixed(), "Identifiers of exercise files", nullable: true)]
106107
#[Path("id", new VUuid(), "identification of exercise", required: true)]
107-
public function actionUploadSupplementaryFiles(string $id)
108+
public function actionUploadExerciseFiles(string $id)
108109
{
109110
$exercise = $this->exercises->findOrThrow($id);
110111

111112
$files = $this->uploadedFiles->findAllById($this->getRequest()->getPost("files"));
112-
$currentSupplementaryFiles = [];
113+
$currentFiles = [];
113114
$totalFileSize = 0;
114115

115-
/** @var SupplementaryExerciseFile $file */
116-
foreach ($exercise->getSupplementaryEvaluationFiles() as $file) {
117-
$currentSupplementaryFiles[$file->getName()] = $file;
116+
/** @var ExerciseFile $file */
117+
foreach ($exercise->getExerciseFiles() as $file) {
118+
$currentFiles[$file->getName()] = $file;
118119
$totalFileSize += $file->getFileSize();
119120
}
120121

121-
$totalFileCount = count($exercise->getSupplementaryEvaluationFiles());
122+
$totalFileCount = count($exercise->getExerciseFiles());
122123

123124
/** @var UploadedFile $file */
124125
foreach ($files as $file) {
125126
if (get_class($file) !== UploadedFile::class) {
126127
throw new ForbiddenRequestException("File {$file->getId()} was already used somewhere else");
127128
}
128129

129-
if (array_key_exists($file->getName(), $currentSupplementaryFiles)) {
130-
/** @var SupplementaryExerciseFile $currentFile */
131-
$currentFile = $currentSupplementaryFiles[$file->getName()];
132-
$exercise->getSupplementaryEvaluationFiles()->removeElement($currentFile);
130+
if (array_key_exists($file->getName(), $currentFiles)) {
131+
/** @var ExerciseFile $currentFile */
132+
$currentFile = $currentFiles[$file->getName()];
133+
$exercise->getExerciseFiles()->removeElement($currentFile);
133134
$totalFileSize -= $currentFile->getFileSize();
134135
} else {
135136
$totalFileCount += 1;
@@ -138,15 +139,15 @@ public function actionUploadSupplementaryFiles(string $id)
138139
$totalFileSize += $file->getFileSize();
139140
}
140141

141-
$fileCountLimit = $this->restrictionsConfig->getSupplementaryFileCountLimit();
142+
$fileCountLimit = $this->restrictionsConfig->getExerciseFileCountLimit();
142143
if ($totalFileCount > $fileCountLimit) {
143144
throw new InvalidApiArgumentException(
144145
'files',
145146
"The number of files would exceed the configured limit ($fileCountLimit)"
146147
);
147148
}
148149

149-
$sizeLimit = $this->restrictionsConfig->getSupplementaryFileSizeLimit();
150+
$sizeLimit = $this->restrictionsConfig->getExerciseFileSizeLimit();
150151
if ($totalFileSize > $sizeLimit) {
151152
throw new InvalidApiArgumentException(
152153
'files',
@@ -156,8 +157,8 @@ public function actionUploadSupplementaryFiles(string $id)
156157

157158
/** @var UploadedFile $file */
158159
foreach ($files as $file) {
159-
$hash = $this->fileStorage->storeUploadedSupplementaryFile($file);
160-
$exerciseFile = SupplementaryExerciseFile::fromUploadedFileAndExercise($file, $exercise, $hash);
160+
$hash = $this->fileStorage->storeUploadedExerciseFile($file);
161+
$exerciseFile = ExerciseFile::fromUploadedFileAndExercise($file, $exercise, $hash);
161162
$this->uploadedFiles->persist($exerciseFile, false);
162163
$this->uploadedFiles->remove($file, false);
163164
}
@@ -169,50 +170,50 @@ public function actionUploadSupplementaryFiles(string $id)
169170
$this->configChecker->check($exercise);
170171
$this->exercises->flush();
171172

172-
$this->sendSuccessResponse($exercise->getSupplementaryEvaluationFiles()->getValues());
173+
$this->sendSuccessResponse($exercise->getExerciseFiles()->getValues());
173174
}
174175

175-
public function checkGetSupplementaryFiles(string $id)
176+
public function checkGetExerciseFiles(string $id)
176177
{
177178
$exercise = $this->exercises->findOrThrow($id);
178179
if (!$this->exerciseAcl->canViewDetail($exercise)) {
179-
throw new ForbiddenRequestException("You cannot view supplementary files for this exercise.");
180+
throw new ForbiddenRequestException("You cannot view exercise files for this exercise.");
180181
}
181182
}
182183

183184
/**
184-
* Get list of all supplementary files for an exercise
185+
* Get list of all exercise files for an exercise
185186
* @GET
186187
*/
187188
#[Path("id", new VUuid(), "identification of exercise", required: true)]
188-
public function actionGetSupplementaryFiles(string $id)
189+
public function actionGetExerciseFiles(string $id)
189190
{
190191
$exercise = $this->exercises->findOrThrow($id);
191-
$this->sendSuccessResponse($exercise->getSupplementaryEvaluationFiles()->getValues());
192+
$this->sendSuccessResponse($exercise->getExerciseFiles()->getValues());
192193
}
193194

194-
public function checkDeleteSupplementaryFile(string $id, string $fileId)
195+
public function checkDeleteExerciseFile(string $id, string $fileId)
195196
{
196197
$exercise = $this->exercises->findOrThrow($id);
197198
if (!$this->exerciseAcl->canUpdate($exercise)) {
198-
throw new ForbiddenRequestException("You cannot delete supplementary files for this exercise.");
199+
throw new ForbiddenRequestException("You cannot delete exercise files for this exercise.");
199200
}
200201
}
201202

202203
/**
203-
* Delete supplementary exercise file with given id
204+
* Delete exercise file with given id
204205
* @DELETE
205206
* @throws ForbiddenRequestException
206207
*/
207208
#[Path("id", new VUuid(), "identification of exercise", required: true)]
208209
#[Path("fileId", new VString(), "identification of file", required: true)]
209-
public function actionDeleteSupplementaryFile(string $id, string $fileId)
210+
public function actionDeleteExerciseFile(string $id, string $fileId)
210211
{
211212
$exercise = $this->exercises->findOrThrow($id);
212-
$file = $this->supplementaryFiles->findOrThrow($fileId);
213+
$file = $this->exerciseFiles->findOrThrow($fileId);
213214

214215
$exercise->updatedNow();
215-
$exercise->removeSupplementaryEvaluationFile($file);
216+
$exercise->removeExerciseFile($file);
216217
$this->exercises->flush();
217218

218219
$this->configChecker->check($exercise);
@@ -221,33 +222,34 @@ public function actionDeleteSupplementaryFile(string $id, string $fileId)
221222
$this->sendSuccessResponse("OK");
222223
}
223224

224-
public function checkDownloadSupplementaryFilesArchive(string $id)
225+
public function checkDownloadExerciseFilesArchive(string $id)
225226
{
226227
$exercise = $this->exercises->findOrThrow($id);
227228
if (!$this->exerciseAcl->canViewDetail($exercise)) {
228-
throw new ForbiddenRequestException("You cannot access archive of exercise supplementary files");
229+
throw new ForbiddenRequestException("You cannot access archive of exercise files");
229230
}
230231
}
231232

232233
/**
233-
* Download archive containing all supplementary files for exercise.
234+
* Download archive containing all files for exercise.
234235
* @GET
235236
* @throws ForbiddenRequestException
236237
* @throws NotFoundException
237238
* @throws \Nette\Application\BadRequestException
238239
* @throws \Nette\Application\AbortException
239240
*/
240241
#[Path("id", new VUuid(), "of exercise", required: true)]
241-
public function actionDownloadSupplementaryFilesArchive(string $id)
242+
public function actionDownloadExerciseFilesArchive(string $id)
242243
{
243244
$exercise = $this->exercises->findOrThrow($id);
244245

245246
$files = [];
246-
foreach ($exercise->getSupplementaryEvaluationFiles() as $file) {
247+
foreach ($exercise->getExerciseFiles() as $file) {
248+
/** @var ExerciseFile $file */
247249
$files[$file->getName()] = $file->getFile($this->fileStorage);
248250
}
249251

250-
$this->sendZipFilesResponse($files, "exercise-supplementary-{$id}.zip", true);
252+
$this->sendZipFilesResponse($files, "exercise-files-{$id}.zip", true);
251253
}
252254

253255
public function checkUploadAttachmentFiles(string $id)
@@ -362,6 +364,7 @@ public function actionDeleteAttachmentFile(string $id, string $fileId)
362364
// file has no attachments to exercises, let's check the assignments
363365
$isUsed = false;
364366
foreach ($file->getAssignments() as $assignment) {
367+
/** @var Assignment $assignment */
365368
$group = $assignment->getGroup();
366369
if ($group && !$group->isArchived()) {
367370
$isUsed = true; // only non-archived assignments are considered relevant
@@ -376,10 +379,12 @@ public function actionDeleteAttachmentFile(string $id, string $fileId)
376379
// only if no attachments exists (except for deleted ones)
377380
// remove all links to deleted entities and remove the file record
378381
foreach ($file->getExercisesAndIReallyMeanAllOkay() as $exercise) {
382+
/** @var Exercise $exercise */
379383
$exercise->removeAttachmentFile($file);
380384
$this->exercises->persist($exercise, false);
381385
}
382386
foreach ($file->getAssignmentsAndIReallyMeanAllOkay() as $assignment) {
387+
/** @var Assignment $assignment */
383388
$assignment->removeAttachmentFile($file);
384389
$this->assignments->persist($assignment, false);
385390
}
@@ -414,6 +419,7 @@ public function actionDownloadAttachmentFilesArchive(string $id)
414419

415420
$files = [];
416421
foreach ($exercise->getAttachmentFiles() as $file) {
422+
/** @var AttachmentFile $file */
417423
$files[$file->getName()] = $file->getFile($this->fileStorage);
418424
}
419425
$this->sendZipFilesResponse($files, "exercise-attachment-{$id}.zip");

0 commit comments

Comments
 (0)