ILIAS  Release_4_1_x_branch Revision 61804
 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 ,'integer')." ";
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) latest FROM copy_wizard_options ";
117  $res = $ilDB->query($query);
118  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
119 
120  $ilDB->insert("copy_wizard_options", array(
121  "copy_id" => array("integer", $row->latest + 1),
122  "source_id" => array("integer", 0)
123  ));
124  return $row->latest + 1;
125  }
126 
134  public function saveOwner($a_user_id)
135  {
136  global $ilDB;
137 
138  $ilDB->insert("copy_wizard_options", array(
139  "copy_id" => array("integer", $this->getCopyId()),
140  "source_id" => array("integer", self::OWNER_KEY),
141  "options" => array('clob',serialize(array($a_user_id)))
142  ));
143 
144  return true;
145  }
146 
154  public function saveRoot($a_root)
155  {
156  global $ilDB;
157 
158  $ilDB->insert("copy_wizard_options", array(
159  "copy_id" => array("integer", $this->getCopyId()),
160  "source_id" => array("integer", self::ROOT_NODE),
161  "options" => array('clob',serialize(array($a_root)))
162  ));
163 
164  return true;
165 
166  }
167 
175  public function isRootNode($a_root)
176  {
177  return in_array($a_root,$this->getOptions(self::ROOT_NODE));
178  }
179 
187  public function disableSOAP()
188  {
189  global $ilDB;
190 
191  $this->options[self::DISABLE_SOAP] = 1;
192 
193  $ilDB->insert("copy_wizard_options", array(
194  "copy_id" => array("integer", $this->getCopyId()),
195  "source_id" => array("integer", self::DISABLE_SOAP),
196  "options" => array('clob',serialize(array(1)))
197  ));
198  }
199 
206  public function isSOAPEnabled()
207  {
208  if(isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP])
209  {
210  return false;
211  }
212  return true;
213  }
214 
215 
216 
224  public function checkOwner($a_user_id)
225  {
226  return in_array($a_user_id,$this->getOptions(self::OWNER_KEY));
227  }
228 
235  public function getCopyId()
236  {
237  return $this->copy_id;
238  }
239 
240 
249  public function initContainer($a_source_id,$a_target_id)
250  {
251  global $tree;
252 
253  $mapping_source = $tree->getParentId($a_source_id);
254  $this->addEntry($a_source_id,array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
255  $this->appendMapping($mapping_source,$a_target_id);
256  }
257 
268  public function storeTree($a_source_id)
269  {
270  global $ilDB;
271 
272  $this->readTree($a_source_id);
273  $a_tree_structure = $this->tmp_tree;
274 
275  $ilDB->update("copy_wizard_options", array(
276  "options" => array('clob',serialize($a_tree_structure))
277  ), array(
278  "copy_id" => array('integer',$this->getCopyId()),
279  "source_id" => array('integer',0
280  )));
281 
282  $ilDB->insert('copy_wizard_options',array(
283  'copy_id' => array('integer',$this->getCopyId()),
284  'source_id' => array('integer',-1),
285  'options' => array('clob',serialize($a_tree_structure))
286  ));
287 
288  return true;
289  }
290 
297  private function fetchFirstNodeById($a_id)
298  {
299  $tree = $this->getOptions($a_id);
300  if(isset($tree[0]) and is_array($tree[0]))
301  {
302  return $tree[0];
303  }
304  return false;
305  }
306 
314  public function fetchFirstNode()
315  {
316  return $this->fetchFirstNodeById(0);
317  }
318 
325  public function fetchFirstDependenciesNode()
326  {
327  return $this->fetchFirstNodeById(-1);
328  }
329 
336  public function dropFirstNodeById($a_id)
337  {
338  global $ilDB;
339 
340  if(!isset($this->options[$a_id]) or !is_array($this->options[$a_id]))
341  {
342  return false;
343  }
344 
345  $this->options[$a_id] = array_slice($this->options[$a_id],1);
346 
347  $ilDB->update('copy_wizard_options',array(
348  'options' => array('clob',serialize($this->options[$a_id]))
349  ),array(
350  'copy_id' => array('integer',$this->getCopyId()),
351  'source_id' => array('integer',$a_id)));
352 
353  $this->read();
354  // check for role_folder
355  if(($node = $this->fetchFirstNodeById($a_id)) === false)
356  {
357  return true;
358  }
359  if($node['type'] == 'rolf')
360  {
361  $this->dropFirstNodeById($a_id);
362  }
363  return true;
364  }
365 
372  public function dropFirstNode()
373  {
374  return $this->dropFirstNodeById(0);
375  }
376 
383  public function dropFirstDependenciesNode()
384  {
385  return $this->dropFirstNodeById(-1);
386  }
387 
395  public function getOptions($a_source_id)
396  {
397  if(isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id]))
398  {
399  return $this->options[$a_source_id];
400  }
401  return array();
402  }
403 
412  public function addEntry($a_source_id,$a_options)
413  {
414  global $ilDB;
415 
416  if(!is_array($a_options))
417  {
418  return false;
419  }
420 
421  $query = "DELETE FROM copy_wizard_options ".
422  "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
423  "AND source_id = ".$this->db->quote($a_source_id ,'integer');
424  $res = $ilDB->manipulate($query);
425 
426  $ilDB->insert('copy_wizard_options',array(
427  'copy_id' => array('integer',$this->copy_id),
428  'source_id' => array('integer',$a_source_id),
429  'options' => array('clob',serialize($a_options))
430  ));
431  return true;
432  }
433 
442  public function appendMapping($a_source_id,$a_target_id)
443  {
444  global $ilDB;
445 
446  $query = "SELECT * FROM copy_wizard_options ".
447  "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
448  "AND source_id = -2 ";
449  $res = $this->db->query($query);
450  $mappings = array();
451  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
452  {
453  $mappings = unserialize($row->options);
454  }
455  $mappings[$a_source_id] = $a_target_id;
456 
457  $query = "DELETE FROM copy_wizard_options ".
458  "WHERE copy_id = ".$ilDB->quote($this->getCopyId(),'integer')." ".
459  "AND source_id = -2 ";
460  $res = $ilDB->manipulate($query);
461 
462 
463  $ilDB->insert('copy_wizard_options', array(
464  'copy_id' => array('integer',$this->getCopyId()),
465  'source_id' => array('integer',-2),
466  'options' => array('clob',serialize($mappings))
467  ));
468 
469  return true;
470  }
471 
478  public function getMappings()
479  {
480  if(isset($this->options[-2]) and is_array($this->options[-2]))
481  {
482  return $this->options[-2];
483  }
484  return array();
485  }
486 
493  public function deleteAll()
494  {
495  global $ilDB;
496 
497  $query = "DELETE FROM copy_wizard_options ".
498  "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
499  $res = $ilDB->manipulate($query);
500  }
501 
509  public function read()
510  {
511  global $ilDB;
512 
513  $query = "SELECT * FROM copy_wizard_options ".
514  "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
515  $res = $this->db->query($query);
516 
517  $this->options = array();
518  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
519  {
520  $this->options[$row->source_id] = unserialize($row->options);
521  }
522 
523  return true;
524  }
525 
533  private function readTree($a_source_id)
534  {
535  global $tree;
536 
537  $this->tmp_tree[] = $tree->getNodeData($a_source_id);
538 
539 
540  foreach($tree->getChilds($a_source_id) as $sub_nodes)
541  {
542  $sub_node_ref_id = $sub_nodes['child'];
543  // check ommited, linked ...
544  $options = $this->options[$sub_node_ref_id];
545  if($options['type'] == self::COPY_WIZARD_COPY or
546  $options['type'] == self::COPY_WIZARD_LINK)
547  {
548  $this->readTree($sub_node_ref_id);
549  }
550  }
551  }
552 }
553 
554 
555 ?>