ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004Item.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004SeqNode.php");
36 
37 
39 {
40 
41 
42  //db fields
43  private $id = null;
44  private $seqNodeId = null;
45  private $treeNodeId = null;
46  private $sequencingId = null;
47  private $nocopy = false;
48  private $nodelete = false;
49  private $nomove = false;
50  private $importId = null;
51  private $seqXml = null;
52  private $rootLevel = false;
53 
54  protected $dom = null;
59  function ilSCORM2004Item($a_treeid = null , $a_rootlevel = false)
60  {
61  //different handling for organization level
62  $this->rootLevel = $a_rootlevel;
63 
64  if ($a_treeid !=null) {
65  $this->treeNodeId = $a_treeid;
66  $this->loadItem();
67  $this->dom = new DOMDocument();
68  if ($this->getSeqXml()!="") {
69  $this->dom->loadXML($this->getSeqXml());
70  } else {
71  $element = $this->dom->createElement('sequencing');
72  $this->dom->appendChild($element);
73  $this->setSeqXml($this->dom->saveXML());
74  }
75  }
76 
77  }
78 
79 
80  // **********************
81  // GETTER METHODS
82  // **********************
83 
84  public function getSeqNodeId()
85  {
86  return $this->seqNodeId;
87  }
88 
89  public function getTreeNodeId()
90  {
91  return $this->treeNodeId;
92  }
93 
94 
95  public function getSequencingId()
96  {
97  return $this->sequencingId;
98  }
99 
100  public function getImportId()
101  {
102  return $this->importId;
103  }
104  public function getNocopy()
105  {
106  return $this->nocopy;
107  }
108 
109  public function getNodelete()
110  {
111  return $this->nodelete;
112  }
113 
114  public function getNomove()
115  {
116  return $this->nomove;
117  }
118 
119  public function getSeqXml()
120  {
121  return $this->seqXml;
122  }
123 
124  public function getRoolLevel()
125  {
126  return $this->rootLevel;
127  }
128 
129 
130  // **********************
131  // Setter METHODS
132  // **********************
133 
134  public function setSeqNodeId($a_seqnodeid)
135  {
136  $this->seqNodeId = $a_seqnodeid;
137  }
138 
139  public function setTreeNodeId($a_tree_node)
140  {
141  $this->treeNodeId = $a_tree_node;
142  }
143 
144  public function setSequencingId($a_seq_id)
145  {
146  $this->sequencingId = $a_seq_id;
147  }
148 
149  public function setNocopy($a_nocopy)
150  {
151  $this->nocopy = $a_nocopy;
152  }
153 
154  public function setNodelete($a_nodelete)
155  {
156  $this->nodelete = $a_nodelete ;
157  }
158 
159  public function setNomove($a_nomove)
160  {
161  $this->nomove = $a_nomove;
162  }
163 
164  public function setImportId($a_importid)
165  {
166  $this->importid = $a_importid;
167  }
168 
169  public function setSeqXml($a_seqxml)
170  {
171  $this->seqXml = $a_seqxml;
172  }
173 
174  public function setDom($a_dom)
175  {
176  $this->dom = $a_dom;
177  }
178 
179  public function setRootLevel($a_rootlevel)
180  {
181  $this->rootLevel = $a_rootlevel;
182  }
183 
184  public static function getAllowedActions($a_node_id)
185  {
186  global $ilDB,$ilLog;
187  $query = "SELECT * FROM sahs_sc13_seq_item WHERE sahs_sc13_tree_node_id = ".
188  $ilDB->quote($a_node_id, "integer");
189  $obj_set = $ilDB->query($query);
190  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
191  return array("copy"=>!$obj_rec['nocopy'],"move"=>!$obj_rec['nomove'],"delete"=>!$obj_rec['nodelete']);
192  }
193 
194  // **********************
195  // Scorm2004 Sequencing Export
196  // **********************
197 
198  public function exportAsXML() {
199 
200  //remove titles
201  $xpath_obj = new DOMXPath($this->dom);
202  $obj_node_list = $xpath_obj->query('//objective | //primaryObjective');
203  for ($i=0;$i<$obj_node_list->length;$i++) {
204  $obj_node_list->item($i)->removeAttribute("title");
205  }
206  $output = $this->dom->saveXML();
207  $output = preg_replace('/<\?xml version="1.0"\?>/','',$output);
208  $output = preg_replace('/(<)([a-z]+|[A-Z]+)/','<imsss:$2',$output);
209  $output = preg_replace('/(<\/)([a-z]+|[A-Z]+)/','</imsss:$2',$output);
210  $output = preg_replace('/\n/','',$output);
211 
212  return $output;
213  }
214 
215  // **********************
216  // Standard DB Operations for Object
217  // **********************
218  public function loadItem()
219  {
220  global $ilDB;
221  $query = "SELECT * FROM sahs_sc13_seq_item WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
222  " AND rootlevel =".$ilDB->quote($this->rootLevel, "integer").")";
223  $obj_set = $ilDB->query($query);
224  $obj_rec = $ilDB->fetchAssoc($obj_set);
225  $this->seqXml = $obj_rec['seqxml'];
226  $this->importId = $obj_rec['importid'];
227  $this->nocopy = $obj_rec['nocopy'];
228  $this->nomove = $obj_rec['nomove'];
229  $this->nodelete = $obj_rec['nodelete'];
230  }
231 
232 
233  public function update($a_insert_node = false)
234  {
235  $this->insert();
236  /*
237  global $ilDB;
238  $query = "UPDATE sahs_sc13_seq_item SET seqxml=".$ilDB->quote($this->dom->saveXML())." WHERE sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId);
239  $obj_set = $ilDB->query($query);
240  */
241  }
242 
243  public function delete($a_insert_node = false)
244  {
245  global $ilDB;
246  $query = "DELETE FROM sahs_sc13_seq_item"." WHERE (sahs_sc13_tree_node_id = ".$ilDB->quote($this->treeNodeId, "integer").
247  " AND rootlevel=".$ilDB->quote($this->rootLevel, "integer").")";
248  $obj_set = $ilDB->manipulate($query);
249  }
250 
251  public function insert($import = false)
252  {
253 
254  global $ilDB;
255  $ilDB->replace("sahs_sc13_seq_item",
256  array("sahs_sc13_tree_node_id" => array("integer", $this->treeNodeId)),
257  array(
258  "importid" => array("text", $this->importId),
259  "seqnodeid" => array("integer", (int) $this->seqNodeId),
260  "sequencingid" => array("text", $this->sequencingId),
261  "nocopy" => array("integer", $this->nocopy),
262  "nodelete" => array("integer", $this->nodelete),
263  "nomove" => array("integer", $this->nomove),
264  "seqxml" => array("text", $this->dom->saveXML()),
265  "rootlevel" => array("integer", $this->rootLevel)
266  ));
267 /* $sql = "REPLACE INTO sahs_sc13_seq_item (`importid`,`seqnodeid`, `sahs_sc13_tree_node_id`".
268  ", `sequencingid` ,`nocopy` ,`nodelete` ,`nomove`,`seqxml`,`rootlevel` )".
269  " values(".$ilDB->quote($this->importId).",".$ilDB->quote($this->seqNodeId).",".$ilDB->quote($this->treeNodeId).",".
270  $ilDB->quote($this->sequencingId).",".$ilDB->quote($this->nocopy).",".
271  $ilDB->quote($this->nodelete).",".$ilDB->quote($this->nomove).",".
272  $ilDB->quote($this->dom->saveXML()). ",".$ilDB->quote($this->rootLevel).");";
273  $result = $ilDB->query($sql);*/
274  return true;
275  }
276 
277 
278 
279 }
280 ?>