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