ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilExcCriteriaFile.php
Go to the documentation of this file.
1<?php
2
21
29{
30 protected \ILIAS\Exercise\PeerReview\DomainService $peer_review;
31 protected string $requested_file_hash = "";
32
33 public function __construct()
34 {
36 global $DIC;
37
39
40 $request = $DIC->exercise()->internal()->gui()->request();
41 $this->requested_file_hash = $request->getFileHash();
42 $this->peer_review = $DIC->exercise()->internal()->domain()->peerReview();
43 }
44
45 public function getType(): string
46 {
47 return "file";
48 }
49
53 public function getFiles(): array
54 {
55 $file_manager = $this->peer_review->criteriaFile($this->ass->getId());
56 $file = $file_manager->getFile($this->giver_id, $this->peer_id, (int) $this->getId());
57 $files = $file ? [$file]
58 : [];
59 return $files;
60 }
61
62 public function resetReview(): void
63 {
64 $this->peer_review->criteriaFile($this->ass->getId())
65 ->delete($this->giver_id, $this->peer_id, $this->getId());
66 }
67
68 // PEER REVIEW
69
70 public function addToPeerReviewForm($a_value = null): void
71 {
72 $existing = array();
73 foreach ($this->getFiles() as $file) {
74 $existing[] = $file->getTitle();
75 }
76 $files = new ilFileInputGUI($this->getTitle(), "prccc_file_" . $this->getId());
77 $files->setInfo($this->getDescription());
78 $files->setRequired($this->isRequired());
79 $files->setValue(implode("<br />", $existing));
80 $files->setAllowDeletion(true);
81 $this->form->addItem($files);
82 }
83
87 public function importFromPeerReviewForm(): void
88 {
89 $file_manager = $this->peer_review->criteriaFile($this->ass->getId());
90 if ($this->form->getItemByPostVar("prccc_file_" . $this->getId())->getDeletionFlag()) {
91 $file_manager->delete($this->giver_id, $this->peer_id, $this->getId());
92 $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setValue("");
93 }
94
95 $incoming = $_FILES["prccc_file_" . $this->getId()];
96 if ($incoming["tmp_name"]) {
97 $org_name = basename($incoming["name"]);
98 $file_manager->addFromLegacyUpload(
99 $incoming,
100 $this->giver_id,
101 $this->peer_id,
102 (int) $this->getId()
103 );
104 }
105 }
106
107 public function hasValue($a_value): bool
108 {
109 return count($this->getFiles()) > 0;
110 }
111
112 public function validate($a_value): bool
113 {
115
116 // because of deletion flag we have to also check ourselves
117 if ($this->isRequired()) {
118 if (!$this->hasValue($a_value)) {
119 if ($this->form) {
120 $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
121 }
122 return false;
123 }
124 }
125 return true;
126 }
127
128 public function getFileByHash(): ?CriteriaFile
129 {
130 $hash = trim($this->requested_file_hash);
131 if ($hash != "") {
132 foreach ($this->getFiles() as $file) {
133 if (md5($file->getTitle()) == $hash) {
134 return $file;
135 }
136 }
137 }
138 return null;
139 }
140
141 public function getHTML($a_value): string
142 {
143 $ilCtrl = $this->ctrl;
144
145 $crit_id = $this->getId()
146 ?: "file";
147 $ilCtrl->setParameterByClass(
148 "ilExPeerReviewGUI",
149 "fu",
150 $this->giver_id . "__" . $this->peer_id . "__" . $crit_id
151 );
152
153 $files = array();
154 foreach ($this->getFiles() as $file) {
155 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", md5($file->getTitle()));
156 $dl = $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "downloadPeerReview");
157 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", "");
158
159 $files[] = '<a href="' . $dl . '">' . $file->getTitle() . '</a>';
160 }
161
162 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", "");
163
164 return implode("<br />", $files);
165 }
166}
Class ilExcCriteriaFile.
addToPeerReviewForm($a_value=null)
ILIAS Exercise PeerReview DomainService $peer_review
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
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...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form(?array $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26