Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 class ilCopyWizardOptions
00033 {
00034 private static $instances = null;
00035
00036 const COPY_WIZARD_OMIT = 1;
00037 const COPY_WIZARD_COPY = 2;
00038 const COPY_WIZARD_LINK = 3;
00039
00040 const OWNER_KEY = -3;
00041 const DISABLE_SOAP = -4;
00042 const ROOT_NODE = -5;
00043
00044 private $db;
00045
00046 private $copy_id;
00047 private $source_id;
00048 private $options = array();
00049
00057 private function __construct($a_copy_id = 0)
00058 {
00059 global $ilDB;
00060
00061 $this->db = $ilDB;
00062 $this->copy_id = $a_copy_id;
00063
00064 if($this->copy_id)
00065 {
00066 $this->read();
00067 }
00068 }
00069
00078 public static function _getInstance($a_copy_id)
00079 {
00080 if(is_array(self::$instances) and isset(self::$instances[$a_copy_id]))
00081 {
00082 return self::$instances[$a_copy_id];
00083 }
00084 return self::$instances[$a_copy_id] = new ilCopyWizardOptions($a_copy_id);
00085 }
00086
00095 public static function _isFinished($a_copy_id)
00096 {
00097 global $ilDB;
00098
00099 $query = "SELECT * FROM copy_wizard_options ".
00100 " WHERE copy_id = ".$ilDB->quote($a_copy_id)." ";
00101 $res = $ilDB->query($query);
00102 return $res->numRows() ? false : true;
00103 }
00104
00112 public static function _allocateCopyId()
00113 {
00114 global $ilDB;
00115
00116 $query = "SELECT MAX(copy_id) as latest FROM copy_wizard_options ";
00117 $res = $ilDB->query($query);
00118 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00119
00120 $query = "INSERT INTO copy_wizard_options ".
00121 "SET copy_id = ".$ilDB->quote($row->latest + 1);
00122 $ilDB->query($query);
00123
00124 return $row->latest + 1;
00125 }
00126
00134 public function saveOwner($a_user_id)
00135 {
00136 $query = "INSERT INTO copy_wizard_options ".
00137 "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
00138 "source_id = ".$this->db->quote(self::OWNER_KEY).", ".
00139 "options = ".$this->db->quote(serialize(array($a_user_id)))."";
00140 $this->db->query($query);
00141 return true;
00142 }
00143
00151 public function saveRoot($a_root)
00152 {
00153 $query = "INSERT INTO copy_wizard_options ".
00154 "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
00155 "source_id = ".$this->db->quote(self::ROOT_NODE).", ".
00156 "options = ".$this->db->quote(serialize(array($a_root)))."";
00157 $this->db->query($query);
00158 return true;
00159
00160 }
00161
00169 public function isRootNode($a_root)
00170 {
00171 return in_array($a_root,$this->getOptions(self::ROOT_NODE));
00172 }
00173
00181 public function disableSOAP()
00182 {
00183 $this->options[self::DISABLE_SOAP] = 1;
00184 $query = "INSERT INTO copy_wizard_options ".
00185 "SET copy_id = ".$this->db->quote($this->getCopyId()).", ".
00186 "source_id = ".$this->db->quote(self::DISABLE_SOAP).", ".
00187 "options = ".$this->db->quote(serialize(array(1)))."";
00188 $this->db->query($query);
00189 }
00190
00197 public function isSOAPEnabled()
00198 {
00199 if(isset($this->options[self::DISABLE_SOAP]) and $this->options[self::DISABLE_SOAP])
00200 {
00201 return false;
00202 }
00203 return true;
00204 }
00205
00206
00207
00215 public function checkOwner($a_user_id)
00216 {
00217 return in_array($a_user_id,$this->getOptions(self::OWNER_KEY));
00218 }
00219
00226 public function getCopyId()
00227 {
00228 return $this->copy_id;
00229 }
00230
00231
00240 public function initContainer($a_source_id,$a_target_id)
00241 {
00242 global $tree;
00243
00244 $mapping_source = $tree->getParentId($a_source_id);
00245 $this->addEntry($a_source_id,array('type' => ilCopyWizardOptions::COPY_WIZARD_COPY));
00246 $this->appendMapping($mapping_source,$a_target_id);
00247 }
00248
00259 public function storeTree($a_source_id)
00260 {
00261
00262 $query = "DESCRIBE copy_wizard_options";
00263 $res = $this->db->query($query);
00264 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00265 {
00266 if($row->Field == 'options' and $row->Type == 'text')
00267 {
00268 $query = 'ALTER TABLE `copy_wizard_options` CHANGE `options` `options` LONGTEXT NOT NULL';
00269 $this->db->query($query);
00270 }
00271 }
00272
00273 $this->readTree($a_source_id);
00274 $a_tree_structure = $this->tmp_tree;
00275
00276 $query = "UPDATE copy_wizard_options ".
00277 "SET options = ".$this->db->quote(serialize($a_tree_structure))." ".
00278 "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
00279 "AND source_id = 0 ";
00280 $res = $this->db->query($query);
00281
00282 $query = "INSERT INTO copy_wizard_options ".
00283 "SET options = ".$this->db->quote(serialize($a_tree_structure)).", ".
00284 "copy_id = ".$this->db->quote($this->copy_id).", ".
00285 "source_id = -1 ";
00286 $res = $this->db->query($query);
00287 return true;
00288 }
00289
00296 private function fetchFirstNodeById($a_id)
00297 {
00298 $tree = $this->getOptions($a_id);
00299 if(isset($tree[0]) and is_array($tree[0]))
00300 {
00301 return $tree[0];
00302 }
00303 return false;
00304 }
00305
00313 public function fetchFirstNode()
00314 {
00315 return $this->fetchFirstNodeById(0);
00316 }
00317
00324 public function fetchFirstDependenciesNode()
00325 {
00326 return $this->fetchFirstNodeById(-1);
00327 }
00328
00335 public function dropFirstNodeById($a_id)
00336 {
00337 if(!isset($this->options[$a_id]) or !is_array($this->options[$a_id]))
00338 {
00339 return false;
00340 }
00341
00342 $this->options[$a_id] = array_slice($this->options[$a_id],1);
00343 $query = "UPDATE copy_wizard_options ".
00344 "SET options = ".$this->db->quote(serialize($this->options[$a_id]))." ".
00345 "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
00346 "AND source_id = ".$this->db->quote($a_id)." ";
00347 ;
00348 $this->db->query($query);
00349 $this->read();
00350
00351 if(($node = $this->fetchFirstNodeById($a_id)) === false)
00352 {
00353 return true;
00354 }
00355 if($node['type'] == 'rolf')
00356 {
00357 $this->dropFirstNodeById($a_id);
00358 }
00359 return true;
00360 }
00361
00368 public function dropFirstNode()
00369 {
00370 return $this->dropFirstNodeById(0);
00371 }
00372
00379 public function dropFirstDependenciesNode()
00380 {
00381 return $this->dropFirstNodeById(-1);
00382 }
00383
00391 public function getOptions($a_source_id)
00392 {
00393 if(isset($this->options[$a_source_id]) and is_array($this->options[$a_source_id]))
00394 {
00395 return $this->options[$a_source_id];
00396 }
00397 return array();
00398 }
00399
00408 public function addEntry($a_source_id,$a_options)
00409 {
00410 if(!is_array($a_options))
00411 {
00412 return false;
00413 }
00414
00415 $query = "DELETE FROM copy_wizard_options ".
00416 "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
00417 "AND source_id = ".$this->db->quote($a_source_id);
00418 $this->db->query($query);
00419
00420 $query = "INSERT INTO copy_wizard_options ".
00421 "SET copy_id = ".$this->db->quote($this->copy_id).", ".
00422 "source_id = ".$this->db->quote($a_source_id).", ".
00423 "options = ".$this->db->quote(serialize($a_options))." ";
00424 $res = $this->db->query($query);
00425 return true;
00426 }
00427
00436 public function appendMapping($a_source_id,$a_target_id)
00437 {
00438 $query = "SELECT * FROM copy_wizard_options ".
00439 "WHERE copy_id = ".$this->db->quote($this->copy_id)." ".
00440 "AND source_id = -2 ";
00441 $res = $this->db->query($query);
00442 $mappings = array();
00443 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00444 {
00445 $mappings = unserialize($row->options);
00446 }
00447 $mappings[$a_source_id] = $a_target_id;
00448
00449 $query = "REPLACE INTO copy_wizard_options ".
00450 "SET copy_id = ".$this->db->quote($this->copy_id).", ".
00451 "source_id = -2, ".
00452 "options = ".$this->db->quote(serialize($mappings))."";
00453 $this->db->query($query);
00454 return true;
00455 }
00456
00463 public function getMappings()
00464 {
00465 if(isset($this->options[-2]) and is_array($this->options[-2]))
00466 {
00467 return $this->options[-2];
00468 }
00469 return array();
00470 }
00471
00478 public function deleteAll()
00479 {
00480 $query = "DELETE FROM copy_wizard_options ".
00481 "WHERE copy_id = ".$this->db->quote($this->copy_id);
00482 $this->db->query($query);
00483 }
00484
00492 public function read()
00493 {
00494 $query = "SELECT * FROM copy_wizard_options ".
00495 "WHERE copy_id = ".$this->db->quote($this->copy_id);
00496 $res = $this->db->query($query);
00497
00498 $this->options = array();
00499 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00500 {
00501 $this->options[$row->source_id] = unserialize($row->options);
00502 }
00503
00504 return true;
00505 }
00506
00514 private function readTree($a_source_id)
00515 {
00516 global $tree;
00517
00518 $this->tmp_tree[] = $tree->getNodeData($a_source_id);
00519
00520
00521 foreach($tree->getChilds($a_source_id) as $sub_nodes)
00522 {
00523 $sub_node_ref_id = $sub_nodes['child'];
00524
00525 $options = $this->options[$sub_node_ref_id];
00526 if($options['type'] == self::COPY_WIZARD_COPY or
00527 $options['type'] == self::COPY_WIZARD_LINK)
00528 {
00529 $this->readTree($sub_node_ref_id);
00530 }
00531 }
00532 }
00533 }
00534
00535
00536 ?>