ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_once "Modules/Exercise/classes/class.ilExcCriteria.php";
6 
14 {
18  protected $lng;
19 
23  protected $ctrl;
24 
25 
29  public function __construct()
30  {
31  global $DIC;
32  parent::__construct();
33 
34  $this->lng = $DIC->language();
35  $this->ctrl = $DIC->ctrl();
36  }
37 
38  public function getType()
39  {
40  return "file";
41  }
42 
43  protected function initStorage()
44  {
45  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
46  $storage = new ilFSStorageExercise($this->ass->getExerciseId(), $this->ass->getId());
47  return $storage->getPeerReviewUploadPath($this->peer_id, $this->giver_id, $this->getId());
48  }
49 
50  public function getFiles()
51  {
52  $path = $this->initStorage();
53  return (array) glob($path . "*.*");
54  }
55 
56  public function resetReview()
57  {
58  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
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)
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 
81  public function importFromPeerReviewForm()
82  {
83  $path = $this->initStorage();
84 
85  if ($this->form->getItemByPostVar("prccc_file_" . $this->getId())->getDeletionFlag()) {
87  $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setValue(null);
88  }
89 
90  $incoming = $_FILES["prccc_file_" . $this->getId()];
91  if ($incoming["tmp_name"]) {
92  $org_name = basename($incoming["name"]);
93 
94  ilUtil::moveUploadedFile(
95  $incoming["tmp_name"],
96  $org_name,
97  $path . $org_name,
98  false
99  );
100  }
101  }
102 
103  public function hasValue($a_value)
104  {
105  return (bool) sizeof($this->getFiles());
106  }
107 
108  public function validate($a_value)
109  {
110  $lng = $this->lng;
111 
112  // because of deletion flag we have to also check ourselves
113  if ($this->isRequired()) {
114  if (!$this->hasValue($a_value)) {
115  if ($this->form) {
116  $this->form->getItemByPostVar("prccc_file_" . $this->getId())->setAlert($lng->txt("msg_input_is_required"));
117  }
118  return false;
119  }
120  }
121  return true;
122  }
123 
124  public function getFileByHash()
125  {
126  $hash = trim($_GET["fuf"]);
127  if ($hash) {
128  foreach ($this->getFiles() as $file) {
129  if (md5($file) == $hash) {
130  return $file;
131  }
132  }
133  }
134  }
135 
136  public function getHTML($a_value)
137  {
139 
140  $crit_id = $this->getId()
141  ? $this->getId()
142  : "file";
143  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", $this->giver_id . "__" . $this->peer_id . "__" . $crit_id);
144 
145  $files = array();
146  foreach ($this->getFiles() as $file) {
147  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", md5($file));
148  $dl = $ilCtrl->getLinkTargetByClass("ilExPeerReviewGUI", "downloadPeerReview");
149  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fuf", "");
150 
151  $files[] = '<a href="' . $dl . '">' . basename($file) . '</a>';
152  }
153 
154  $ilCtrl->setParameterByClass("ilExPeerReviewGUI", "fu", "");
155 
156  return implode("<br />", $files);
157  }
158 }
$files
Definition: add-vimline.php:18
Class ilExcCriteria.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
This class represents a file property in a property form.
deleteDirectory($a_abs_name)
Delete directory.
global $ilCtrl
Definition: ilias.php:18
addToPeerReviewForm($a_value=null)
getPeerReviewUploadPath($a_peer_id, $a_giver_id, $a_crit_id)
Get pear review upload path (each peer handled in a separate path)
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class ilExcCriteriaFile.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively