ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
37  const COPY_WIZARD_OMIT = 1;
38  const COPY_WIZARD_COPY = 2;
39  const COPY_WIZARD_LINK = 3;
41 
42  const OWNER_KEY = -3;
43  const DISABLE_SOAP = -4;
44  const ROOT_NODE = -5;
45  const DISABLE_TREE_COPY = -6;
46 
47  private $db;
48 
49  private $copy_id;
50  private $source_id;
51  private $options = array();
52 
60  private function __construct($a_copy_id = 0)
61  {
62  global $DIC;
63 
64  $ilDB = $DIC['ilDB'];
65 
66  $this->db = $ilDB;
67  $this->copy_id = $a_copy_id;
68 
69  if ($this->copy_id) {
70  $this->read();
71  }
72  }
73 
82  public static function _getInstance($a_copy_id)
83  {
84  if (is_array(self::$instances) and isset(self::$instances[$a_copy_id])) {
85  return self::$instances[$a_copy_id];
86  }
87  return self::$instances[$a_copy_id] = new ilCopyWizardOptions($a_copy_id);
88  }
89 
90 
95  public function getRequiredSteps()
96  {
97  $steps = 0;
98  if (is_array($this->options) && array_key_exists(0, $this->options) && is_array($this->options[0])) {
99  $steps += count($this->options[0]);
100  }
101  if (is_array($this->options) && array_key_exists(-1, $this->options) && is_array($this->options[-1])) {
102  $steps += count($this->options[-1]);
103  }
104  return $steps;
105  }
106 
107 
116  public static function _isFinished($a_copy_id)
117  {
118  global $DIC;
119 
120  $ilDB = $DIC['ilDB'];
121 
122  $query = "SELECT * FROM copy_wizard_options " .
123  "WHERE copy_id = " . $ilDB->quote($a_copy_id, 'integer') . " ";
124  $res = $ilDB->query($query);
125  return $res->numRows() ? false : true;
126  }
127 
135  public static function _allocateCopyId()
136  {
137  global $DIC;
138 
139  $ilDB = $DIC['ilDB'];
140 
141  $query = "SELECT MAX(copy_id) latest FROM copy_wizard_options ";
142  $res = $ilDB->query($query);
144 
145  $ilDB->insert("copy_wizard_options", array(
146  "copy_id" => array("integer", ((int) $row->latest) + 1),
147  "source_id" => array("integer", 0)
148  ));
149  return ((int) $row->latest) + 1;
150  }
151 
159  public function saveOwner($a_user_id)
160  {
161  global $DIC;
162 
163  $ilDB = $DIC['ilDB'];
164 
165  $ilDB->insert("copy_wizard_options", array(
166  "copy_id" => array("integer", $this->getCopyId()),
167  "source_id" => array("integer", self::OWNER_KEY),
168  "options" => array('clob',serialize(array($a_user_id)))
169  ));
170 
171  return true;
172  }
173 
181  public function saveRoot($a_root)
182  {
183  global $DIC;
184 
185  $ilDB = $DIC['ilDB'];
186 
187  $ilDB->insert("copy_wizard_options", array(
188  "copy_id" => array("integer", $this->getCopyId()),
189  "source_id" => array("integer", self::ROOT_NODE),
190  "options" => array('clob',serialize(array($a_root)))
191  ));
192 
193  return true;
194  }
195 
203  public function isRootNode($a_root)
204  {
205  return in_array($a_root, $this->getOptions(self::ROOT_NODE));
206  }
207 
211  public function getRootNode()
212  {
213  $options = $this->getOptions(self::ROOT_NODE);
214  if (!is_array($options) || !array_key_exists(0, $options)) {
215  return null;
216  }
217  return (int) $options[0];
218  }
219 
227  public function disableSOAP()
228  {
229  global $DIC;
230 
231  $ilDB = $DIC['ilDB'];
232 
233  $this->options[self::DISABLE_SOAP] = 1;
234 
235  $ilDB->insert("copy_wizard_options", array(
236  "copy_id" => array("integer", $this->getCopyId()),
237  "source_id" => array("integer", self::DISABLE_SOAP),
238  "options" => array('clob',serialize(array(1)))
239  ));
240  }
241 
247  public function disableTreeCopy()
248  {
249  global $DIC;
250 
251  $ilDB = $DIC['ilDB'];
252 
253  $this->options[self::DISABLE_TREE_COPY] = 1;
254 
255  $ilDB->insert("copy_wizard_options", array(
256  "copy_id" => array("integer", $this->getCopyId()),
257  "source_id" => array("integer", self::DISABLE_TREE_COPY),
258  "options" => array('clob',serialize(array(1)))
259  ));
260  }
261 
266  public function isTreeCopyDisabled()
267  {
268  if (isset($this->options[self::DISABLE_TREE_COPY]) and $this->options[self::DISABLE_TREE_COPY]) {
269  return true;
270  }
271  return false;
272  }
273 
280  public function isSOAPEnabled()
281  {
282  if (isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP]) {
283  return false;
284  }
285  return true;
286  }
287 
288 
289 
297  public function checkOwner($a_user_id)
298  {
299  return in_array($a_user_id, $this->getOptions(self::OWNER_KEY));
300  }
301 
308  public function getCopyId()
309  {
310  return $this->copy_id;
311  }
312 
313 
322  public function initContainer($a_source_id, $a_target_id)
323  {
324  global $DIC;
325 
326  $tree = $DIC['tree'];
327 
328  $mapping_source = $tree->getParentId($a_source_id);
329  $this->addEntry($a_source_id, array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
330  $this->appendMapping($mapping_source, $a_target_id);
331  }
332 
343  public function storeTree($a_source_id)
344  {
345  global $DIC;
346 
347  $ilDB = $DIC['ilDB'];
348 
349  $this->tmp_tree = array();
350  $this->readTree($a_source_id);
351  $a_tree_structure = $this->tmp_tree;
352 
353  $ilDB->update("copy_wizard_options", array(
354  "options" => array('clob',serialize($a_tree_structure))
355  ), array(
356  "copy_id" => array('integer',$this->getCopyId()),
357  "source_id" => array('integer',0
358  )));
359 
360  $ilDB->insert('copy_wizard_options', array(
361  'copy_id' => array('integer',$this->getCopyId()),
362  'source_id' => array('integer',-1),
363  'options' => array('clob',serialize($a_tree_structure))
364  ));
365 
366  return true;
367  }
368 
375  private function fetchFirstNodeById($a_id)
376  {
377  $tree = $this->getOptions($a_id);
378  if (isset($tree[0]) and is_array($tree[0])) {
379  return $tree[0];
380  }
381  return false;
382  }
383 
391  public function fetchFirstNode()
392  {
393  return $this->fetchFirstNodeById(0);
394  }
395 
402  public function fetchFirstDependenciesNode()
403  {
404  return $this->fetchFirstNodeById(-1);
405  }
406 
413  public function dropFirstNodeById($a_id)
414  {
415  global $DIC;
416 
417  $ilDB = $DIC['ilDB'];
418 
419  if (!isset($this->options[$a_id]) or !is_array($this->options[$a_id])) {
420  return false;
421  }
422 
423  $this->options[$a_id] = array_slice($this->options[$a_id], 1);
424 
425  $ilDB->update('copy_wizard_options', array(
426  'options' => array('clob',serialize($this->options[$a_id]))
427  ), array(
428  'copy_id' => array('integer',$this->getCopyId()),
429  'source_id' => array('integer',$a_id)));
430 
431  $this->read();
432  // check for role_folder
433  if (($node = $this->fetchFirstNodeById($a_id)) === false) {
434  return true;
435  }
436  if ($node['type'] == 'rolf') {
437  $this->dropFirstNodeById($a_id);
438  }
439  return true;
440  }
441 
448  public function dropFirstNode()
449  {
450  return $this->dropFirstNodeById(0);
451  }
452 
459  public function dropFirstDependenciesNode()
460  {
461  return $this->dropFirstNodeById(-1);
462  }
463 
471  public function getOptions($a_source_id)
472  {
473  if (isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id])) {
474  return $this->options[$a_source_id];
475  }
476  return array();
477  }
478 
487  public function addEntry($a_source_id, $a_options)
488  {
489  global $DIC;
490 
491  $ilDB = $DIC['ilDB'];
492 
493  if (!is_array($a_options)) {
494  return false;
495  }
496 
497  $query = "DELETE FROM copy_wizard_options " .
498  "WHERE copy_id = " . $this->db->quote($this->copy_id, 'integer') . " " .
499  "AND source_id = " . $this->db->quote($a_source_id, 'integer');
500  $res = $ilDB->manipulate($query);
501 
502  $ilDB->insert('copy_wizard_options', array(
503  'copy_id' => array('integer',$this->copy_id),
504  'source_id' => array('integer',$a_source_id),
505  'options' => array('clob',serialize($a_options))
506  ));
507  return true;
508  }
509 
518  public function appendMapping($a_source_id, $a_target_id)
519  {
520  global $DIC;
521 
522  $ilDB = $DIC['ilDB'];
523 
524  $query = "SELECT * FROM copy_wizard_options " .
525  "WHERE copy_id = " . $this->db->quote($this->copy_id, 'integer') . " " .
526  "AND source_id = -2 ";
527  $res = $this->db->query($query);
528  $mappings = array();
529  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
530  $mappings = unserialize($row->options);
531  }
532  $mappings[$a_source_id] = $a_target_id;
533 
534  $query = "DELETE FROM copy_wizard_options " .
535  "WHERE copy_id = " . $ilDB->quote($this->getCopyId(), 'integer') . " " .
536  "AND source_id = -2 ";
537  $res = $ilDB->manipulate($query);
538 
539 
540  $ilDB->insert('copy_wizard_options', array(
541  'copy_id' => array('integer',$this->getCopyId()),
542  'source_id' => array('integer',-2),
543  'options' => array('clob',serialize($mappings))
544  ));
545 
546  return true;
547  }
548 
555  public function getMappings()
556  {
557  if (isset($this->options[-2]) and is_array($this->options[-2])) {
558  return $this->options[-2];
559  }
560  return array();
561  }
562 
569  public function deleteAll()
570  {
571  global $DIC;
572 
573  $ilDB = $DIC['ilDB'];
574 
575  $query = "DELETE FROM copy_wizard_options " .
576  "WHERE copy_id = " . $this->db->quote($this->copy_id, 'integer');
577  $res = $ilDB->manipulate($query);
578  }
579 
587  public function read()
588  {
589  global $DIC;
590 
591  $ilDB = $DIC['ilDB'];
592 
593  $query = "SELECT * FROM copy_wizard_options " .
594  "WHERE copy_id = " . $this->db->quote($this->copy_id, 'integer');
595  $res = $this->db->query($query);
596 
597  $this->options = array();
598  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
599  $this->options[$row->source_id] = unserialize($row->options);
600  }
601 
602  return true;
603  }
604 
612  private function readTree($a_source_id)
613  {
614  global $DIC;
615 
616  $tree = $DIC['tree'];
617 
618  $this->tmp_tree[] = $tree->getNodeData($a_source_id);
619 
620 
621  foreach ($tree->getChilds($a_source_id) as $sub_nodes) {
622  $sub_node_ref_id = $sub_nodes['child'];
623  // check ommited, linked ...
624  $options = $this->options[$sub_node_ref_id];
625  if ($options['type'] == self::COPY_WIZARD_COPY or
626  $options['type'] == self::COPY_WIZARD_LINK) {
627  $this->readTree($sub_node_ref_id);
628  }
629  }
630  }
631 }
fetchFirstNodeById($a_id)
Get first node of stored tree.
storeTree($a_source_id)
Save tree Stores two copies of the tree structure: id 0 is used for recursive call of cloneObject() i...
readTree($a_source_id)
Purge ommitted node recursively.
saveOwner($a_user_id)
Save owner for copy.
getRequiredSteps()
Get required steps.
global $DIC
Definition: saml.php:7
fetchFirstNode()
Fetch first node for cloneObject.
disableSOAP()
Disable soap calls.
checkOwner($a_user_id)
check owner
fetchFirstDependenciesNode()
Fetch first dependencies node.
addEntry($a_source_id, $a_options)
Add new entry.
$steps
Definition: latex.php:3
__construct($a_copy_id=0)
Private Constructor (Singleton class)
saveRoot($a_root)
Save root node id.
isSOAPEnabled()
Check if SOAP calls are disabled.
static _isFinished($a_copy_id)
check if copy is finished
static _getInstance($a_copy_id)
Get instance of copy wizard options.
appendMapping($a_source_id, $a_target_id)
Add mapping of source -> target.
foreach($_POST as $key=> $value) $res
isTreeCopyDisabled()
Check if tree copy is enabled.
disableTreeCopy()
Disable copying of tree.
static _allocateCopyId()
Allocate a copy for further entries.
initContainer($a_source_id, $a_target_id)
Init container Add copy entry.
$query
isRootNode($a_root)
Is root node.
dropFirstDependenciesNode()
Drop first node (for cloneDependencies())
$row
dropFirstNodeById($a_id)
Drop first node by id.
getOptions($a_source_id)
Get entry by source.
global $ilDB
deleteAll()
Delete all entries.
dropFirstNode()
Drop first node (for cloneObject())