ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCopyWizardOptions.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
33 {
34  private static $instances = null;
35 
36  const COPY_WIZARD_OMIT = 1;
37  const COPY_WIZARD_COPY = 2;
38  const COPY_WIZARD_LINK = 3;
39 
40  const OWNER_KEY = -3;
41  const DISABLE_SOAP = -4;
42  const ROOT_NODE = -5;
43 
44  private $db;
45 
46  private $copy_id;
47  private $source_id;
48  private $options = array();
49 
57  private function __construct($a_copy_id = 0)
58  {
59  global $ilDB;
60 
61  $this->db = $ilDB;
62  $this->copy_id = $a_copy_id;
63 
64  if($this->copy_id)
65  {
66  $this->read();
67  }
68  }
69 
78  public static function _getInstance($a_copy_id)
79  {
80  if(is_array(self::$instances) and isset(self::$instances[$a_copy_id]))
81  {
82  return self::$instances[$a_copy_id];
83  }
84  return self::$instances[$a_copy_id] = new ilCopyWizardOptions($a_copy_id);
85  }
86 
95  public static function _isFinished($a_copy_id)
96  {
97  global $ilDB;
98 
99  $query = "SELECT * FROM copy_wizard_options ".
100  " WHERE copy_id = ".$ilDB->quote($a_copy_id)." ";
101  $res = $ilDB->query($query);
102  return $res->numRows() ? false : true;
103  }
104 
112  public static function _allocateCopyId()
113  {
114  global $ilDB;
115 
116  $query = "SELECT MAX(copy_id) as latest FROM copy_wizard_options ";
117  $res = $ilDB->query($query);
118  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
119 
120  $query = "INSERT INTO copy_wizard_options ".
121  "SET copy_id = ".$ilDB->quote($row->latest + 1);
122  $ilDB->query($query);
123 
124  return $row->latest + 1;
125  }
126 
134  public function saveOwner($a_user_id)
135  {
136  $query = "INSERT INTO copy_wizard_options ".
137  "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
138  "source_id = ".$this->db->quote(self::OWNER_KEY).", ".
139  "options = ".$this->db->quote(serialize(array($a_user_id)))."";
140  $this->db->query($query);
141  return true;
142  }
143 
151  public function saveRoot($a_root)
152  {
153  $query = "INSERT INTO copy_wizard_options ".
154  "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
155  "source_id = ".$this->db->quote(self::ROOT_NODE).", ".
156  "options = ".$this->db->quote(serialize(array($a_root)))."";
157  $this->db->query($query);
158  return true;
159 
160  }
161 
169  public function isRootNode($a_root)
170  {
171  return in_array($a_root,$this->getOptions(self::ROOT_NODE));
172  }
173 
181  public function disableSOAP()
182  {
183  $this->options[self::DISABLE_SOAP] = 1;
184  $query = "INSERT INTO copy_wizard_options ".
185  "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
186  "source_id = ".$this->db->quote(self::DISABLE_SOAP).", ".
187  "options = ".$this->db->quote(serialize(array(1)))."";
188  $this->db->query($query);
189  }
190 
197  public function isSOAPEnabled()
198  {
199  if(isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP])
200  {
201  return false;
202  }
203  return true;
204  }
205 
206 
207 
215  public function checkOwner($a_user_id)
216  {
217  return in_array($a_user_id,$this->getOptions(self::OWNER_KEY));
218  }
219 
226  public function getCopyId()
227  {
228  return $this->copy_id;
229  }
230 
231 
240  public function initContainer($a_source_id,$a_target_id)
241  {
242  global $tree;
243 
244  $mapping_source = $tree->getParentId($a_source_id);
245  $this->addEntry($a_source_id,array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
246  $this->appendMapping($mapping_source,$a_target_id);
247  }
248 
259  public function storeTree($a_source_id)
260  {
261  $this->readTree($a_source_id);
262  $a_tree_structure = $this->tmp_tree;
263 
264  $query = "UPDATE copy_wizard_options ".
265  "SET options = ".$this->db->quote(serialize($a_tree_structure))." ".
266  "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
267  "AND source_id = 0 ";
268  $res = $this->db->query($query);
269 
270  $query = "INSERT INTO copy_wizard_options ".
271  "SET options = ".$this->db->quote(serialize($a_tree_structure)).", ".
272  "copy_id = ".$this->db->quote($this->copy_id).", ".
273  "source_id = -1 ";
274  $res = $this->db->query($query);
275  return true;
276  }
277 
284  private function fetchFirstNodeById($a_id)
285  {
286  $tree = $this->getOptions($a_id);
287  if(isset($tree[0]) and is_array($tree[0]))
288  {
289  return $tree[0];
290  }
291  return false;
292  }
293 
301  public function fetchFirstNode()
302  {
303  return $this->fetchFirstNodeById(0);
304  }
305 
312  public function fetchFirstDependenciesNode()
313  {
314  return $this->fetchFirstNodeById(-1);
315  }
316 
323  public function dropFirstNodeById($a_id)
324  {
325  if(!isset($this->options[$a_id]) or !is_array($this->options[$a_id]))
326  {
327  return false;
328  }
329 
330  $this->options[$a_id] = array_slice($this->options[$a_id],1);
331  $query = "UPDATE copy_wizard_options ".
332  "SET options = ".$this->db->quote(serialize($this->options[$a_id]))." ".
333  "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
334  "AND source_id = ".$this->db->quote($a_id)." ";
335  ;
336  $this->db->query($query);
337  $this->read();
338  // check for role_folder
339  if(($node = $this->fetchFirstNodeById($a_id)) === false)
340  {
341  return true;
342  }
343  if($node['type'] == 'rolf')
344  {
345  $this->dropFirstNodeById($a_id);
346  }
347  return true;
348  }
349 
356  public function dropFirstNode()
357  {
358  return $this->dropFirstNodeById(0);
359  }
360 
367  public function dropFirstDependenciesNode()
368  {
369  return $this->dropFirstNodeById(-1);
370  }
371 
379  public function getOptions($a_source_id)
380  {
381  if(isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id]))
382  {
383  return $this->options[$a_source_id];
384  }
385  return array();
386  }
387 
396  public function addEntry($a_source_id,$a_options)
397  {
398  if(!is_array($a_options))
399  {
400  return false;
401  }
402 
403  $query = "DELETE FROM copy_wizard_options ".
404  "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
405  "AND source_id = ".$this->db->quote($a_source_id);
406  $this->db->query($query);
407 
408  $query = "INSERT INTO copy_wizard_options ".
409  "SET copy_id = ".$this->db->quote($this->copy_id).", ".
410  "source_id = ".$this->db->quote($a_source_id).", ".
411  "options = ".$this->db->quote(serialize($a_options))." ";
412  $res = $this->db->query($query);
413  return true;
414  }
415 
424  public function appendMapping($a_source_id,$a_target_id)
425  {
426  $query = "SELECT * FROM copy_wizard_options ".
427  "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
428  "AND source_id = -2 ";
429  $res = $this->db->query($query);
430  $mappings = array();
431  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
432  {
433  $mappings = unserialize($row->options);
434  }
435  $mappings[$a_source_id] = $a_target_id;
436 
437  $query = "REPLACE INTO copy_wizard_options ".
438  "SET copy_id = ".$this->db->quote($this->copy_id).", ".
439  "source_id = -2, ".
440  "options = ".$this->db->quote(serialize($mappings))."";
441  $this->db->query($query);
442  return true;
443  }
444 
451  public function getMappings()
452  {
453  if(isset($this->options[-2]) and is_array($this->options[-2]))
454  {
455  return $this->options[-2];
456  }
457  return array();
458  }
459 
466  public function deleteAll()
467  {
468  $query = "DELETE FROM copy_wizard_options ".
469  "WHERE copy_id = ".$this->db->quote($this->copy_id);
470  $this->db->query($query);
471  }
472 
480  public function read()
481  {
482  $query = "SELECT * FROM copy_wizard_options ".
483  "WHERE copy_id = ".$this->db->quote($this->copy_id);
484  $res = $this->db->query($query);
485 
486  $this->options = array();
487  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
488  {
489  $this->options[$row->source_id] = unserialize($row->options);
490  }
491 
492  return true;
493  }
494 
502  private function readTree($a_source_id)
503  {
504  global $tree;
505 
506  $this->tmp_tree[] = $tree->getNodeData($a_source_id);
507 
508 
509  foreach($tree->getChilds($a_source_id) as $sub_nodes)
510  {
511  $sub_node_ref_id = $sub_nodes['child'];
512  // check ommited, linked ...
513  $options = $this->options[$sub_node_ref_id];
514  if($options['type'] == self::COPY_WIZARD_COPY or
515  $options['type'] == self::COPY_WIZARD_LINK)
516  {
517  $this->readTree($sub_node_ref_id);
518  }
519  }
520  }
521 }
522 
523 
524 ?>