ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFSWebStorageExercise.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 protected $log;
13 protected $ass_id;
15
21 public function __construct($a_container_id = 0, $a_ass_id = 0)
22 {
23 $this->ass_id = $a_ass_id;
24 $this->log = ilLoggerFactory::getLogger("exc");
25 $this->log->debug("ilFSWebStorageExercise construct with a_container_id = " . $a_container_id . " and ass_id =" . $a_ass_id);
26 parent::__construct(self::STORAGE_WEB, true, $a_container_id);
27 }
28
32 public function init()
33 {
34 if (parent::init()) {
35 if ($this->ass_id > 0) {
36 $this->submissions_path = $this->path . "/subm_" . $this->ass_id;
37
38 $this->log->debug("parent init() with ass_id =" . $this->ass_id);
39 $this->path .= "/ass_" . $this->ass_id;
40 }
41 } else {
42 $this->log->debug("no parent init() without ass_id");
43 return false;
44 }
45 return true;
46 }
47
48
55 protected function getPathPostfix()
56 {
57 return 'exc';
58 }
59
66 protected function getPathPrefix()
67 {
68 return 'ilExercise';
69 }
70
77 public function create()
78 {
79 $this->log->debug("parent create");
80
81 parent::create();
82
83 return true;
84 }
85
86 public function deleteUserSubmissionDirectory(int $user_id) : void
87 {
88 $internal_dir = $this->submissions_path . "/" . $user_id;
89
90 //remove first dot from (./data/client/ilExercise/3/exc_318/subm_21/6)
91 $internal_dir_without_dot = substr($internal_dir, 1);
92
93 $absolute_path = ILIAS_ABSOLUTE_PATH . $internal_dir_without_dot;
94
95 if (is_dir($absolute_path)) {
96 parent::deleteDirectory($absolute_path);
97 $this->log->debug("Removed = " . $absolute_path);
98 }
99 }
100
104 public function getFiles()
105 {
106 $ass = new ilExAssignment($this->ass_id);
107 $files_order = $ass->getInstructionFilesOrder();
108
109 $files = array();
110 if (!is_dir($this->path)) {
111 return $files;
112 }
113
114 $dp = opendir($this->path);
115 while ($file = readdir($dp)) {
116 if (!is_dir($this->path . '/' . $file)) {
117 $files[] = array(
118 'name' => $file,
119 'size' => filesize($this->path . '/' . $file),
120 'ctime' => filectime($this->path . '/' . $file),
121 'fullpath' => $this->path . '/' . $file,
122 'order' => $files_order[$file]["order_nr"] ? $files_order[$file]["order_nr"] : 0
123 );
124 }
125 }
126 closedir($dp);
127 $files = ilUtil::sortArray($files, "order", "asc", true);
128 return $files;
129 }
130
134 public function getAssignmentFilePath($a_file)
135 {
136 return $this->getAbsolutePath() . "/" . $a_file;
137 }
138
144 public function uploadAssignmentFiles($a_files)
145 {
146 if (is_array($a_files["name"])) {
147 foreach ($a_files["name"] as $k => $name) {
148 if ($name != "") {
149 $type = $a_files["type"][$k];
150 $tmp_name = $a_files["tmp_name"][$k];
151 $size = $a_files["size"][$k];
153 $tmp_name,
154 basename($name),
155 $this->path . DIRECTORY_SEPARATOR . basename($name),
156 false
157 );
158 }
159 }
160 }
161 }
162}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
Exercise assignment.
__construct($a_container_id=0, $a_ass_id=0)
Constructor.
init()
Append ass_<ass_id> to path (assignment id)
getPathPrefix()
Implementation of abstract method.
uploadAssignmentFiles($a_files)
Upload assignment files (e.g.
getAssignmentFilePath($a_file)
Get path for assignment file.
getPathPostfix()
Implementation of abstract method.
getAbsolutePath()
Get absolute path of storage directory.
static getLogger($a_component_id)
Get component logger.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type