ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcCriteriaFile.php
Go to the documentation of this file.
1<?php
2
20
28{
29 protected \ILIAS\Exercise\PeerReview\DomainService $peer_review;
30 protected string $requested_file_hash = "";
31
32 public function __construct()
33 {
35 global $DIC;
36
38
39 $request = $DIC->exercise()->internal()->gui()->request();
40 $this->requested_file_hash = $request->getFileHash();
41 $this->peer_review = $DIC->exercise()->internal()->domain()->peerReview();
42 }
43
44 public function getType(): string
45 {
46 return "file";
47 }
48
52 public function getFiles(): array
53 {
54 $file_manager = $this->peer_review->criteriaFile($this->ass->getId());
55 $file = $file_manager->getFile($this->giver_id, $this->peer_id, (int) $this->getId());
56 $files = $file ? [$file]
57 : [];
58 return $files;
59 }
60
61 public function resetReview(): void
62 {
63 $this->peer_review->criteriaFile($this->ass->getId())
64 ->delete($this->giver_id, $this->peer_id, $this->getId());
65 }
66
67 // PEER REVIEW
68
69 public function addToPeerReviewForm($a_value = null): void
70 {
71 $existing = array();
72 foreach ($this->getFiles() as $file) {
73 $existing[] = $file->getTitle();
74 }
75 $files = new ilFileInputGUI($this->getTitle(), "prccc_file_" . $this->getId());
76 $files->setInfo($this->getDescription());
77 $files->setRequired($this->isRequired());
78 $files->setValue(implode("<br />", $existing));
79 $files->setAllowDeletion(true);
80 $this->form->addItem($files);
81 }
82
86 public function importFromPeerReviewForm(): void
87 {
88 $file_manager = $this->peer_review->criteriaFile($this->ass->getId());
89 if ($this->form->getItemByPostVar("prccc_file_" . $this->getId())->getDeletionFlag()) {
90 $file_manager->delete($this->giver_id, $this->peer_id, $this->getId());
91 $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setValue("");
92 }
93
94 $incoming = $_FILES["prccc_file_" . $this->getId()];
95 if ($incoming["tmp_name"]) {
96 $org_name = basename($incoming["name"]);
97 $file_manager->addFromLegacyUpload(
98 $incoming,
99 $this->giver_id,
100 $this->peer_id,
101 (int) $this->getId()
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 {
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->getTitle()) == $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(
150 "ilExPeerReviewGUI",
151 "fu",
152 $this->giver_id . "__" . $this->peer_id . "__" . $crit_id
153 );
154
155 $files = array();
156 foreach ($this->getFiles() as $file) {
157 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", md5($file->getTitle()));
158 $dl = $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "downloadPeerReview");
159 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", "");
160
161 $files[] = '<a href="' . $dl . '">' . $file->getTitle() . '</a>';
162 }
163
164 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", "");
165
166 return implode("<br />", $files);
167 }
168}
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( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26