ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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;
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
87
92 public function getRequiredSteps()
93 {
94 return count($this->options[0]) + count($this->options[-1]);
95 }
96
97
106 public static function _isFinished($a_copy_id)
107 {
108 global $ilDB;
109
110 $query = "SELECT * FROM copy_wizard_options ".
111 "WHERE copy_id = ".$ilDB->quote($a_copy_id ,'integer')." ";
112 $res = $ilDB->query($query);
113 return $res->numRows() ? false : true;
114 }
115
123 public static function _allocateCopyId()
124 {
125 global $ilDB;
126
127 $query = "SELECT MAX(copy_id) latest FROM copy_wizard_options ";
128 $res = $ilDB->query($query);
129 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
130
131 $ilDB->insert("copy_wizard_options", array(
132 "copy_id" => array("integer", ((int) $row->latest) + 1),
133 "source_id" => array("integer", 0)
134 ));
135 return ((int) $row->latest) + 1;
136 }
137
145 public function saveOwner($a_user_id)
146 {
147 global $ilDB;
148
149 $ilDB->insert("copy_wizard_options", array(
150 "copy_id" => array("integer", $this->getCopyId()),
151 "source_id" => array("integer", self::OWNER_KEY),
152 "options" => array('clob',serialize(array($a_user_id)))
153 ));
154
155 return true;
156 }
157
165 public function saveRoot($a_root)
166 {
167 global $ilDB;
168
169 $ilDB->insert("copy_wizard_options", array(
170 "copy_id" => array("integer", $this->getCopyId()),
171 "source_id" => array("integer", self::ROOT_NODE),
172 "options" => array('clob',serialize(array($a_root)))
173 ));
174
175 return true;
176
177 }
178
186 public function isRootNode($a_root)
187 {
188 return in_array($a_root,$this->getOptions(self::ROOT_NODE));
189 }
190
198 public function disableSOAP()
199 {
200 global $ilDB;
201
202 $this->options[self::DISABLE_SOAP] = 1;
203
204 $ilDB->insert("copy_wizard_options", array(
205 "copy_id" => array("integer", $this->getCopyId()),
206 "source_id" => array("integer", self::DISABLE_SOAP),
207 "options" => array('clob',serialize(array(1)))
208 ));
209 }
210
217 public function isSOAPEnabled()
218 {
219 if(isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP])
220 {
221 return false;
222 }
223 return true;
224 }
225
226
227
235 public function checkOwner($a_user_id)
236 {
237 return in_array($a_user_id,$this->getOptions(self::OWNER_KEY));
238 }
239
246 public function getCopyId()
247 {
248 return $this->copy_id;
249 }
250
251
260 public function initContainer($a_source_id,$a_target_id)
261 {
262 global $tree;
263
264 $mapping_source = $tree->getParentId($a_source_id);
265 $this->addEntry($a_source_id,array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
266 $this->appendMapping($mapping_source,$a_target_id);
267 }
268
279 public function storeTree($a_source_id)
280 {
281 global $ilDB;
282
283 $this->tmp_tree = array();
284 $this->readTree($a_source_id);
285 $a_tree_structure = $this->tmp_tree;
286
287 $ilDB->update("copy_wizard_options", array(
288 "options" => array('clob',serialize($a_tree_structure))
289 ), array(
290 "copy_id" => array('integer',$this->getCopyId()),
291 "source_id" => array('integer',0
292 )));
293
294 $ilDB->insert('copy_wizard_options',array(
295 'copy_id' => array('integer',$this->getCopyId()),
296 'source_id' => array('integer',-1),
297 'options' => array('clob',serialize($a_tree_structure))
298 ));
299
300 return true;
301 }
302
309 private function fetchFirstNodeById($a_id)
310 {
311 $tree = $this->getOptions($a_id);
312 if(isset($tree[0]) and is_array($tree[0]))
313 {
314 return $tree[0];
315 }
316 return false;
317 }
318
326 public function fetchFirstNode()
327 {
328 return $this->fetchFirstNodeById(0);
329 }
330
338 {
339 return $this->fetchFirstNodeById(-1);
340 }
341
348 public function dropFirstNodeById($a_id)
349 {
350 global $ilDB;
351
352 if(!isset($this->options[$a_id]) or !is_array($this->options[$a_id]))
353 {
354 return false;
355 }
356
357 $this->options[$a_id] = array_slice($this->options[$a_id],1);
358
359 $ilDB->update('copy_wizard_options',array(
360 'options' => array('clob',serialize($this->options[$a_id]))
361 ),array(
362 'copy_id' => array('integer',$this->getCopyId()),
363 'source_id' => array('integer',$a_id)));
364
365 $this->read();
366 // check for role_folder
367 if(($node = $this->fetchFirstNodeById($a_id)) === false)
368 {
369 return true;
370 }
371 if($node['type'] == 'rolf')
372 {
373 $this->dropFirstNodeById($a_id);
374 }
375 return true;
376 }
377
384 public function dropFirstNode()
385 {
386 return $this->dropFirstNodeById(0);
387 }
388
396 {
397 return $this->dropFirstNodeById(-1);
398 }
399
407 public function getOptions($a_source_id)
408 {
409 if(isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id]))
410 {
411 return $this->options[$a_source_id];
412 }
413 return array();
414 }
415
424 public function addEntry($a_source_id,$a_options)
425 {
426 global $ilDB;
427
428 if(!is_array($a_options))
429 {
430 return false;
431 }
432
433 $query = "DELETE FROM copy_wizard_options ".
434 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
435 "AND source_id = ".$this->db->quote($a_source_id ,'integer');
436 $res = $ilDB->manipulate($query);
437
438 $ilDB->insert('copy_wizard_options',array(
439 'copy_id' => array('integer',$this->copy_id),
440 'source_id' => array('integer',$a_source_id),
441 'options' => array('clob',serialize($a_options))
442 ));
443 return true;
444 }
445
454 public function appendMapping($a_source_id,$a_target_id)
455 {
456 global $ilDB;
457
458 $query = "SELECT * FROM copy_wizard_options ".
459 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer')." ".
460 "AND source_id = -2 ";
461 $res = $this->db->query($query);
462 $mappings = array();
463 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
464 {
465 $mappings = unserialize($row->options);
466 }
467 $mappings[$a_source_id] = $a_target_id;
468
469 $query = "DELETE FROM copy_wizard_options ".
470 "WHERE copy_id = ".$ilDB->quote($this->getCopyId(),'integer')." ".
471 "AND source_id = -2 ";
472 $res = $ilDB->manipulate($query);
473
474
475 $ilDB->insert('copy_wizard_options', array(
476 'copy_id' => array('integer',$this->getCopyId()),
477 'source_id' => array('integer',-2),
478 'options' => array('clob',serialize($mappings))
479 ));
480
481 return true;
482 }
483
490 public function getMappings()
491 {
492 if(isset($this->options[-2]) and is_array($this->options[-2]))
493 {
494 return $this->options[-2];
495 }
496 return array();
497 }
498
505 public function deleteAll()
506 {
507 global $ilDB;
508
509 $query = "DELETE FROM copy_wizard_options ".
510 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
511 $res = $ilDB->manipulate($query);
512 }
513
521 public function read()
522 {
523 global $ilDB;
524
525 $query = "SELECT * FROM copy_wizard_options ".
526 "WHERE copy_id = ".$this->db->quote($this->copy_id ,'integer');
527 $res = $this->db->query($query);
528
529 $this->options = array();
530 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
531 {
532 $this->options[$row->source_id] = unserialize($row->options);
533 }
534
535 return true;
536 }
537
545 private function readTree($a_source_id)
546 {
547 global $tree;
548
549 $this->tmp_tree[] = $tree->getNodeData($a_source_id);
550
551
552 foreach($tree->getChilds($a_source_id) as $sub_nodes)
553 {
554 $sub_node_ref_id = $sub_nodes['child'];
555 // check ommited, linked ...
556 $options = $this->options[$sub_node_ref_id];
557 if($options['type'] == self::COPY_WIZARD_COPY or
558 $options['type'] == self::COPY_WIZARD_LINK)
559 {
560 $this->readTree($sub_node_ref_id);
561 }
562 }
563 }
564}
565
566
567?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
saveOwner($a_user_id)
Save owner for copy.
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...
isSOAPEnabled()
Check if SOAP calls are disabled.
getRequiredSteps()
Get required steps.
__construct($a_copy_id=0)
Private Constructor (Singleton class)
global $ilDB