ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
SampleSolutionManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
29  protected \ilExcSampleSolutionStakeholder $stakeholder;
30  protected int $ass_id;
31  protected \ILIAS\FileUpload\FileUpload $upload;
34 
35  public function __construct(
36  int $ass_id,
38  \ilExcSampleSolutionStakeholder $stakeholder,
39  InternalDomainService $domain
40  ) {
41  global $DIC;
42 
43  $this->upload = $DIC->upload();
44 
45  $this->repo = $repo;
46  $this->ass_id = $ass_id;
47  $this->stakeholder = $stakeholder;
48  $this->domain = $domain;
49  }
50 
52  {
53  return $this->stakeholder;
54  }
55 
56 
57  public function importFromLegacyUpload(array $file_input): string
58  {
59  if (!isset($file_input["tmp_name"])) {
60  return "";
61  }
62  return $this->repo->importFromLegacyUpload(
63  $this->ass_id,
64  $file_input,
65  $this->stakeholder
66  );
67  }
68 
69  public function deliver(): void
70  {
71  if ($this->repo->hasFile($this->ass_id)) {
72  $this->repo->deliverFile($this->ass_id);
73  } else {
74  $ass = $this->domain->assignment()->getAssignment($this->ass_id);
76  $ass->getGlobalFeedbackFilePath(),
77  $ass->getFeedbackFile()
78  );
79  }
80  }
81 
82  public function cloneTo(
83  int $to_ass_id
84  ): void {
85  // IRSS
86  if ($this->repo->hasFile($this->ass_id)) {
87  $this->repo->clone($this->ass_id, $to_ass_id);
88  } else { // NO IRSS
89  $old_exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
90  $new_exc_id = \ilExAssignment::lookupExerciseId($to_ass_id);
91 
92  $old_storage = new \ilFSStorageExercise($old_exc_id, $this->ass_id);
93  $new_storage = new \ilFSStorageExercise($new_exc_id, $to_ass_id);
94  $new_storage->create();
95  if (is_dir($old_storage->getGlobalFeedbackPath())) {
96  \ilFileUtils::rCopy($old_storage->getGlobalFeedbackPath(), $new_storage->getGlobalFeedbackPath());
97  }
98  }
99  }
100 
101 }
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
__construct(int $ass_id, SampleSolutionRepository $repo, \ilExcSampleSolutionStakeholder $stakeholder, InternalDomainService $domain)
static lookupExerciseId(int $a_ass_id)