ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 // default is offline
37 $this->setOfflineStatus(true);
38
39 $this->db = $DIC->database();
40 // this also calls read() method! (if $a_id is set)
41 $this->type = "htlm";
42 parent::__construct($a_id, $a_call_by_reference);
43 }
44
45
52 public function update($a_skip_meta = false)
53 {
55
56 if (!$a_skip_meta) {
57 $this->updateMetaData();
58 }
59 parent::update();
60
61 $ilDB->manipulate($q = "UPDATE file_based_lm SET " .
62 " startfile = " . $ilDB->quote($this->getStartFile(), "text") . " " .
63 " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
64 return true;
65 }
66
70 public function read()
71 {
73
74 parent::read();
75
76 $q = "SELECT * FROM file_based_lm WHERE id = " . $ilDB->quote($this->getId(), "integer");
77 $lm_set = $ilDB->query($q);
78 $lm_rec = $ilDB->fetchAssoc($lm_set);
79 $this->setStartFile((string) $lm_rec["startfile"]);
80 }
81
82
83
87 public function create($a_skip_meta = false)
88 {
90
91 parent::create();
92 $this->createDataDirectory();
93
94 $ilDB->manipulate("INSERT INTO file_based_lm (id, startfile) VALUES " .
95 " (" . $ilDB->quote($this->getID(), "integer") . "," .
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
134 public function getDiskUsage()
135 {
136 require_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php");
138 }
139
140
141
152 public function delete()
153 {
155
156 // always call parent delete function first!!
157 if (!parent::delete()) {
158 return false;
159 }
160
161 // Delete meta data
162 $this->deleteMetaData();
163
164 // delete file_based_lm record
165 $ilDB->manipulate("DELETE FROM file_based_lm WHERE id = " .
166 $ilDB->quote($this->getID(), "integer"));
167
168 // delete data directory
170
171 return true;
172 }
173
183 public function populateByDirectoy($a_dir, $a_filename = "")
184 {
185 preg_match("/.*htlm_([0-9]*)\.zip/", $a_filename, $match);
186 if (is_dir($a_dir . "/htlm_" . $match[1])) {
187 $a_dir = $a_dir . "/htlm_" . $match[1];
188 }
189 ilUtil::rCopy($a_dir, $this->getDataDirectory());
191 }
192
199 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
200 {
201 $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
202 $this->cloneMetaData($new_obj);
203
204 //copy online status if object is not the root copy object
205 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
206
207 if (!$cp_options->isRootNode($this->getRefId())) {
208 $new_obj->setOfflineStatus($this->getOfflineStatus());
209 }
210
211 // copy content
212 $new_obj->populateByDirectoy($this->getDataDirectory());
213
214 $new_obj->setStartFile($this->getStartFile());
215 $new_obj->update();
216
217 return $new_obj;
218 }
219}
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.
create($a_skip_meta=false)
create file based lm
getDataDirectory($mode="filesystem")
Class ilObject Basic functions for all objects.
setOfflineStatus($a_status)
Set offline status.
deleteMetaData()
delete meta data entry
updateMetaData()
update meta data entry
getOfflineStatus()
Get offline status.
createMetaData()
create meta data entry
cloneMetaData($target_obj)
Copy meta data.
getId()
get object id @access public
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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 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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilDB
$lm_set
$DIC
Definition: xapitoken.php:46