ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
39
40 const OWNER_KEY = -3;
41 const DISABLE_SOAP = -4;
42 const ROOT_NODE = -5;
44
45 private $db;
46
47 private $copy_id;
48 private $source_id;
49 private $options = array();
50
58 private function __construct($a_copy_id = 0)
59 {
60 global $ilDB;
61
62 $this->db = $ilDB;
63 $this->copy_id = $a_copy_id;
64
65 if($this->copy_id)
66 {
67 $this->read();
68 }
69 }
70
79 public static function _getInstance($a_copy_id)
80 {
81 if(is_array(self::$instances) and isset(self::$instances[$a_copy_id]))
82 {
83 return self::$instances[$a_copy_id];
84 }
85 return self::$instances[$a_copy_id] = new ilCopyWizardOptions($a_copy_id);
86 }
87
88
93 public function getRequiredSteps()
94 {
95 return count($this->options[0]) + count($this->options[-1]);
96 }
97
98
107 public static function _isFinished($a_copy_id)
108 {
109 global $ilDB;
110
111 $query = "SELECT * FROM copy_wizard_options ".
112 "WHERE copy_id = ".$ilDB->quote($a_copy_id ,'integer')." ";
113 $res = $ilDB->query($query);
114 return $res->numRows() ? false : true;
115 }
116
124 public static function _allocateCopyId()
125 {
126 global $ilDB;
127
128 $query = "SELECT MAX(copy_id) latest FROM copy_wizard_options ";
129 $res = $ilDB->query($query);
131
132 $ilDB->insert("copy_wizard_options", array(
133 "copy_id" => array("integer", ((int) $row->latest) + 1),
134 "source_id" => array("integer", 0)
135 ));
136 return ((int) $row->latest) + 1;
137 }
138
146 public function saveOwner($a_user_id)
147 {
148 global $ilDB;
149
150 $ilDB->insert("copy_wizard_options", array(
151 "copy_id" => array("integer", $this->getCopyId()),
152 "source_id" => array("integer", self::OWNER_KEY),
153 "options" => array('clob',serialize(array($a_user_id)))
154 ));
155
156 return true;
157 }
158
166 public function saveRoot($a_root)
167 {
168 global $ilDB;
169
170 $ilDB->insert("copy_wizard_options", array(
171 "copy_id" => array("integer", $this->getCopyId()),
172 "source_id" => array("integer", self::ROOT_NODE),
173 "options" => array('clob',serialize(array($a_root)))
174 ));
175
176 return true;
177
178 }
179
187 public function isRootNode($a_root)
188 {
189 return in_array($a_root,$this->getOptions(self::ROOT_NODE));
190 }
191
199 public function disableSOAP()
200 {
201 global $ilDB;
202
203 $this->options[self::DISABLE_SOAP] = 1;
204
205 $ilDB->insert("copy_wizard_options", array(
206 "copy_id" => array("integer", $this->getCopyId()),
207 "source_id" => array("integer", self::DISABLE_SOAP),
208 "options" => array('clob',serialize(array(1)))
209 ));
210 }
211
217 public function disableTreeCopy()
218 {
219 global $ilDB;
220
221 $this->options[self::DISABLE_TREE_COPY] = 1;
222
223 $ilDB->insert("copy_wizard_options", array(
224 "copy_id" => array("integer", $this->getCopyId()),
225 "source_id" => array("integer", self::DISABLE_TREE_COPY),
226 "options" => array('clob',serialize(array(1)))
227 ));
228 }
229
234 public function isTreeCopyDisabled()
235 {
236 if(isset($this->options[self::DISABLE_TREE_COPY]) and $this->options[self::DISABLE_TREE_COPY])
237 {
238 return true;
239 }
240 return false;
241
242 }
243
250 public function isSOAPEnabled()
251 {
252 if(isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP])
253 {
254 return false;
255 }
256 return true;
257 }
258
259
260
268 public function checkOwner($a_user_id)
269 {
270 return in_array($a_user_id,$this->getOptions(self::OWNER_KEY));
271 }
272
279 public function getCopyId()
280 {
281 return $this->copy_id;
282 }
283
284
293 public function initContainer($a_source_id,$a_target_id)
294 {
295 global $tree;
296
297 $mapping_source = $tree->getParentId($a_source_id);
298 $this->addEntry($a_source_id,array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
299 $this->appendMapping($mapping_source,$a_target_id);
300 }
301
312 public function storeTree($a_source_id)
313 {
314 global $ilDB;
315
316 $this->tmp_tree = array();
317 $this->readTree($a_source_id);
318 $a_tree_structure = $this->tmp_tree;
319
320 $ilDB->update("copy_wizard_options", array(
321 "options" => array('clob',serialize($a_tree_structure))
322 ), array(
323 "copy_id" => array('integer',$this->getCopyId()),
324 "source_id" => array('integer',0
325 )));
326
327 $ilDB->insert('copy_wizard_options',array(
328 'copy_id' => array('integer',$this->getCopyId()),
329 'source_id' => array('integer',-1),
330 'options' => array('clob',serialize($a_tree_structure))
331 ));
332
333 return true;
334 }
335
342 private function fetchFirstNodeById($a_id)
343 {
344 $tree = $this->getOptions($a_id);
345 if(isset($tree[0]) and is_array($tree[0]))
346 {
347 return $tree[0];
348 }
349 return false;
350 }
351
359 public function fetchFirstNode()
360 {
361 return $this->fetchFirstNodeById(0);
362 }
363
371 {
372 return $this->fetchFirstNodeById(-1);
373 }
374
381 public function dropFirstNodeById($a_id)
382 {
383 global $ilDB;
384
385 if(!isset($this->options[$a_id]) or !is_array($this->options[$a_id]))
386 {
387 return false;
388 }
389
390 $this->options[$a_id] = array_slice($this->options[$a_id],1);
391
392 $ilDB->update('copy_wizard_options',array(
393 'options' => array('clob',serialize($this->options[$a_id]))
394 ),array(
395 'copy_id' => array('integer',$this->getCopyId()),
396 'source_id' => array('integer',$a_id)));
397
398 $this->read();
399 // check for role_folder
400 if(($node = $this->fetchFirstNodeById($a_id)) === false)
401 {
402 return true;
403 }
404 if($node['type'] == 'rolf')
405 {
406 $this->dropFirstNodeById($a_id);
407 }
408 return true;
409 }
410
417 public function dropFirstNode()
418 {
419 return $this->dropFirstNodeById(0);
420 }
421
429 {
430 return $this->dropFirstNodeById(-1);
431 }
432
440 public function getOptions($a_source_id)
441 {
442 if(isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id]))
443 {
444 return $this->options[$a_source_id];
445 }
446 return array();
447 }
448
457 public function addEntry($a_source_id,$a_options)
458 {
459 global $ilDB;
460
461 if(!is_array($a_options))
462 {
463 return false;
464 }
465
466 $query = "DELETE FROM copy_wizard_options ".
467 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
468 "AND source_id = ".$this->db->quote($a_source_id ,'integer');
469 $res = $ilDB->manipulate($query);
470
471 $ilDB->insert('copy_wizard_options',array(
472 'copy_id' => array('integer',$this->copy_id),
473 'source_id' => array('integer',$a_source_id),
474 'options' => array('clob',serialize($a_options))
475 ));
476 return true;
477 }
478
487 public function appendMapping($a_source_id,$a_target_id)
488 {
489 global $ilDB;
490
491 $query = "SELECT * FROM copy_wizard_options ".
492 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
493 "AND source_id = -2 ";
494 $res = $this->db->query($query);
495 $mappings = array();
496 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
497 {
498 $mappings = unserialize($row->options);
499 }
500 $mappings[$a_source_id] = $a_target_id;
501
502 $query = "DELETE FROM copy_wizard_options ".
503 "WHERE copy_id = ".$ilDB->quote($this->getCopyId(),'integer')." ".
504 "AND source_id = -2 ";
505 $res = $ilDB->manipulate($query);
506
507
508 $ilDB->insert('copy_wizard_options', array(
509 'copy_id' => array('integer',$this->getCopyId()),
510 'source_id' => array('integer',-2),
511 'options' => array('clob',serialize($mappings))
512 ));
513
514 return true;
515 }
516
523 public function getMappings()
524 {
525 if(isset($this->options[-2]) and is_array($this->options[-2]))
526 {
527 return $this->options[-2];
528 }
529 return array();
530 }
531
538 public function deleteAll()
539 {
540 global $ilDB;
541
542 $query = "DELETE FROM copy_wizard_options ".
543 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
544 $res = $ilDB->manipulate($query);
545 }
546
554 public function read()
555 {
556 global $ilDB;
557
558 $query = "SELECT * FROM copy_wizard_options ".
559 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
560 $res = $this->db->query($query);
561
562 $this->options = array();
563 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
564 {
565 $this->options[$row->source_id] = unserialize($row->options);
566 }
567
568 return true;
569 }
570
578 private function readTree($a_source_id)
579 {
580 global $tree;
581
582 $this->tmp_tree[] = $tree->getNodeData($a_source_id);
583
584
585 foreach($tree->getChilds($a_source_id) as $sub_nodes)
586 {
587 $sub_node_ref_id = $sub_nodes['child'];
588 // check ommited, linked ...
589 $options = $this->options[$sub_node_ref_id];
590 if($options['type'] == self::COPY_WIZARD_COPY or
591 $options['type'] == self::COPY_WIZARD_LINK)
592 {
593 $this->readTree($sub_node_ref_id);
594 }
595 }
596 }
597}
598
599
600?>
An exception for terminatinating execution or to throw for unit testing.
saveOwner($a_user_id)
Save owner for copy.
disableTreeCopy()
Disable copying of tree.
fetchFirstNode()
Fetch first node for cloneObject.
saveRoot($a_root)
Save root node id.
static _allocateCopyId()
Allocate a copy for further entries.
fetchFirstNodeById($a_id)
Get first node of stored tree.
dropFirstNodeById($a_id)
Drop first node by id.
disableSOAP()
Disable soap calls.
checkOwner($a_user_id)
check owner
readTree($a_source_id)
Purge ommitted node recursively.
dropFirstNode()
Drop first node (for cloneObject())
static _getInstance($a_copy_id)
Get instance of copy wizard options.
appendMapping($a_source_id, $a_target_id)
Add mapping of source -> target.
static _isFinished($a_copy_id)
check if copy is finished
deleteAll()
Delete all entries.
initContainer($a_source_id, $a_target_id)
Init container Add copy entry.
isRootNode($a_root)
Is root node.
fetchFirstDependenciesNode()
Fetch first dependencies node.
addEntry($a_source_id, $a_options)
Add new entry.
dropFirstDependenciesNode()
Drop first node (for cloneDependencies())
getOptions($a_source_id)
Get entry by source.
storeTree($a_source_id)
Save tree Stores two copies of the tree structure: id 0 is used for recursive call of cloneObject() i...
isTreeCopyDisabled()
Check if tree copy is enabled.
isSOAPEnabled()
Check if SOAP calls are disabled.
getRequiredSteps()
Get required steps.
__construct($a_copy_id=0)
Private Constructor (Singleton class)
global $ilDB