ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
SampleSolutionRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
31  protected \ilDBInterface $db;
32 
33  public function __construct(
34  CollectionWrapper $wrapper,
35  \ilDBInterface $db
36  ) {
37  $this->db = $db;
38  $this->wrapper = $wrapper;
39  }
40 
41  public function getIdStringForAssId(int $ass_id): string
42  {
43  $set = $this->db->queryF(
44  "SELECT solution_rid FROM exc_assignment " .
45  " WHERE id = %s ",
46  ["integer"],
47  [$ass_id]
48  );
49  $rec = $this->db->fetchAssoc($set);
50  return ($rec["solution_rid"] ?? "");
51  }
52 
53  public function hasFile(int $ass_id): bool
54  {
55  $rid = $this->getIdStringForAssId($ass_id);
56  return ($rid !== "");
57  }
58 
59  public function deliverFile(int $ass_id): void
60  {
61  $rid = $this->getIdStringForAssId($ass_id);
62  $this->wrapper->deliverFile($rid);
63  }
64 
65  public function importFromLegacyUpload(
66  int $ass_id,
67  array $file_input,
68  ResourceStakeholder $stakeholder
69  ): string {
70  $rcid = $this->wrapper->importFileFromLegacyUpload(
71  $file_input,
72  $stakeholder
73  );
74  if ($rcid !== "") {
75  $this->db->update(
76  "exc_assignment",
77  [
78  "fb_file" => ["text", $file_input["name"]],
79  "solution_rid" => ["text", $rcid]
80  ],
81  [ // where
82  "id" => ["integer", $ass_id]
83  ]
84  );
85  }
86  return $rcid;
87  }
88 
89  public function clone(
90  int $from_ass_id,
91  int $to_ass_id
92  ): void {
93  $from_rid = $this->getIdStringForAssId($from_ass_id);
94  $to_rid = $this->wrapper->cloneResource($from_rid);
95  if ($to_rid !== "") {
96  $this->db->update(
97  "exc_assignment",
98  [
99  "solution_rid" => ["text", $to_rid]
100  ],
101  [ // where
102  "id" => ["integer", $to_ass_id]
103  ]
104  );
105  }
106  }
107 }
importFromLegacyUpload(int $ass_id, array $file_input, ResourceStakeholder $stakeholder)
__construct(CollectionWrapper $wrapper, \ilDBInterface $db)