ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSCORM2004Item.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004SeqNode.php");
6 
18 {
22  protected $db;
23 
24  //db fields
25  private $id = null;
26  private $seqNodeId = null;
27  private $treeNodeId = null;
28  private $sequencingId = null;
29  private $nocopy = false;
30  private $nodelete = false;
31  private $nomove = false;
32  private $importId = null;
33  private $seqXml = null;
34  private $importSeqXml = null;
35  private $rootLevel = false;
36 
37  protected $dom = null;
38 
42  protected $log;
43 
48  public function __construct($a_treeid = null, $a_rootlevel = false)
49  {
50  global $DIC;
51 
52  $this->db = $DIC->database();
53  $this->log = ilLoggerFactory::getLogger("sc13");
54 
55  //different handling for organization level
56  $this->rootLevel = $a_rootlevel;
57 
58  if ($a_treeid != null) {
59  $this->treeNodeId = $a_treeid;
60  $this->loadItem();
61  $this->dom = new DOMDocument();
62  $this->initDom();
63  }
64  }
65 
66  // **********************
67  // GETTER METHODS
68  // **********************
69 
70  public function getSeqNodeId()
71  {
72  return $this->seqNodeId;
73  }
74 
75  public function getTreeNodeId()
76  {
77  return $this->treeNodeId;
78  }
79 
80 
81  public function getSequencingId()
82  {
83  return $this->sequencingId;
84  }
85 
86  public function getImportId()
87  {
88  return $this->importId;
89  }
90  public function getNocopy()
91  {
92  return $this->nocopy;
93  }
94 
95  public function getNodelete()
96  {
97  return $this->nodelete;
98  }
99 
100  public function getNomove()
101  {
102  return $this->nomove;
103  }
104 
105  public function getSeqXml()
106  {
107  return $this->seqXml;
108  }
109 
110  public function getRoolLevel()
111  {
112  return $this->rootLevel;
113  }
114 
120  public function getImportSeqXml()
121  {
122  return $this->importSeqXml;
123  }
124 
125  // **********************
126  // Setter METHODS
127  // **********************
128 
134  public function setImportSeqXml($a_val)
135  {
136  $this->importSeqXml = $a_val;
137  }
138 
139  public function setSeqNodeId($a_seqnodeid)
140  {
141  $this->seqNodeId = $a_seqnodeid;
142  }
143 
144  public function setTreeNodeId($a_tree_node)
145  {
146  $this->treeNodeId = $a_tree_node;
147  }
148 
149  public function setSequencingId($a_seq_id)
150  {
151  $this->sequencingId = $a_seq_id;
152  }
153 
154  public function setNocopy($a_nocopy)
155  {
156  $this->nocopy = $a_nocopy;
157  }
158 
159  public function setNodelete($a_nodelete)
160  {
161  $this->nodelete = $a_nodelete ;
162  }
163 
164  public function setNomove($a_nomove)
165  {
166  $this->nomove = $a_nomove;
167  }
168 
169  public function setImportId($a_importid)
170  {
171  $this->importid = $a_importid;
172  }
173 
174  public function setSeqXml($a_seqxml)
175  {
176  $this->log->debug("seq xml: " . $a_seqxml);
177  $this->seqXml = $a_seqxml;
178  }
179 
180  public function setDom($a_dom)
181  {
182  $this->dom = $a_dom;
183  }
184 
185  public function setRootLevel($a_rootlevel)
186  {
187  $this->rootLevel = $a_rootlevel;
188  }
189 
190  public static function getAllowedActions($a_node_id)
191  {
192  global $DIC;
193 
194  $ilDB = $DIC->database();
195  $ilLog = $DIC["ilLog"];
196  $query = "SELECT * FROM sahs_sc13_seq_item WHERE sahs_sc13_tree_node_id = " .
197  $ilDB->quote($a_node_id, "integer") .
198  " AND rootlevel = " . $ilDB->quote(false, "integer");
199  $obj_set = $ilDB->query($query);
200  $obj_rec = $obj_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
201  return array("copy"=>!$obj_rec['nocopy'],"move"=>!$obj_rec['nomove'],"delete"=>!$obj_rec['nodelete']);
202  }
203 
207  public function initDom()
208  {
209  if ($this->getSeqXml() != "") {
210  $this->dom->loadXML($this->getSeqXml());
211  } else {
212  $this->setDefaultXml();
213  }
214  }
215 
221  public function setDefaultXml($a_def_control_mode= false)
222  {
223  while ($this->dom->hasChildNodes()) {
224  $this->dom->removeChild($this->dom->childNodes->item(0));
225  }
226 
227  $element = $this->dom->createElement('sequencing');
228  $this->dom->appendChild($element);
229 
230  if ($a_def_control_mode) {
231  $cm = $this->dom->createElement('controlMode');
232  $cm->setAttribute("flow", "true");
233  $cm->setAttribute("choice", "true");
234  $cm->setAttribute("forwardOnly", "false");
235  $element->appendChild($cm);
236  }
237  $this->setSeqXml($this->dom->saveXML());
238  }
239 
240 
246  public function exportAsXML($add_prefix = true)
247  {
248  // remove titles
249  // @todo: the objectives (titles) text should be stored outside of
250  // the sequencing information in the future
251  $xpath_obj = new DOMXPath($this->dom);
252  $obj_node_list = $xpath_obj->query('//objective | //primaryObjective');
253  for ($i=0;$i<$obj_node_list->length;$i++) {
254  $obj_node_list->item($i)->removeAttribute("title");
255  }
256  $output = $this->dom->saveXML();
257 
258  $output = preg_replace('/<\?xml version="1.0"\?>/', '', $output);
259  if ($add_prefix) {
260  $output = preg_replace('/(<)([a-z]+|[A-Z]+)/', '<imsss:$2', $output);
261  $output = preg_replace('/(<\/)([a-z]+|[A-Z]+)/', '</imsss:$2', $output);
262  }
263  $output = preg_replace('/\n/', '', $output);
264 
265  return $output;
266  }
267 
271  public function loadItem()
272  {
273  $ilDB = $this->db;
274  $query = "SELECT * FROM sahs_sc13_seq_item WHERE (sahs_sc13_tree_node_id = " . $ilDB->quote($this->treeNodeId, "integer") .
275  " AND rootlevel =" . $ilDB->quote($this->rootLevel, "integer") . ")";
276  $obj_set = $ilDB->query($query);
277  $obj_rec = $ilDB->fetchAssoc($obj_set);
278  $this->seqXml = $obj_rec['seqxml'];
279  $this->importSeqXml = $obj_rec['importseqxml'];
280  $this->importId = $obj_rec['importid'];
281  $this->nocopy = $obj_rec['nocopy'];
282  $this->nomove = $obj_rec['nomove'];
283  $this->nodelete = $obj_rec['nodelete'];
284  }
285 
289  public function update()
290  {
291  $this->insert();
292  }
293 
297  public function delete($a_insert_node = false)
298  {
299  $ilDB = $this->db;
300 
301  $query = "DELETE FROM sahs_sc13_seq_item" . " WHERE (sahs_sc13_tree_node_id = " . $ilDB->quote($this->treeNodeId, "integer") .
302  " AND rootlevel=" . $ilDB->quote($this->rootLevel, "integer") . ")";
303  $obj_set = $ilDB->manipulate($query);
304  }
305 
309  public function insert($import = false)
310  {
311  $ilDB = $this->db;
312 
313  $ilDB->replace(
314  "sahs_sc13_seq_item",
315  array("sahs_sc13_tree_node_id" => array("integer", $this->treeNodeId),
316  "rootlevel" => array("integer", $this->rootLevel)),
317  array(
318  "importid" => array("text", $this->importId),
319  "seqnodeid" => array("integer", (int) $this->seqNodeId),
320  "sequencingid" => array("text", $this->sequencingId),
321  "nocopy" => array("integer", $this->nocopy),
322  "nodelete" => array("integer", $this->nodelete),
323  "nomove" => array("integer", $this->nomove),
324  "seqxml" => array("clob", $this->dom->saveXML()),
325  "importseqxml" => array("clob", $this->getImportSeqXml())
326  )
327  );
328  return true;
329  }
330 }
Class ilSCORM2004Condition.
loadItem()
Read data from DB into object.
__construct($a_treeid=null, $a_rootlevel=false)
Constructor public.
global $DIC
Definition: saml.php:7
setRootLevel($a_rootlevel)
setSeqNodeId($a_seqnodeid)
static getAllowedActions($a_node_id)
setImportSeqXml($a_val)
Set import seq xml.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
insert($import=false)
Insert/replace sequencing item in db.
$query
exportAsXML($add_prefix=true)
Get sequencing information for export (use imsss namespace prefix)
setTreeNodeId($a_tree_node)
Create styles array
The data for the language used.
global $ilDB
setDefaultXml($a_def_control_mode=false)
Set default xml.
$i
Definition: disco.tpl.php:19
static getLogger($a_component_id)
Get component logger.
getImportSeqXml()
Get import seq xml.