ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
8 require_once "./Services/Object/classes/class.ilObject.php";
9 //require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
10 
21 {
22  var $tree;
23 
24  protected $online; // [bool]
25  protected $show_license; // [bool]
26  protected $show_bib; // [bool]
27 
34  function ilObjFileBasedLM($a_id = 0,$a_call_by_reference = true)
35  {
36  // this also calls read() method! (if $a_id is set)
37  $this->type = "htlm";
38  $this->ilObject($a_id,$a_call_by_reference);
39 
40  $this->setShowLicense(false);
41  $this->setShowBibliographicalData(false);
42  }
43 
44 
51  function update()
52  {
53  global $ilDB;
54 
55  $this->updateMetaData();
56  parent::update();
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  ", show_lic = ".$ilDB->quote($this->getShowLicense(), "integer")." ".
62  ", show_bib = ".$ilDB->quote($this->getShowBibliographicalData(), "integer")." ".
63  " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
64  return true;
65  }
66 
70  function read()
71  {
72  global $ilDB;
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->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
80  $this->setStartFile((string) $lm_rec["startfile"]);
81  $this->setShowLicense($lm_rec["show_lic"]);
82  $this->setShowBibliographicalData($lm_rec["show_bib"]);
83  }
84 
88  function initBibItemObject()
89  {
90  include_once("./Modules/LearningModule/classes/class.ilBibItem.php");
91 
92  $this->bib_obj =& new ilBibItem($this);
93  $this->bib_obj->read();
94 
95  return true;
96  }
97 
98 
102  function create()
103  {
104  global $ilDB;
105 
106  parent::create();
107  $this->createDataDirectory();
108 
109  $ilDB->manipulate("INSERT INTO file_based_lm (id, is_online, startfile) VALUES ".
110  " (".$ilDB->quote($this->getID(), "integer").",".
111  $ilDB->quote("n", "text").",".
112  $ilDB->quote($this->getStartfile(), "text").")");
113 
114  $this->createMetaData();
115  }
116 
117  function getDataDirectory($mode = "filesystem")
118  {
119  $lm_data_dir = ilUtil::getWebspaceDir($mode)."/lm_data";
120  $lm_dir = $lm_data_dir."/lm_".$this->getId();
121 
122  return $lm_dir;
123  }
124 
126  {
128  }
129 
130  function getStartFile()
131  {
132  return $this->start_file;
133  }
134 
135  function setStartFile($a_file, $a_omit_file_check = false)
136  {
137  if($a_file &&
138  (file_exists($this->getDataDirectory()."/".$a_file) || $a_omit_file_check))
139  {
140  $this->start_file = $a_file;
141  }
142  }
143 
144  function setOnline($a_online)
145  {
146  $this->online = $a_online;
147  }
148 
149  function getOnline()
150  {
151  return $this->online;
152  }
153 
154  function setShowLicense($a_value)
155  {
156  $this->show_license = (bool)$a_value;
157  }
158 
159  function getShowLicense()
160  {
161  return $this->show_license;
162  }
163 
164  function setShowBibliographicalData($a_value)
165  {
166  $this->show_bib = (bool)$a_value;
167  }
168 
170  {
171  return $this->show_bib;
172  }
173 
177  function _lookupOnline($a_id)
178  {
179  global $ilDB;
180 
181  $q = "SELECT * FROM file_based_lm WHERE id = ".$ilDB->quote($a_id, "integer");
182  $lm_set = $ilDB->query($q);
183  $lm_rec = $ilDB->fetchAssoc($lm_set);
184 
185  return ilUtil::yn2tf($lm_rec["is_online"]);
186  }
187 
194  function getDiskUsage()
195  {
196  require_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php");
198  }
199 
200 
201 
212  function delete()
213  {
214  global $ilDB;
215 
216  // always call parent delete function first!!
217  if (!parent::delete())
218  {
219  return false;
220  }
221 
222  // delete meta data of content object
223 /*
224  $nested = new ilNestedSetXML();
225  $nested->init($this->getId(), $this->getType());
226  $nested->deleteAllDBData();
227 */
228 
229  // Delete meta data
230  $this->deleteMetaData();
231 
232  // delete bibliographical items of object
233  include_once("./Services/Xml/classes/class.ilNestedSetXML.php");
234  $nested = new ilNestedSetXML();
235  $nested->init($this->getId(), "bib");
236  $nested->deleteAllDBData();
237 
238  // delete file_based_lm record
239  $ilDB->manipulate("DELETE FROM file_based_lm WHERE id = ".
240  $ilDB->quote($this->getID(), "integer"));
241 
242  // delete data directory
244 
245  return true;
246  }
247 
248 
262  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
263  {
264  global $tree;
265 
266  switch ($a_event)
267  {
268  case "link":
269 
270  //var_dump("<pre>",$a_params,"</pre>");
271  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
272  //exit;
273  break;
274 
275  case "cut":
276 
277  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
278  //exit;
279  break;
280 
281  case "copy":
282 
283  //var_dump("<pre>",$a_params,"</pre>");
284  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
285  //exit;
286  break;
287 
288  case "paste":
289 
290  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
291  //exit;
292  break;
293 
294  case "new":
295 
296  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
297  //exit;
298  break;
299  }
300 
301  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
302  if ($a_node_id==$_GET["ref_id"])
303  {
304  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
305  $parent_type = $parent_obj->getType();
306  if($parent_type == $this->getType())
307  {
308  $a_node_id = (int) $tree->getParentId($a_node_id);
309  }
310  }
311 
312  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
313  }
314 
324  function populateByDirectoy($a_dir, $a_filename = "")
325  {
326  preg_match("/.*htlm_([0-9]*)\.zip/", $a_filename, $match);
327  if (is_dir($a_dir."/htlm_".$match[1]))
328  {
329  $a_dir = $a_dir."/htlm_".$match[1];
330  }
331  ilUtil::rCopy($a_dir, $this->getDataDirectory());
333  }
334 
341  public function cloneObject($a_target_id,$a_copy_id = 0)
342  {
343  global $ilDB, $ilUser, $ilias;
344 
345  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
346  $this->cloneMetaData($new_obj);
347 
348  //copy online status if object is not the root copy object
349  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
350 
351  if(!$cp_options->isRootNode($this->getRefId()))
352  {
353  $new_obj->setOnline($this->getOnline());
354  }
355 
356  $new_obj->setTitle($this->getTitle());
357  $new_obj->setDescription($this->getDescription());
358  $new_obj->setShowLicense($this->getShowLicense());
359  $new_obj->setShowBibliographicalData($this->getShowBibliographicalData());
360 
361  // copy content
362  $new_obj->populateByDirectoy($this->getDataDirectory());
363 
364  $new_obj->setStartFile($this->getStartFile());
365  $new_obj->update();
366 
367  return $new_obj;
368  }
369 
370 }
371 ?>
getDataDirectory($mode="filesystem")
static tf2yn($a_tf)
convert true/false to "y"/"n"
Class NestedSetXML functions for storing XML-Data into nested-set-database-strcture.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
_lookupDiskUsage($a_id)
Returns the number of bytes used on the harddisk by the learning module with the specified object id...
$_GET["client_id"]
Class ilBibItem.
updateMetaData()
update meta data entry
update()
update object data
Class ilObject Basic functions for all objects.
File Based Learning Module (HTML) object.
createMetaData()
create meta data entry
ilObject($a_id=0, $a_reference=true)
Constructor public.
setStartFile($a_file, $a_omit_file_check=false)
notify($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
notifys an object about an event occured Based on the event happend, each object may decide how it re...
static _getInstance($a_copy_id)
Get instance of copy wizard options.
getId()
get object id public
getTitle()
get object title public
getDescription()
get object description
redirection script todo: (a better solution should control the processing via a xml file) ...
cloneMetaData($target_obj)
Copy meta data.
cloneObject($a_target_id, $a_copy_id=0)
Clone HTML learning module.
getDiskUsage()
Gets the disk usage of the object in bytes.
initBibItemObject()
init bib object (contains all bib item data)
getType()
get object type public
create()
create file based lm
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$lm_set
global $ilUser
Definition: imgupload.php:15
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
global $ilDB
deleteMetaData()
delete meta data entry
_lookupOnline($a_id)
check wether content object is online
static yn2tf($a_yn)
convert "y"/"n" to true/false
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
ilObjFileBasedLM($a_id=0, $a_call_by_reference=true)
Constructor public.
populateByDirectoy($a_dir, $a_filename="")
Populate by directory.