ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
19  //db fields
20  private $id = null;
21  private $seqNodeId = null;
22  private $treeNodeId = null;
23  private $sequencingId = null;
24  private $nocopy = false;
25  private $nodelete = false;
26  private $nomove = false;
27  private $importId = null;
28  private $seqXml = null;
29  private $importSeqXml = null;
30  private $rootLevel = false;
31 
32  protected $dom = null;
33 
37  protected $log;
38 
43  function __construct($a_treeid = null , $a_rootlevel = false)
44  {
45  $this->log = ilLoggerFactory::getLogger("sc13");
46 
47  //different handling for organization level
48  $this->rootLevel = $a_rootlevel;
49 
50  if ($a_treeid != null)
51  {
52  $this->treeNodeId = $a_treeid;
53  $this->loadItem();
54  $this->dom = new DOMDocument();
55  $this->initDom();
56  }
57  }
58 
59  // **********************
60  // GETTER METHODS
61  // **********************
62 
63  public function getSeqNodeId()
64  {
65  return $this->seqNodeId;
66  }
67 
68  public function getTreeNodeId()
69  {
70  return $this->treeNodeId;
71  }
72 
73 
74  public function getSequencingId()
75  {
76  return $this->sequencingId;
77  }
78 
79  public function getImportId()
80  {
81  return $this->importId;
82  }
83  public function getNocopy()
84  {
85  return $this->nocopy;
86  }
87 
88  public function getNodelete()
89  {
90  return $this->nodelete;
91  }
92 
93  public function getNomove()
94  {
95  return $this->nomove;
96  }
97 
98  public function getSeqXml()
99  {
100  return $this->seqXml;
101  }
102 
103  public function getRoolLevel()
104  {
105  return $this->rootLevel;
106  }
107 
113  function getImportSeqXml()
114  {
115  return $this->importSeqXml;
116  }
117 
118  // **********************
119  // Setter METHODS
120  // **********************
121 
127  function setImportSeqXml($a_val)
128  {
129  $this->importSeqXml = $a_val;
130  }
131 
132  public function setSeqNodeId($a_seqnodeid)
133  {
134  $this->seqNodeId = $a_seqnodeid;
135  }
136 
137  public function setTreeNodeId($a_tree_node)
138  {
139  $this->treeNodeId = $a_tree_node;
140  }
141 
142  public function setSequencingId($a_seq_id)
143  {
144  $this->sequencingId = $a_seq_id;
145  }
146 
147  public function setNocopy($a_nocopy)
148  {
149  $this->nocopy = $a_nocopy;
150  }
151 
152  public function setNodelete($a_nodelete)
153  {
154  $this->nodelete = $a_nodelete ;
155  }
156 
157  public function setNomove($a_nomove)
158  {
159  $this->nomove = $a_nomove;
160  }
161 
162  public function setImportId($a_importid)
163  {
164  $this->importid = $a_importid;
165  }
166 
167  public function setSeqXml($a_seqxml)
168  {
169  $this->log->debug("seq xml: ".$a_seqxml);
170  $this->seqXml = $a_seqxml;
171  }
172 
173  public function setDom($a_dom)
174  {
175  $this->dom = $a_dom;
176  }
177 
178  public function setRootLevel($a_rootlevel)
179  {
180  $this->rootLevel = $a_rootlevel;
181  }
182 
183  public static function getAllowedActions($a_node_id)
184  {
185  global $ilDB,$ilLog;
186  $query = "SELECT * FROM sahs_sc13_seq_item WHERE sahs_sc13_tree_node_id = ".
187  $ilDB->quote($a_node_id, "integer").
188  " AND rootlevel = ".$ilDB->quote(false, "integer");
189  $obj_set = $ilDB->query($query);
190  $obj_rec = $obj_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
191  return array("copy"=>!$obj_rec['nocopy'],"move"=>!$obj_rec['nomove'],"delete"=>!$obj_rec['nodelete']);
192  }
193 
197  function initDom()
198  {
199  if ($this->getSeqXml() != "")
200  {
201  $this->dom->loadXML($this->getSeqXml());
202  }
203  else
204  {
205  $this->setDefaultXml();
206  }
207  }
208 
214  function setDefaultXml($a_def_control_mode= false)
215  {
216  while ($this->dom->hasChildNodes()){
217  $this->dom->removeChild($this->dom->childNodes->item(0));
218  }
219 
220  $element = $this->dom->createElement('sequencing');
221  $this->dom->appendChild($element);
222 
223  if ($a_def_control_mode)
224  {
225  $cm = $this->dom->createElement('controlMode');
226  $cm->setAttribute("flow", "true");
227  $cm->setAttribute("choice", "true");
228  $cm->setAttribute("forwardOnly", "false");
229  $element->appendChild($cm);
230  }
231  $this->setSeqXml($this->dom->saveXML());
232  }
233 
234 
240  public function exportAsXML($add_prefix = true)
241  {
242  // remove titles
243  // @todo: the objectives (titles) text should be stored outside of
244  // the sequencing information in the future
245  $xpath_obj = new DOMXPath($this->dom);
246  $obj_node_list = $xpath_obj->query('//objective | //primaryObjective');
247  for ($i=0;$i<$obj_node_list->length;$i++) {
248  $obj_node_list->item($i)->removeAttribute("title");
249  }
250  $output = $this->dom->saveXML();
251 
252  $output = preg_replace('/<\?xml version="1.0"\?>/','',$output);
253  if ($add_prefix)
254  {
255  $output = preg_replace('/(<)([a-z]+|[A-Z]+)/','<imsss:$2',$output);
256  $output = preg_replace('/(<\/)([a-z]+|[A-Z]+)/','</imsss:$2',$output);
257  }
258  $output = preg_replace('/\n/','',$output);
259 
260  return $output;
261  }
262 
266  public function loadItem()
267  {
268  global $ilDB;
269  $query = "SELECT * FROM sahs_sc13_seq_item WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
270  " AND rootlevel =".$ilDB->quote($this->rootLevel, "integer").")";
271  $obj_set = $ilDB->query($query);
272  $obj_rec = $ilDB->fetchAssoc($obj_set);
273  $this->seqXml = $obj_rec['seqxml'];
274  $this->importSeqXml = $obj_rec['importseqxml'];
275  $this->importId = $obj_rec['importid'];
276  $this->nocopy = $obj_rec['nocopy'];
277  $this->nomove = $obj_rec['nomove'];
278  $this->nodelete = $obj_rec['nodelete'];
279  }
280 
284  public function update()
285  {
286  $this->insert();
287  }
288 
292  public function delete($a_insert_node = false)
293  {
294  global $ilDB;
295 
296  $query = "DELETE FROM sahs_sc13_seq_item"." WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
297  " AND rootlevel=".$ilDB->quote($this->rootLevel, "integer").")";
298  $obj_set = $ilDB->manipulate($query);
299  }
300 
304  public function insert($import = false)
305  {
306  global $ilDB;
307 
308  $ilDB->replace("sahs_sc13_seq_item",
309  array("sahs_sc13_tree_node_id" => array("integer", $this->treeNodeId),
310  "rootlevel" => array("integer", $this->rootLevel)),
311  array(
312  "importid" => array("text", $this->importId),
313  "seqnodeid" => array("integer", (int) $this->seqNodeId),
314  "sequencingid" => array("text", $this->sequencingId),
315  "nocopy" => array("integer", $this->nocopy),
316  "nodelete" => array("integer", $this->nodelete),
317  "nomove" => array("integer", $this->nomove),
318  "seqxml" => array("clob", $this->dom->saveXML()),
319  "importseqxml" => array("clob", $this->getImportSeqXml())
320  ));
321  return true;
322  }
323 
324 }
325 ?>
Class ilSCORM2004Condition.
loadItem()
Read data from DB into object.
__construct($a_treeid=null, $a_rootlevel=false)
Constructor public.
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.
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.
static getLogger($a_component_id)
Get component logger.
getImportSeqXml()
Get import seq xml.