ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExcCriteriaFile.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  protected string $requested_file_hash = "";
28 
29  public function __construct()
30  {
32  global $DIC;
33 
35 
36  $request = $DIC->exercise()->internal()->gui()->request();
37  $this->requested_file_hash = $request->getFileHash();
38  }
39 
40  public function getType(): string
41  {
42  return "file";
43  }
44 
45  protected function initStorage(): string
46  {
47  $storage = new ilFSStorageExercise($this->ass->getExerciseId(), $this->ass->getId());
48  return $storage->getPeerReviewUploadPath($this->peer_id, $this->giver_id, $this->getId());
49  }
50 
51  public function getFiles(): array
52  {
53  $path = $this->initStorage();
54  return (array) glob($path . "*.*");
55  }
56 
57  public function resetReview(): void
58  {
59  $storage = new ilFSStorageExercise($this->ass->getExerciseId(), $this->ass->getId());
60  $storage->deleteDirectory($storage->getPeerReviewUploadPath($this->peer_id, $this->giver_id, $this->getId()));
61  }
62 
63 
64  // PEER REVIEW
65 
66  public function addToPeerReviewForm($a_value = null): void
67  {
68  $existing = array();
69  foreach ($this->getFiles() as $file) {
70  $existing[] = basename($file);
71  }
72 
73  $files = new ilFileInputGUI($this->getTitle(), "prccc_file_" . $this->getId());
74  $files->setInfo($this->getDescription());
75  $files->setRequired($this->isRequired());
76  $files->setValue(implode("<br />", $existing));
77  $files->setAllowDeletion(true);
78  $this->form->addItem($files);
79  }
80 
84  public function importFromPeerReviewForm(): void
85  {
86  $path = $this->initStorage();
87 
88  if ($this->form->getItemByPostVar("prccc_file_" . $this->getId())->getDeletionFlag()) {
90  $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setValue("");
91  }
92 
93  $incoming = $_FILES["prccc_file_" . $this->getId()];
94  if ($incoming["tmp_name"]) {
95  $org_name = basename($incoming["name"]);
96 
98  $incoming["tmp_name"],
99  $org_name,
100  $path . $org_name,
101  false
102  );
103  }
104  }
105 
106  public function hasValue($a_value): bool
107  {
108  return count($this->getFiles()) > 0;
109  }
110 
111  public function validate($a_value): bool
112  {
113  $lng = $this->lng;
114 
115  // because of deletion flag we have to also check ourselves
116  if ($this->isRequired()) {
117  if (!$this->hasValue($a_value)) {
118  if ($this->form) {
119  $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
120  }
121  return false;
122  }
123  }
124  return true;
125  }
126 
130  public function getFileByHash()
131  {
132  $hash = trim($this->requested_file_hash);
133  if ($hash != "") {
134  foreach ($this->getFiles() as $file) {
135  if (md5($file) == $hash) {
136  return $file;
137  }
138  }
139  }
140  return false;
141  }
142 
143  public function getHTML($a_value): string
144  {
145  $ilCtrl = $this->ctrl;
146 
147  $crit_id = $this->getId()
148  ?: "file";
149  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", $this->giver_id . "__" . $this->peer_id . "__" . $crit_id);
150 
151  $files = array();
152  foreach ($this->getFiles() as $file) {
153  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", md5($file));
154  $dl = $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "downloadPeerReview");
155  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", "");
156 
157  $files[] = '<a href="' . $dl . '">' . basename($file) . '</a>';
158  }
159 
160  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", "");
161 
162  return implode("<br />", $files);
163  }
164 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a file property in a property form.
getPeerReviewUploadPath(int $a_peer_id, int $a_giver_id, ?int $a_crit_id=null)
Get pear review upload path (each peer handled in a separate path)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
addToPeerReviewForm($a_value=null)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
form( $class_path, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...