ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilExcCriteriaFile.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $lng;
17
21 protected $ctrl;
22
23
27 public function __construct()
28 {
29 global $DIC;
31
32 $this->lng = $DIC->language();
33 $this->ctrl = $DIC->ctrl();
34 }
35
36 public function getType()
37 {
38 return "file";
39 }
40
41 protected function initStorage()
42 {
43 $storage = new ilFSStorageExercise($this->ass->getExerciseId(), $this->ass->getId());
44 return $storage->getPeerReviewUploadPath($this->peer_id, $this->giver_id, $this->getId());
45 }
46
47 public function getFiles()
48 {
49 $path = $this->initStorage();
50 return (array) glob($path . "*.*");
51 }
52
53 public function resetReview()
54 {
55 $storage = new ilFSStorageExercise($this->ass->getExerciseId(), $this->ass->getId());
56 $storage->deleteDirectory($storage->getPeerReviewUploadPath($this->peer_id, $this->giver_id, $this->getId()));
57 }
58
59
60 // PEER REVIEW
61
62 public function addToPeerReviewForm($a_value = null)
63 {
64 $existing = array();
65 foreach ($this->getFiles() as $file) {
66 $existing[] = basename($file);
67 }
68
69 $files = new ilFileInputGUI($this->getTitle(), "prccc_file_" . $this->getId());
70 $files->setInfo($this->getDescription());
71 $files->setRequired($this->isRequired());
72 $files->setValue(implode("<br />", $existing));
73 $files->setALlowDeletion(true);
74 $this->form->addItem($files);
75 }
76
77 public function importFromPeerReviewForm()
78 {
79 $path = $this->initStorage();
80
81 if ($this->form->getItemByPostVar("prccc_file_" . $this->getId())->getDeletionFlag()) {
82 ilUtil::delDir($path);
83 $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setValue(null);
84 }
85
86 $incoming = $_FILES["prccc_file_" . $this->getId()];
87 if ($incoming["tmp_name"]) {
88 $org_name = basename($incoming["name"]);
89
91 $incoming["tmp_name"],
92 $org_name,
93 $path . $org_name,
94 false
95 );
96 }
97 }
98
99 public function hasValue($a_value)
100 {
101 return (bool) sizeof($this->getFiles());
102 }
103
104 public function validate($a_value)
105 {
107
108 // because of deletion flag we have to also check ourselves
109 if ($this->isRequired()) {
110 if (!$this->hasValue($a_value)) {
111 if ($this->form) {
112 $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
113 }
114 return false;
115 }
116 }
117 return true;
118 }
119
120 public function getFileByHash()
121 {
122 $hash = trim($_GET["fuf"]);
123 if ($hash) {
124 foreach ($this->getFiles() as $file) {
125 if (md5($file) == $hash) {
126 return $file;
127 }
128 }
129 }
130 }
131
132 public function getHTML($a_value)
133 {
135
136 $crit_id = $this->getId()
137 ? $this->getId()
138 : "file";
139 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", $this->giver_id . "__" . $this->peer_id . "__" . $crit_id);
140
141 $files = array();
142 foreach ($this->getFiles() as $file) {
143 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", md5($file));
144 $dl = $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "downloadPeerReview");
145 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", "");
146
147 $files[] = '<a href="' . $dl . '">' . basename($file) . '</a>';
148 }
149
150 $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", "");
151
152 return implode("<br />", $files);
153 }
154}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilExcCriteriaFile.
addToPeerReviewForm($a_value=null)
Class ilExcCriteria.
This class represents a file property in a property form.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46