00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
00025
00036 class ilLMObject
00037 {
00038 var $ilias;
00039 var $lm_id;
00040 var $type;
00041 var $id;
00042 var $meta_data;
00043 var $data_record;
00044 var $content_object;
00045 var $title;
00046 var $description;
00047 var $active = true;
00048
00052 function ilLMObject(&$a_content_obj, $a_id = 0)
00053 {
00054 global $ilias;
00055
00056 $this->ilias =& $ilias;
00057 $this->id = $a_id;
00058 $this->setContentObject($a_content_obj);
00059 $this->setLMId($a_content_obj->getId());
00060 if($a_id != 0)
00061 {
00062 $this->read();
00063 }
00064 }
00065
00077 function MDUpdateListener($a_element)
00078 {
00079 include_once 'Services/MetaData/classes/class.ilMD.php';
00080
00081 switch($a_element)
00082 {
00083 case 'General':
00084
00085
00086 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00087 $md_gen = $md->getGeneral();
00088
00089 ilLMObject::_writeTitle($this->getId(),$md_gen->getTitle());
00090
00091 foreach($md_gen->getDescriptionIds() as $id)
00092 {
00093 $md_des = $md_gen->getDescription($id);
00094
00095 break;
00096 }
00097
00098 break;
00099
00100 default:
00101 }
00102 return true;
00103 }
00104
00105
00109 function _lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
00110 {
00111 include_once 'Services/MetaData/classes/class.ilMD.php';
00112
00113 $md = new ilMD($a_lm_id, $a_lm_obj_id, $a_type);
00114 $md_gen = $md->getGeneral();
00115 foreach($md_gen->getIdentifierIds() as $id)
00116 {
00117 $md_id = $md_gen->getIdentifier($id);
00118 if ($md_id->getCatalog() == "ILIAS_NID")
00119 {
00120 return $md_id->getEntry();
00121 }
00122 }
00123
00124 return false;
00125 }
00126
00127
00131 function createMetaData()
00132 {
00133 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00134
00135 global $ilUser;
00136
00137 $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
00138 $md_creator->setTitle($this->getTitle());
00139 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00140 $md_creator->setDescription($this->getDescription());
00141 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00142 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00143 $md_creator->setLanguage($ilUser->getPref('language'));
00144 $md_creator->create();
00145
00146 return true;
00147 }
00148
00152 function updateMetaData()
00153 {
00154 include_once("Services/MetaData/classes/class.ilMD.php");
00155 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00156 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00157
00158 $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
00159 $md_gen =& $md->getGeneral();
00160 $md_gen->setTitle($this->getTitle());
00161
00162
00163 $md_des_ids =& $md_gen->getDescriptionIds();
00164 if (count($md_des_ids) > 0)
00165 {
00166 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00167
00168 $md_des->update();
00169 }
00170 $md_gen->update();
00171
00172 }
00173
00174
00178 function deleteMetaData()
00179 {
00180
00181 include_once('Services/MetaData/classes/class.ilMD.php');
00182 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00183 $md->deleteAll();
00184 }
00185
00186
00187
00191 function setDataRecord($a_record)
00192 {
00193 $this->data_record = $a_record;
00194 }
00195
00196 function read()
00197 {
00198 global $ilBench, $ilDB;
00199
00200 $ilBench->start("ContentPresentation", "ilLMObject_read");
00201
00202 if(!isset($this->data_record))
00203 {
00204 $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
00205 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($this->id);
00206 $obj_set = $this->ilias->db->query($query);
00207 $this->data_record = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00208 $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
00209 }
00210
00211 $this->type = $this->data_record["type"];
00212 $this->setImportId($this->data_record["import_id"]);
00213 $this->setTitle($this->data_record["title"]);
00214 $this->setActive(ilUtil::yn2tf($this->data_record["active"]));
00215
00216 $ilBench->stop("ContentPresentation", "ilLMObject_read");
00217 }
00218
00224 function setTitle($a_title)
00225 {
00226 $this->title = $a_title;
00227 }
00228
00234 function getTitle()
00235 {
00236 return $this->title;
00237 }
00238
00239
00240 function _lookupTitle($a_obj_id)
00241 {
00242 global $ilDB;
00243
00244 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id);
00245 $obj_set = $ilDB->query($query);
00246 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00247
00248 return $obj_rec["title"];
00249 }
00250
00251 function _lookupType($a_obj_id)
00252 {
00253 global $ilDB;
00254
00255 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id);
00256 $obj_set = $ilDB->query($query);
00257 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00258
00259 return $obj_rec["type"];
00260 }
00261
00262
00263 function _writeTitle($a_obj_id, $a_title)
00264 {
00265 global $ilDB;
00266
00267 $query = "UPDATE lm_data SET ".
00268 " title = ".$ilDB->quote($a_title).
00269 " WHERE obj_id = ".$ilDB->quote($a_obj_id);
00270 $ilDB->query($query);
00271 }
00272
00273
00274 function setDescription($a_description)
00275 {
00276 $this->description = $a_description;
00277 }
00278
00279 function getDescription()
00280 {
00281 return $this->description;
00282 }
00283
00284 function setType($a_type)
00285 {
00286 $this->type = $a_type;
00287 }
00288
00289 function getType()
00290 {
00291 return $this->type;
00292 }
00293
00294 function setLMId($a_lm_id)
00295 {
00296 $this->lm_id = $a_lm_id;
00297
00298 }
00299
00300 function getLMId()
00301 {
00302 return $this->lm_id;
00303 }
00304
00305 function setContentObject(&$a_content_obj)
00306 {
00307 $this->content_object =& $a_content_obj;
00308 }
00309
00310 function &getContentObject()
00311 {
00312 return $this->content_object;
00313 }
00314
00315 function setId($a_id)
00316 {
00317 $this->id = $a_id;
00318 }
00319
00320 function getId()
00321 {
00322 return $this->id;
00323 }
00324
00325 function getImportId()
00326 {
00327 return $this->import_id;
00328 }
00329
00330 function setImportId($a_id)
00331 {
00332 $this->import_id = $a_id;
00333 }
00334
00340 function setActive($a_active)
00341 {
00342 $this->active = $a_active;
00343 }
00344
00350 function getActive()
00351 {
00352 return $this->active;
00353 }
00354
00362 function _writeImportId($a_id, $a_import_id)
00363 {
00364 global $ilDB;
00365
00366 $q = "UPDATE lm_data ".
00367 "SET ".
00368 "import_id = ".$ilDB->quote($a_import_id).",".
00369 "last_update = now() ".
00370 "WHERE obj_id = ".$ilDB->quote($a_id);
00371
00372 $ilDB->query($q);
00373 }
00374
00375 function create($a_upload = false)
00376 {
00377 global $ilDB;
00378
00379
00380 $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date, active) ".
00381 "VALUES (".$ilDB->quote($this->getTitle()).",".$ilDB->quote($this->getType()).", ".
00382 $ilDB->quote($this->getLMId()).",".$ilDB->quote($this->getImportId()).
00383 ", now(),".$ilDB->quote(ilUtil::tf2yn($this->getActive())).")";
00384 $this->ilias->db->query($query);
00385 $this->setId($this->ilias->db->getLastInsertId());
00386
00387
00388 include_once("classes/class.ilHistory.php");
00389 ilHistory::_createEntry($this->getId(), "create", "",
00390 $this->content_object->getType().":".$this->getType());
00391
00392 if (!$a_upload)
00393 {
00394 $this->createMetaData();
00395 }
00396
00397 }
00398
00402 function update()
00403 {
00404 global $ilDB;
00405
00406 $this->updateMetaData();
00407
00408 $query = "UPDATE lm_data SET ".
00409 " lm_id = ".$ilDB->quote($this->getLMId()).
00410 " ,title = ".$ilDB->quote($this->getTitle()).
00411 " ,active = ".$ilDB->quote(ilUtil::tf2yn($this->getActive())).
00412 " WHERE obj_id = ".$ilDB->quote($this->getId());
00413
00414 $ilDB->query($query);
00415 }
00416
00417
00426 function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
00427 {
00428 global $ilDB,$ilLog,$ilErr,$ilTree;
00429
00430 if (!is_array($a_pages))
00431 {$a_pages = array(0);
00432
00433
00434
00435
00436 }
00437
00438 if (empty($a_cont_obj_id))
00439 {
00440 $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
00441 $ilLog->write($message,$ilLog->WARNING);
00442 $ilErr->raiseError($message,$ilErr->MESSAGE);
00443 return false;
00444 }
00445
00446
00447 $lm_tree = new ilTree($a_cont_obj_id);
00448 $lm_tree->setTableNames('lm_tree','lm_data');
00449 $lm_tree->setTreeTablePK("lm_id");
00450 $lm_tree->readRootId();
00451
00452
00453 $q = "SELECT obj_id FROM lm_data " .
00454 "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00455 "AND type = 'st'";
00456 $r = $ilDB->query($q);
00457
00458
00459 while ($row = $r->fetchRow())
00460 {
00461 $childs = $lm_tree->getChilds($row[0]);
00462
00463 foreach ($childs as $page)
00464 {
00465 if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
00466 {
00467 array_push($a_pages, $row[0]);
00468 break;
00469 }
00470 }
00471 }
00472
00473
00474 $q = "UPDATE lm_data SET " .
00475 "public_access = CASE " .
00476 "WHEN obj_id IN (".implode(',',ilUtil::quoteArray($a_pages)).") " .
00477 "THEN 'y' ".
00478 "ELSE 'n' ".
00479 "END " .
00480 "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00481 "AND type IN ('pg','st')";
00482 $ilDB->query($q);
00483
00484 return true;
00485 }
00486
00487 function _isPagePublic($a_node_id,$a_check_public_mode = false)
00488 {
00489 global $ilDB,$ilLog;
00490
00491 if (empty($a_node_id))
00492 {
00493 $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00494 $ilLog->write($message,$ilLog->WARNING);
00495 return false;
00496 }
00497
00498 if ($a_check_public_mode === true)
00499 {
00500 $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00501
00502 $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00503 $r = $ilDB->query($q);
00504 $row = $r->fetchRow();
00505
00506 if ($row[0] == "complete")
00507 {
00508 return true;
00509 }
00510 }
00511
00512 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00513 $r = $ilDB->query($q);
00514 $row = $r->fetchRow();
00515
00516 return ilUtil::yn2tf($row[0]);
00517 }
00518
00522 function delete($a_delete_meta_data = true)
00523 {
00524 global $ilDB;
00525
00526 $query = "DELETE FROM lm_data WHERE obj_id= ".$ilDB->quote($this->getId());
00527 $this->ilias->db->query($query);
00528
00529 $this->deleteMetaData();
00530 }
00531
00543 function _getIdForImportId($a_import_id)
00544 {
00545 global $ilDB;
00546
00547 $q = "SELECT * FROM lm_data WHERE import_id = ".$ilDB->quote($a_import_id)." ".
00548 " ORDER BY create_date DESC LIMIT 1";
00549 $obj_set = $ilDB->query($q);
00550 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00551 {
00552 $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00553
00554
00555 if (ilObject::_hasUntrashedReference($lm_id))
00556 {
00557 return $obj_rec["obj_id"];
00558 }
00559 }
00560
00561 return 0;
00562 }
00563
00573 function _getAllObjectsForImportId($a_import_id)
00574 {
00575 global $ilDB;
00576
00577 $q = "SELECT * FROM lm_data WHERE import_id = ".$ilDB->quote($a_import_id)." ".
00578 " ORDER BY create_date DESC";
00579 $obj_set = $ilDB->query($q);
00580
00581 $items = array();
00582 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00583 {
00584
00585 if (ilObject::_hasUntrashedReference($obj_rec["lm_id"]))
00586 {
00587 $items[] = $obj_rec;
00588 }
00589 }
00590
00591 return $items;
00592 }
00593
00601 function _exists($a_id)
00602 {
00603 global $ilDB;
00604
00605 include_once("./Services/COPage/classes/class.ilInternalLink.php");
00606 if (is_int(strpos($a_id, "_")))
00607 {
00608 $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00609 }
00610
00611 $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id);
00612 $obj_set = $ilDB->query($q);
00613 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00614 {
00615 return true;
00616 }
00617 else
00618 {
00619 return false;
00620 }
00621
00622 }
00623
00627 function getObjectList($lm_id, $type = "")
00628 {
00629 global $ilDB;
00630
00631 $type_str = ($type != "")
00632 ? "AND type = ".$ilDB->quote($type)." "
00633 : "";
00634 $query = "SELECT * FROM lm_data ".
00635 "WHERE lm_id= ".$ilDB->quote($lm_id)." ".
00636 $type_str." ".
00637 "ORDER BY title";
00638 $obj_set = $ilDB->query($query);
00639 $obj_list = array();
00640 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00641 {
00642 $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00643 "title" => $obj_rec["title"],
00644 "type" => $obj_rec["type"]);
00645 }
00646 return $obj_list;
00647 }
00648
00649
00653 function _deleteAllObjectData(&$a_cobj)
00654 {
00655 global $ilDB;
00656
00657 include_once './classes/class.ilNestedSetXML.php';
00658
00659 $query = "SELECT * FROM lm_data ".
00660 "WHERE lm_id= ".$ilDB->quote($a_cobj->getId())." ";
00661 $obj_set = $this->ilias->db->query($query);
00662
00663 require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
00664 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00665 {
00666 $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
00667
00668 if (is_object($lm_obj))
00669 {
00670 $lm_obj->delete(true);
00671 }
00672 }
00673
00674 return true;
00675 }
00676
00680 function _lookupContObjID($a_id)
00681 {
00682 global $ilDB;
00683
00684 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id)."";
00685 $obj_set = $ilDB->query($query);
00686 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00687
00688 return $obj_rec["lm_id"];
00689 }
00690
00694 function _lookupActive($a_id)
00695 {
00696 global $ilDB;
00697
00698 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id);
00699 $obj_set = $ilDB->query($query);
00700 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00701
00702 return ilUtil::yn2tf($obj_rec["active"]);
00703 }
00704
00708 function _writeActive($a_id, $a_active)
00709 {
00710 global $ilDB;
00711
00712 $query = "UPDATE lm_data ".
00713 " SET active = ".$ilDB->quote(ilUtil::tf2yn($a_active)).
00714 " WHERE obj_id = ".$ilDB->quote($a_id);
00715 $ilDB->query($query);
00716 }
00717
00721 static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
00722 {
00723 foreach($a_copied_nodes as $original_id => $copied_id)
00724 {
00725 if (ilLMObject::_lookupType($copied_id) == "pg")
00726 {
00727
00728
00729
00730 $targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
00731 $copy_lm = ilLMObject::_lookupContObjID($copied_id);
00732 $fix = array();
00733 foreach($targets as $target)
00734 {
00735 if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
00736 ($target["type"] == "pg" || $target["type"] == "st"))
00737 {
00738
00739 if ($a_copied_nodes[$target["id"]] > 0)
00740 {
00741 $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
00742 }
00743 else
00744 {
00745
00746 $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$target["type"]."_".$target["id"]);
00747 $found = false;
00748
00749 foreach($lm_data as $item)
00750 {
00751 if (!$found && ($item["lm_id"] == $copy_lm))
00752 {
00753 $fix[$target["id"]] = $item["obj_id"];
00754 }
00755 }
00756
00757 if (!$found)
00758 {
00759
00760 }
00761 }
00762 }
00763 }
00764
00765
00766 if (count($fix) > 0)
00767 {
00768 $page = new ilPageObject(ilObject::_lookupType($copy_lm), $copied_id);
00769 $page->moveIntLinks($fix);
00770 $page->update();
00771 }
00772
00773
00774
00775
00776
00777
00778
00779
00780 $original_lm = ilLMObject::_lookupContObjID($original_id);
00781 $original_type = ilObject::_lookupType($original_lm);
00782
00783
00784 $sources = ilInternalLink::_getSourcesOfTarget("pg", $original_id, 0);
00785 $fix = array();
00786 foreach($sources as $source)
00787 {
00788 $stype = explode(":", $source["type"]);
00789 $source_type = $stype[1];
00790
00791 if ($source_type == "pg" || $source_type == "st")
00792 {
00793
00794
00795 $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$source_type."_".$source["id"]);
00796 $found = false;
00797 foreach($lm_data as $item)
00798 {
00799 if (!$found && ($item["lm_id"] == $copy_lm))
00800 {
00801 $fix[$item["obj_id"]][$original_id] = $copied_id;
00802 }
00803 }
00804
00805 if (!$found)
00806 {
00807
00808 }
00809 }
00810 }
00811
00812
00813 if (count($fix) > 0)
00814 {
00815 foreach ($fix as $page_id => $fix_array)
00816 {
00817 $page = new ilPageObject(ilObject::_lookupType($copy_lm), $page_id);
00818 $page->moveIntLinks($fix_array);
00819 $page->update();
00820 }
00821 }
00822 }
00823 }
00824 }
00825 }
00826 ?>