ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjHelpSettings.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject2.php";
6 
16 {
20  protected $db;
21 
25  protected $settings;
26 
27 
31  public function __construct()
32  {
33  parent::__construct();
34  global $DIC;
35 
36  $this->db = $DIC->database();
37  $this->settings = $DIC->settings();
38  }
39 
43  public function initType()
44  {
45  $this->type = "hlps";
46  }
47 
54  public static function createHelpModule()
55  {
56  global $DIC;
57 
58  $ilDB = $DIC->database();
59 
60  $id = $ilDB->nextId("help_module");
61 
62  $ilDB->manipulate("INSERT INTO help_module " .
63  "(id) VALUES (" .
64  $ilDB->quote($id, "integer") .
65  ")");
66 
67  return $id;
68  }
69 
76  public static function writeHelpModuleLmId($a_id, $a_lm_id)
77  {
78  global $DIC;
79 
80  $ilDB = $DIC->database();
81 
82  $ilDB->manipulate(
83  "UPDATE help_module SET " .
84  " lm_id = " . $ilDB->quote($a_lm_id, "integer") .
85  " WHERE id = " . $ilDB->quote($a_id, "integer")
86  );
87  }
88 
89 
96  public function uploadHelpModule($a_file)
97  {
98  $id = $this->createHelpModule();
99 
100  // create and insert object in objecttree
101  /*include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
102  $newObj = new ilObjContentObject();
103  $newObj->setType("lm");
104  $newObj->setTitle("Help Module");
105  $newObj->create(true);
106  $newObj->createLMTree();*/
107 
108  try {
109  include_once("./Services/Export/classes/class.ilImport.php");
110  $imp = new ilImport();
111  $conf = $imp->getConfig("Services/Help");
112  $conf->setModuleId($id);
113  $new_id = $imp->importObject("", $a_file["tmp_name"], $a_file["name"], "lm", "Modules/LearningModule");
114  $newObj = new ilObjLearningModule($new_id, false);
115 
116  self::writeHelpModuleLmId($id, $newObj->getId());
118  // old import
119  $t = $imp->getTemporaryImportDir();
120 
121  // create and insert object in objecttree
122  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
123  $newObj = new ilObjContentObject();
124  $newObj->setType("lm");
125  $newObj->setTitle("Help Module");
126  $newObj->create(true);
127  $newObj->createLMTree();
128 
129  $mess = $newObj->importFromDirectory($t, false);
130 
131  // this should only be true for help modules
132  // search the zip file
133  $dir = $t;
134  $files = ilUtil::getDir($dir);
135  foreach ($files as $file) {
136  if (is_int(strpos($file["entry"], "__help_")) &&
137  is_int(strpos($file["entry"], ".zip"))) {
138  include_once("./Services/Export/classes/class.ilImport.php");
139  $imp = new ilImport();
140  $imp->getMapping()->addMapping('Services/Help', 'help_module', 0, $id);
141  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
142  $chaps = ilLMObject::getObjectList($newObj->getId(), "st");
143  foreach ($chaps as $chap) {
144  $chap_arr = explode("_", $chap["import_id"]);
145  $imp->getMapping()->addMapping(
146  'Services/Help',
147  'help_chap',
148  $chap_arr[count($chap_arr) - 1],
149  $chap["obj_id"]
150  );
151  }
152  $imp->importEntity(
153  $dir . "/" . $file["entry"],
154  $file["entry"],
155  "help",
156  "Services/Help",
157  true
158  );
159  }
160  }
161 
162  // delete import directory
164 
165  self::writeHelpModuleLmId($id, $newObj->getId());
166  }
167 
168 
169  $GLOBALS['ilAppEventHandler']->raise(
170  'Services/Help',
171  'create',
172  array(
173  'obj_id' => $id,
174  'obj_type' => 'lm'
175  )
176  );
177  }
178 
185  public function getHelpModules()
186  {
187  $ilDB = $this->db;
188 
189  $set = $ilDB->query("SELECT * FROM help_module");
190 
191  $mods = array();
192  while ($rec = $ilDB->fetchAssoc($set)) {
193  if (ilObject::_lookupType($rec["lm_id"]) == "lm") {
194  $rec["title"] = ilObject::_lookupTitle($rec["lm_id"]);
195  $rec["create_date"] = ilObject::_lookupCreationDate($rec["lm_id"]);
196  }
197 
198  $mods[] = $rec;
199  }
200 
201  return $mods;
202  }
203 
210  public static function lookupModuleTitle($a_id)
211  {
212  global $DIC;
213 
214  $ilDB = $DIC->database();
215 
216  $set = $ilDB->query(
217  "SELECT * FROM help_module " .
218  " WHERE id = " . $ilDB->quote($a_id, "integer")
219  );
220  $rec = $ilDB->fetchAssoc($set);
221  if (ilObject::_lookupType($rec["lm_id"]) == "lm") {
222  return ilObject::_lookupTitle($rec["lm_id"]);
223  }
224  return "";
225  }
226 
233  public static function lookupModuleLmId($a_id)
234  {
235  global $DIC;
236 
237  $ilDB = $DIC->database();
238 
239  $set = $ilDB->query(
240  "SELECT lm_id FROM help_module " .
241  " WHERE id = " . $ilDB->quote($a_id, "integer")
242  );
243  $rec = $ilDB->fetchAssoc($set);
244  return $rec["lm_id"];
245  }
246 
253  public function deleteModule($a_id)
254  {
255  $ilDB = $this->db;
257 
258  // if this is the currently activated one, deactivate it first
259  if ($a_id == (int) $ilSetting->get("help_module")) {
260  $ilSetting->set("help_module", "");
261  }
262 
263  $set = $ilDB->query(
264  "SELECT * FROM help_module " .
265  " WHERE id = " . $ilDB->quote($a_id, "integer")
266  );
267  $rec = $ilDB->fetchAssoc($set);
268 
269  // delete learning module
270  if (ilObject::_lookupType($rec["lm_id"]) == "lm") {
271  include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
272  $lm = new ilObjLearningModule($rec["lm_id"], false);
273  $lm->delete();
274  }
275 
276  // delete mappings
277  include_once("./Services/Help/classes/class.ilHelpMapping.php");
279 
280  // delete tooltips
281  include_once("./Services/Help/classes/class.ilHelp.php");
283 
284  // delete help module record
285  $ilDB->manipulate("DELETE FROM help_module WHERE " .
286  " id = " . $ilDB->quote($a_id, "integer"));
287  }
288 
295  public static function isHelpLM($a_lm_id)
296  {
297  global $DIC;
298 
299  $ilDB = $DIC->database();
300 
301  $set = $ilDB->query(
302  "SELECT id FROM help_module " .
303  " WHERE lm_id = " . $ilDB->quote($a_lm_id, "integer")
304  );
305  if ($rec = $ilDB->fetchAssoc($set)) {
306  return true;
307  }
308  return false;
309  }
310 }
$files
Definition: add-vimline.php:18
Class ilObjLearningModule.
static deleteEntriesOfModule($a_id)
Delete entries of module.
global $DIC
Definition: saml.php:7
deleteModule($a_id)
Delete module.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Import class.
static _lookupTitle($a_id)
lookup object title
static isHelpLM($a_lm_id)
Check if LM is a help LM.
static deleteTooltipsOfModule($a_id)
Delete tooltips of module.
static lookupModuleTitle($a_id)
lookup module title
Help settings application class.
static writeHelpModuleLmId($a_id, $a_lm_id)
Write help module lm id.
static _lookupCreationDate($a_id)
Lookup creation date.
uploadHelpModule($a_file)
Upload help file.
manifest.xml file not found-exception for import
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getHelpModules()
Get help modules.
static lookupModuleLmId($a_id)
lookup module lm id
settings()
Definition: settings.php:2
global $ilSetting
Definition: privfeed.php:17
global $ilDB
Class ilObject2 This is an intermediate progress of ilObject class.
static createHelpModule()
Create help module.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class ilObjContentObject.
static getObjectList($lm_id, $type="")
static
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively