ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjFileBasedLM.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
8require_once "./Services/Object/classes/class.ilObject.php";
9//require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
10
21{
22 public $tree;
23
24 protected $online; // [bool]
25
32 public function __construct($a_id = 0, $a_call_by_reference = true)
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 // this also calls read() method! (if $a_id is set)
38 $this->type = "htlm";
39 parent::__construct($a_id, $a_call_by_reference);
40 }
41
42
49 public function update($a_skip_meta = false)
50 {
52
53 if (!$a_skip_meta) {
54 $this->updateMetaData();
55 }
57
58 $ilDB->manipulate($q = "UPDATE file_based_lm SET " .
59 " is_online = " . $ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text") .
60 ", startfile = " . $ilDB->quote($this->getStartFile(), "text") . " " .
61 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
62 return true;
63 }
64
68 public function read()
69 {
71
72 parent::read();
73
74 $q = "SELECT * FROM file_based_lm WHERE id = " . $ilDB->quote($this->getId(), "integer");
75 $lm_set = $ilDB->query($q);
76 $lm_rec = $ilDB->fetchAssoc($lm_set);
77 $this->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
78 $this->setStartFile((string) $lm_rec["startfile"]);
79 }
80
81
82
86 public function create($a_skip_meta = false)
87 {
89
90 parent::create();
91 $this->createDataDirectory();
92
93 $ilDB->manipulate("INSERT INTO file_based_lm (id, is_online, startfile) VALUES " .
94 " (" . $ilDB->quote($this->getID(), "integer") . "," .
95 $ilDB->quote("n", "text") . "," .
96 $ilDB->quote($this->getStartfile(), "text") . ")");
97 if (!$a_skip_meta) {
98 $this->createMetaData();
99 }
100 }
101
102 public function getDataDirectory($mode = "filesystem")
103 {
104 $lm_data_dir = ilUtil::getWebspaceDir($mode) . "/lm_data";
105 $lm_dir = $lm_data_dir . "/lm_" . $this->getId();
106
107 return $lm_dir;
108 }
109
110 public function createDataDirectory()
111 {
113 }
114
115 public function getStartFile()
116 {
117 return $this->start_file;
118 }
119
120 public function setStartFile($a_file, $a_omit_file_check = false)
121 {
122 if ($a_file &&
123 (file_exists($this->getDataDirectory() . "/" . $a_file) || $a_omit_file_check)) {
124 $this->start_file = $a_file;
125 }
126 }
127
128 public function setOnline($a_online)
129 {
130 $this->online = $a_online;
131 }
132
133 public function getOnline()
134 {
135 return $this->online;
136 }
137
141 public static function _lookupOnline($a_id)
142 {
143 global $DIC;
144
145 $ilDB = $DIC->database();
146
147 $q = "SELECT * FROM file_based_lm WHERE id = " . $ilDB->quote($a_id, "integer");
148 $lm_set = $ilDB->query($q);
149 $lm_rec = $ilDB->fetchAssoc($lm_set);
150
151 return ilUtil::yn2tf($lm_rec["is_online"]);
152 }
153
160 public function getDiskUsage()
161 {
162 require_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php");
164 }
165
166
167
178 public function delete()
179 {
181
182 // always call parent delete function first!!
183 if (!parent::delete()) {
184 return false;
185 }
186
187 // Delete meta data
188 $this->deleteMetaData();
189
190 // delete file_based_lm record
191 $ilDB->manipulate("DELETE FROM file_based_lm WHERE id = " .
192 $ilDB->quote($this->getID(), "integer"));
193
194 // delete data directory
196
197 return true;
198 }
199
209 public function populateByDirectoy($a_dir, $a_filename = "")
210 {
211 preg_match("/.*htlm_([0-9]*)\.zip/", $a_filename, $match);
212 if (is_dir($a_dir . "/htlm_" . $match[1])) {
213 $a_dir = $a_dir . "/htlm_" . $match[1];
214 }
215 ilUtil::rCopy($a_dir, $this->getDataDirectory());
217 }
218
225 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
226 {
227 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
228 $this->cloneMetaData($new_obj);
229
230 //copy online status if object is not the root copy object
231 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
232
233 if (!$cp_options->isRootNode($this->getRefId())) {
234 $new_obj->setOnline($this->getOnline());
235 }
236
237 $new_obj->setTitle($this->getTitle());
238 $new_obj->setDescription($this->getDescription());
239
240 // copy content
241 $new_obj->populateByDirectoy($this->getDataDirectory());
242
243 $new_obj->setStartFile($this->getStartFile());
244 $new_obj->update();
245
246 return $new_obj;
247 }
248}
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id.
File Based Learning Module (HTML) object.
__construct($a_id=0, $a_call_by_reference=true)
Constructor @access public.
update($a_skip_meta=false)
update object data
getDiskUsage()
Gets the disk usage of the object in bytes.
setStartFile($a_file, $a_omit_file_check=false)
populateByDirectoy($a_dir, $a_filename="")
Populate by directory.
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone HTML learning module.
static _lookupOnline($a_id)
check wether content object is online
create($a_skip_meta=false)
create file based lm
getDataDirectory($mode="filesystem")
Class ilObject Basic functions for all objects.
deleteMetaData()
delete meta data entry
updateMetaData()
update meta data entry
createMetaData()
create meta data entry
getDescription()
get object description
cloneMetaData($target_obj)
Copy meta data.
getId()
get object id @access public
getTitle()
get object title @access public
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static tf2yn($a_tf)
convert true/false to "y"/"n"
static getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static yn2tf($a_yn)
convert "y"/"n" to true/false
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
update($pash, $contents, Config $config)
global $DIC
Definition: saml.php:7
global $ilDB
$lm_set