ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjFileBasedLM.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected ?string $start_file = null;
26  protected bool $online;
27 
28  public function __construct(
29  int $a_id = 0,
30  bool $a_call_by_reference = true
31  ) {
32  global $DIC;
33 
34 
35  $this->db = $DIC->database();
36  // this also calls read() method! (if $a_id is set)
37  $this->type = "htlm";
38  parent::__construct($a_id, $a_call_by_reference);
39  }
40 
41  public function update(bool $a_skip_meta = false): bool
42  {
43  $ilDB = $this->db;
44 
45  if (!$a_skip_meta) {
46  $this->updateMetaData();
47  }
48  parent::update();
49 
50  $ilDB->manipulate($q = "UPDATE file_based_lm SET " .
51  " startfile = " . $ilDB->quote($this->getStartFile(), "text") . " " .
52  " WHERE id = " . $ilDB->quote($this->getId(), "integer"));
53  return true;
54  }
55 
56  public function read(): void
57  {
58  $ilDB = $this->db;
59 
60  parent::read();
61 
62  $q = "SELECT * FROM file_based_lm WHERE id = " . $ilDB->quote($this->getId(), "integer");
63  $lm_set = $ilDB->query($q);
64  $lm_rec = $ilDB->fetchAssoc($lm_set);
65  $this->setStartFile((string) $lm_rec["startfile"]);
66  }
67 
68  public function create(bool $a_skip_meta = false): int
69  {
70  $ilDB = $this->db;
71 
72  $id = parent::create();
73  $this->createDataDirectory();
74 
75  $ilDB->manipulate("INSERT INTO file_based_lm (id, startfile) VALUES " .
76  " (" . $ilDB->quote($this->getId(), "integer") . "," .
77  $ilDB->quote($this->getStartFile(), "text") . ")");
78  if (!$a_skip_meta) {
79  $this->createMetaData();
80  }
81  return $id;
82  }
83 
84  public function getDataDirectory(string $mode = "filesystem"): string
85  {
86  $lm_data_dir = ilFileUtils::getWebspaceDir($mode) . "/lm_data";
87  $lm_dir = $lm_data_dir . "/lm_" . $this->getId();
88 
89  return $lm_dir;
90  }
91 
92  public function createDataDirectory(): void
93  {
95  }
96 
97  public function getStartFile(): ?string
98  {
99  return $this->start_file;
100  }
101 
102  public function setStartFile(
103  string $a_file,
104  bool $a_omit_file_check = false
105  ): void {
106  if ($a_file &&
107  (file_exists($this->getDataDirectory() . "/" . $a_file) || $a_omit_file_check)) {
108  $this->start_file = $a_file;
109  }
110  }
111 
112 
113  public function delete(): bool
114  {
115  $ilDB = $this->db;
116 
117  // always call parent delete function first!!
118  if (!parent::delete()) {
119  return false;
120  }
121 
122  // Delete meta data
123  $this->deleteMetaData();
124 
125  // delete file_based_lm record
126  $ilDB->manipulate("DELETE FROM file_based_lm WHERE id = " .
127  $ilDB->quote($this->getId(), "integer"));
128 
129  // delete data directory
131 
132  return true;
133  }
134 
141  public function populateByDirectoy(
142  string $a_dir,
143  string $a_filename = ""
144  ): void {
145  preg_match("/.*htlm_([0-9]*)\.zip/", $a_filename, $match);
146  if (is_dir($a_dir . "/htlm_" . ($match[1] ?? ""))) {
147  $a_dir .= "/htlm_" . ($match[1] ?? "");
148  }
149  ilFileUtils::rCopy($a_dir, $this->getDataDirectory());
151  }
152 
153  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
154  {
156  $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
157  $this->cloneMetaData($new_obj);
158 
159  //copy online status if object is not the root copy object
160  $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
161 
162  if (!$cp_options->isRootNode($this->getRefId())) {
163  $new_obj->setOfflineStatus($this->getOfflineStatus());
164  } else {
165  $new_obj->setOfflineStatus(true);
166  }
167 
168  // copy content
169  $new_obj->populateByDirectoy($this->getDataDirectory());
170 
171  $new_obj->setStartFile((string) $this->getStartFile());
172  $new_obj->update();
173 
174  return $new_obj;
175  }
176 
177  public function isInfoEnabled(): bool
178  {
180  }
181 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
__construct(int $a_id=0, bool $a_call_by_reference=true)
update(bool $a_skip_meta=false)
getDataDirectory(string $mode="filesystem")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $DIC
Definition: feed.php:28
static renameExecutables(string $a_dir)
setStartFile(string $a_file, bool $a_omit_file_check=false)
cloneMetaData(ilObject $target_obj)
Copy meta data.
__construct(VocabulariesInterface $vocabularies)
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
ilDBInterface $db
create(bool $a_skip_meta=false)
$lm_set
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$q
Definition: shib_logout.php:21
static _getInstance(int $a_copy_id)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
populateByDirectoy(string $a_dir, string $a_filename="")
Populate by directory.