ILIAS  release_4-4 Revision
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 
38  function ilSCORM2004Item($a_treeid = null , $a_rootlevel = false)
39  {
40  //different handling for organization level
41  $this->rootLevel = $a_rootlevel;
42 
43  if ($a_treeid != null)
44  {
45  $this->treeNodeId = $a_treeid;
46  $this->loadItem();
47  $this->dom = new DOMDocument();
48  $this->initDom();
49  }
50  }
51 
52  // **********************
53  // GETTER METHODS
54  // **********************
55 
56  public function getSeqNodeId()
57  {
58  return $this->seqNodeId;
59  }
60 
61  public function getTreeNodeId()
62  {
63  return $this->treeNodeId;
64  }
65 
66 
67  public function getSequencingId()
68  {
69  return $this->sequencingId;
70  }
71 
72  public function getImportId()
73  {
74  return $this->importId;
75  }
76  public function getNocopy()
77  {
78  return $this->nocopy;
79  }
80 
81  public function getNodelete()
82  {
83  return $this->nodelete;
84  }
85 
86  public function getNomove()
87  {
88  return $this->nomove;
89  }
90 
91  public function getSeqXml()
92  {
93  return $this->seqXml;
94  }
95 
96  public function getRoolLevel()
97  {
98  return $this->rootLevel;
99  }
100 
106  function getImportSeqXml()
107  {
108  return $this->importSeqXml;
109  }
110 
111  // **********************
112  // Setter METHODS
113  // **********************
114 
120  function setImportSeqXml($a_val)
121  {
122  $this->importSeqXml = $a_val;
123  }
124 
125  public function setSeqNodeId($a_seqnodeid)
126  {
127  $this->seqNodeId = $a_seqnodeid;
128  }
129 
130  public function setTreeNodeId($a_tree_node)
131  {
132  $this->treeNodeId = $a_tree_node;
133  }
134 
135  public function setSequencingId($a_seq_id)
136  {
137  $this->sequencingId = $a_seq_id;
138  }
139 
140  public function setNocopy($a_nocopy)
141  {
142  $this->nocopy = $a_nocopy;
143  }
144 
145  public function setNodelete($a_nodelete)
146  {
147  $this->nodelete = $a_nodelete ;
148  }
149 
150  public function setNomove($a_nomove)
151  {
152  $this->nomove = $a_nomove;
153  }
154 
155  public function setImportId($a_importid)
156  {
157  $this->importid = $a_importid;
158  }
159 
160  public function setSeqXml($a_seqxml)
161  {
162  $this->seqXml = $a_seqxml;
163  }
164 
165  public function setDom($a_dom)
166  {
167  $this->dom = $a_dom;
168  }
169 
170  public function setRootLevel($a_rootlevel)
171  {
172  $this->rootLevel = $a_rootlevel;
173  }
174 
175  public static function getAllowedActions($a_node_id)
176  {
177  global $ilDB,$ilLog;
178  $query = "SELECT * FROM sahs_sc13_seq_item WHERE sahs_sc13_tree_node_id = ".
179  $ilDB->quote($a_node_id, "integer").
180  " AND rootlevel = ".$ilDB->quote(false, "integer");
181  $obj_set = $ilDB->query($query);
182  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
183  return array("copy"=>!$obj_rec['nocopy'],"move"=>!$obj_rec['nomove'],"delete"=>!$obj_rec['nodelete']);
184  }
185 
189  function initDom()
190  {
191  if ($this->getSeqXml() != "")
192  {
193  $this->dom->loadXML($this->getSeqXml());
194  }
195  else
196  {
197  $element = $this->dom->createElement('sequencing');
198  $this->dom->appendChild($element);
199  $this->setSeqXml($this->dom->saveXML());
200  }
201  }
202 
203 
209  public function exportAsXML($add_prefix = true)
210  {
211  // remove titles
212  // @todo: the objectives (titles) text should be stored outside of
213  // the sequencing information in the future
214  $xpath_obj = new DOMXPath($this->dom);
215  $obj_node_list = $xpath_obj->query('//objective | //primaryObjective');
216  for ($i=0;$i<$obj_node_list->length;$i++) {
217  $obj_node_list->item($i)->removeAttribute("title");
218  }
219  $output = $this->dom->saveXML();
220 
221  $output = preg_replace('/<\?xml version="1.0"\?>/','',$output);
222  if ($add_prefix)
223  {
224  $output = preg_replace('/(<)([a-z]+|[A-Z]+)/','<imsss:$2',$output);
225  $output = preg_replace('/(<\/)([a-z]+|[A-Z]+)/','</imsss:$2',$output);
226  }
227  $output = preg_replace('/\n/','',$output);
228 
229  return $output;
230  }
231 
235  public function loadItem()
236  {
237  global $ilDB;
238  $query = "SELECT * FROM sahs_sc13_seq_item WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
239  " AND rootlevel =".$ilDB->quote($this->rootLevel, "integer").")";
240  $obj_set = $ilDB->query($query);
241  $obj_rec = $ilDB->fetchAssoc($obj_set);
242  $this->seqXml = $obj_rec['seqxml'];
243  $this->importSeqXml = $obj_rec['importseqxml'];
244  $this->importId = $obj_rec['importid'];
245  $this->nocopy = $obj_rec['nocopy'];
246  $this->nomove = $obj_rec['nomove'];
247  $this->nodelete = $obj_rec['nodelete'];
248  }
249 
253  public function update()
254  {
255  $this->insert();
256  }
257 
261  public function delete($a_insert_node = false)
262  {
263  global $ilDB;
264 
265  $query = "DELETE FROM sahs_sc13_seq_item"." WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
266  " AND rootlevel=".$ilDB->quote($this->rootLevel, "integer").")";
267  $obj_set = $ilDB->manipulate($query);
268  }
269 
273  public function insert($import = false)
274  {
275  global $ilDB;
276 
277  $ilDB->replace("sahs_sc13_seq_item",
278  array("sahs_sc13_tree_node_id" => array("integer", $this->treeNodeId),
279  "rootlevel" => array("integer", $this->rootLevel)),
280  array(
281  "importid" => array("text", $this->importId),
282  "seqnodeid" => array("integer", (int) $this->seqNodeId),
283  "sequencingid" => array("text", $this->sequencingId),
284  "nocopy" => array("integer", $this->nocopy),
285  "nodelete" => array("integer", $this->nodelete),
286  "nomove" => array("integer", $this->nomove),
287  "seqxml" => array("clob", $this->dom->saveXML()),
288  "importseqxml" => array("clob", $this->getImportSeqXml())
289  ));
290  return true;
291  }
292 
293 }
294 ?>
Class ilSCORM2004Condition.
loadItem()
Read data from DB into object.
setRootLevel($a_rootlevel)
setSeqNodeId($a_seqnodeid)
ilSCORM2004Item($a_treeid=null, $a_rootlevel=false)
Constructor public.
static getAllowedActions($a_node_id)
setImportSeqXml($a_val)
Set import seq xml.
insert($import=false)
Insert/replace sequencing item in db.
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
exportAsXML($add_prefix=true)
Get sequencing information for export (use imsss namespace prefix)
setTreeNodeId($a_tree_node)
getImportSeqXml()
Get import seq xml.