ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLMChapterImportForm.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
14 protected $tree = null;
15 protected $node_id = null;
16 protected $confirm = false;
17 protected $perform = false;
18
25 function __construct($a_slm, $a_node_id, $a_first_child, $a_confirm = false)
26 {
27 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tree.php");
28 $this->slm = $a_slm;
29 $this->tree = new ilSCORM2004Tree($this->slm->getId());
30 $this->node_id = $a_node_id;
31 $this->node = $this->tree->getNodeData($this->node_id);
32 $this->current_depth = $this->node["depth"];
33 if ($a_first_child)
34 {
35 $this->current_depth++;
36 $this->current_parent = $this->node;
37 }
38 else
39 {
40 $this->current_parent = $this->tree->getNodeData($this->node["parent"]);
41 }
42 if ($this->current_parent["child"] == $this->tree->readRootId())
43 {
44 $this->current_parent["title"] = ilObject::_lookupTitle($this->slm->getId());
45 $this->current_parent["type"] = "sahs";
46 }
47 $this->first_child = $a_first_child;
48 $this->confirm = $a_confirm;
49 $this->correct = true;
50 }
51
58 function isCorrect()
59 {
60 return $this->correct;
61 }
62
63 function performInserts()
64 {
65 // act like in confirm mode
66 $this->confirm = true;
67 $this->perform = true;
68 $this->processHierarchy();
69 }
70
72 {
73 global $ilUser;
74
75 $target = ($this->first_child)
77 : $this->node_id;
78
79 // get chapters
80 $chapters = $ilUser->getClipboardObjects("st", true);
81
82 if ($this->perform)
83 {
84 $this->current_parent["insert_id"] = $this->current_parent["child"];
85 $this->target[$this->current_parent["insert_id"]] = $target;
86 }
87 foreach ($chapters as $chap)
88 {
89 $chap["parent"] = $this->current_parent;
90 $this->addNode($chap, $this->current_parent, $this->current_depth);
91 }
92 }
93
100 function getHTML()
101 {
102 global $ilUser;
103
104 include_once("./Services/UIComponent/NestedList/classes/class.ilNestedList.php");
105 $this->list = new ilNestedList();
106 $this->list->setListClass("noStyle");
107
108 $this->list->addListNode(
109 ilUtil::img(ilUtil::getImagePath("icon_".$this->current_parent["type"].".svg"))." ".
110 $this->current_parent["title"]." ".
111 "",
112 $this->current_parent["id"], 0);
113
114 $this->processHierarchy();
115
116 return $this->list->getHTML();
117 }
118
125 function addNode($a_node, $a_parent, $a_depth)
126 {
127 global $ilUser, $lng;
128
129 //$tpl = new ilTemplate("tpl.lm_chap_import_node.html", true, true, "Modules/Scorm2004");
130 $lng->loadLanguageModule("content");
131
132 $options = array(
133 "" => $lng->txt("cont_assign_to_parent"),
134 "chap" => $lng->txt("obj_chap"),
135 "sco" => $lng->txt("obj_sco"),
136 "ass" => $lng->txt("obj_ass")
137 );
138
139 if (!$this->confirm)
140 {
141 $sel = ($a_node["type"] != "pg")
142 ? $sel = ilUtil::formSelect($_POST["node"][$a_node["id"]], "node[".$a_node["id"]."]", $options, false, true)
143 : "";
144 $img = ilUtil::img(ilUtil::getImagePath("icon_".$a_node["type"].".svg"));
145 }
146 else
147 {
148 // if scos/assets are nested in scos/assets, put the tree one level up
149//echo "<br>-".$a_node["title"]."-".$_POST["node"][$a_node["id"]]."-".$_POST["node"][$a_parent["id"]]."-";
150 if (in_array($_POST["node"][$a_node["id"]], array("sco", "ass")) && in_array($_POST["node"][$a_parent["id"]], array("sco", "ass")))
151 {
152//echo "j";
153//var_dump($a_parent);
154// echo "<br>getting-from-".$a_parent["title"]."-".$a_parent["id"]."-".$a_target."-";
155 $a_parent = $a_parent["parent"];
156 $a_depth--;
157 }
158
159 $sel = ($a_node["type"] != "pg")
160 ? $sel = "<strong>".$lng->txt("obj_".$_POST["node"][$a_node["id"]])."</strong>"
161 : "";
162 $ctype = ($a_node["type"] != "pg")
163 ? $_POST["node"][$a_node["id"]]
164 : "pg";
165
166 $parent_type = $a_parent["type"];
167 if (isset($_POST["node"][$a_parent["id"]]))
168 {
169 $parent_type = $_POST["node"][$a_parent["id"]];
170 }
171//echo "<br>-".$a_node["title"]."-".$parent_type."-";
172 $img = ilUtil::img(ilUtil::getImagePath("icon_".$ctype.".svg"));
173
174 $error = "";
175 switch ($a_depth)
176 {
177 case 0:
178 case 1:
179 $this->correct = false;
180 break;
181
182 case 2:
183 if (!in_array($ctype, array("", "chap", "sco", "ass")))
184 {
185 $error = '<span class="alert">'.$lng->txt("cont_type_not_allowed").": ".$lng->txt("obj_".$ctype)."</span>";
186 if ($_POST["node"][$a_node["id"]] != "" || $a_node["type"] == "pg")
187 {
188 $this->correct = false;
189 }
190 }
191 break;
192
193 default:
194 if ($parent_type == "chap" && !in_array($ctype, array("sco", "ass")) ||
195 ($parent_type != "chap" && !in_array($ctype, array("pg"))))
196 {
197 $error = '<span class="alert">'.$lng->txt("cont_type_not_allowed").": ".$lng->txt("obj_".$ctype)."</span>";
198 if ($_POST["node"][$a_node["id"]] != "" || $a_node["type"] == "pg")
199 {
200 $this->correct = false;
201 }
202 }
203 break;
204 }
205 }
206
207 // if node should be inserted, increase depth
208 if (!$this->confirm || $_POST["node"][$a_node["id"]] != "" || $a_node["type"] == "pg")
209 {
210 if (!$this->perform)
211 {
212 $this->list->addListNode(
213 $img." ".
214 $a_node["title"]." ".
215 $sel." ".$error,
216 $a_node["id"], $a_parent["id"]);
217 }
218 else
219 {
220 if ($a_parent["insert_id"] > 0)
221 {
222 $target = $this->target[$a_parent["insert_id"]];
223
224 // create new node of ctype, put it under parent (respect after node from hierarchy)
225 switch ($ctype)
226 {
227 case "chap":
228 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Chapter.php");
229 $chap = new ilSCORM2004Chapter($this->slm);
230 $chap->setTitle($a_node["title"]);
231 $chap->setSLMId($this->slm->getId());
232 $chap->create();
233 ilSCORM2004Node::putInTree($chap, $a_parent["insert_id"], $target);
234 $a_node["insert_id"] = $chap->getId();
235 break;
236
237 case "ass":
238 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Asset.php");
239 $ass = new ilSCORM2004Asset($this->slm);
240 $ass->setTitle($a_node["title"]);
241 $ass->setSLMId($this->slm->getId());
242 $ass->create();
243 ilSCORM2004Node::putInTree($ass, $a_parent["insert_id"], $target);
244 $a_node["insert_id"] = $ass->getId();
245 break;
246
247 case "sco":
248 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php");
249 $sco = new ilSCORM2004Sco($this->slm);
250 $sco->setTitle($a_node["title"]);
251 $sco->setSLMId($this->slm->getId());
252 $sco->create();
253 ilSCORM2004Node::putInTree($sco, $a_parent["insert_id"], $target);
254 $a_node["insert_id"] = $sco->getId();
255 break;
256
257 case "pg":
258 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
259 $copied_nodes = array();
260 $a_node["insert_id"] = ilSCORM2004Node::pasteTree($this->slm, $a_node["id"], $a_parent["insert_id"], $a_target,
261 $a_node["insert_time"], $copied_nodes,
262 true, true, "lm");
263 break;
264 }
265
266 $this->target[$a_parent["insert_id"]] = $a_node["insert_id"];
267
268 // set $a_node["insert_id"] to new id
269
270 }
271 }
272
273 $a_depth++;
274 $parent = $a_node;
275 }
276 else
277 {
278 $parent = $a_parent;
279 }
280
281 $childs = $ilUser->getClipboardChilds($a_node["id"], $a_node["insert_time"]);
282 foreach ($childs as $c)
283 {
284 $c["parent"] = $a_node;
285// $c["parent_target"] = rand(1,100);
286// echo "<br>setting-".$c["parent_target"]."-into-".$c["id"]."-".$c["title"]."-";
287 $this->addNode($c, $parent, $a_depth);
288 }
289 }
290
291
292
293}
294
295?>
const IL_FIRST_NODE
Definition: class.ilTree.php:5
__construct($a_slm, $a_node_id, $a_first_child, $a_confirm=false)
Constructor.
addNode($a_node, $a_parent, $a_depth)
Add node.
static _lookupTitle($a_id)
lookup object title
Class ilSCORM2004Asset.
Class ilSCORM2004Chapter.
static pasteTree($a_target_slm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy=false, $a_from_clipboard=true, $a_source_parent_type="")
Paste item (tree) from clipboard or other learning module to target scorm learning module.
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
Class ilSCORM2004Sco.
SCORM 2004 Editing tree.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static formSelect($selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15