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("classes/class.ilMetaData.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
00051 function ilLMObject(&$a_content_obj, $a_id = 0)
00052 {
00053 global $ilias;
00054
00055 $this->ilias =& $ilias;
00056 $this->id = $a_id;
00057 $this->setContentObject($a_content_obj);
00058 $this->setLMId($a_content_obj->getId());
00059 if($a_id != 0)
00060 {
00061 $this->read();
00062 }
00063 }
00064
00076 function MDUpdateListener($a_element)
00077 {
00078 include_once 'Services/MetaData/classes/class.ilMD.php';
00079
00080 switch($a_element)
00081 {
00082 case 'General':
00083
00084
00085 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00086 $md_gen = $md->getGeneral();
00087
00088 ilLMObject::_writeTitle($this->getId(),$md_gen->getTitle());
00089
00090 foreach($md_gen->getDescriptionIds() as $id)
00091 {
00092 $md_des = $md_gen->getDescription($id);
00093
00094 break;
00095 }
00096
00097 break;
00098
00099 default:
00100 }
00101 return true;
00102 }
00103
00104
00108 function _lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
00109 {
00110 include_once 'Services/MetaData/classes/class.ilMD.php';
00111
00112 $md = new ilMD($a_lm_id, $a_lm_obj_id, $a_type);
00113 $md_gen = $md->getGeneral();
00114 foreach($md_gen->getIdentifierIds() as $id)
00115 {
00116 $md_id = $md_gen->getIdentifier($id);
00117 if ($md_id->getCatalog() == "ILIAS_NID")
00118 {
00119 return $md_id->getEntry();
00120 }
00121 }
00122
00123 return false;
00124 }
00125
00126
00130 function createMetaData()
00131 {
00132 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00133
00134 global $ilUser;
00135
00136 $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
00137 $md_creator->setTitle($this->getTitle());
00138 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00139 $md_creator->setDescription($this->getDescription());
00140 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00141 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00142 $md_creator->setLanguage($ilUser->getPref('language'));
00143 $md_creator->create();
00144
00145 return true;
00146 }
00147
00151 function updateMetaData()
00152 {
00153 include_once("Services/MetaData/classes/class.ilMD.php");
00154 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00155 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00156
00157 $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
00158 $md_gen =& $md->getGeneral();
00159 $md_gen->setTitle($this->getTitle());
00160
00161
00162 $md_des_ids =& $md_gen->getDescriptionIds();
00163 if (count($md_des_ids) > 0)
00164 {
00165 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00166
00167 $md_des->update();
00168 }
00169 $md_gen->update();
00170
00171 }
00172
00173
00177 function deleteMetaData()
00178 {
00179
00180 include_once('Services/MetaData/classes/class.ilMD.php');
00181 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00182 $md->deleteAll();
00183 }
00184
00185
00186
00190 function setDataRecord($a_record)
00191 {
00192 $this->data_record = $a_record;
00193 }
00194
00195 function read()
00196 {
00197 global $ilBench;
00198
00199 $ilBench->start("ContentPresentation", "ilLMObject_read");
00200
00201 if(!isset($this->data_record))
00202 {
00203 $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
00204 $query = "SELECT * FROM lm_data WHERE obj_id = '".$this->id."'";
00205 $obj_set = $this->ilias->db->query($query);
00206 $this->data_record = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00207 $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
00208 }
00209
00210 $this->type = $this->data_record["type"];
00211
00212
00213
00214
00215
00216 $this->setImportId($this->data_record["import_id"]);
00217 $this->setTitle($this->data_record["title"]);
00218
00219 $ilBench->stop("ContentPresentation", "ilLMObject_read");
00220 }
00221
00225 function setTitle($a_title)
00226 {
00227
00228 $this->title = $a_title;
00229 }
00230
00231 function getTitle()
00232 {
00233
00234 return $this->title;
00235 }
00236
00237
00238 function _lookupTitle($a_obj_id)
00239 {
00240 global $ilDB;
00241
00242 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00243 $obj_set = $ilDB->query($query);
00244 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00245
00246 return $obj_rec["title"];
00247 }
00248
00249 function _lookupType($a_obj_id)
00250 {
00251 global $ilDB;
00252
00253 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00254 $obj_set = $ilDB->query($query);
00255 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00256
00257 return $obj_rec["type"];
00258 }
00259
00260
00261 function _writeTitle($a_obj_id, $a_title)
00262 {
00263 global $ilDB;
00264
00265 $query = "UPDATE lm_data SET ".
00266 " title = ".$ilDB->quote($a_title).
00267 " WHERE obj_id = ".$ilDB->quote($a_obj_id);
00268 $ilDB->query($query);
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 function setDescription($a_description)
00284 {
00285
00286 $this->description = $a_description;
00287 }
00288
00289 function getDescription()
00290 {
00291
00292 return $this->description;
00293 }
00294
00295 function setType($a_type)
00296 {
00297 $this->type = $a_type;
00298 }
00299
00300 function getType()
00301 {
00302 return $this->type;
00303 }
00304
00305 function setLMId($a_lm_id)
00306 {
00307 $this->lm_id = $a_lm_id;
00308
00309 }
00310
00311 function getLMId()
00312 {
00313 return $this->lm_id;
00314 }
00315
00316 function setContentObject(&$a_content_obj)
00317 {
00318 $this->content_object =& $a_content_obj;
00319 }
00320
00321 function &getContentObject()
00322 {
00323 return $this->content_object;
00324 }
00325
00326 function setId($a_id)
00327 {
00328 $this->id = $a_id;
00329 }
00330
00331 function getId()
00332 {
00333 return $this->id;
00334 }
00335
00336 function getImportId()
00337 {
00338 return $this->import_id;
00339 }
00340
00341 function setImportId($a_id)
00342 {
00343 $this->import_id = $a_id;
00344 }
00345
00353 function _writeImportId($a_id, $a_import_id)
00354 {
00355 global $ilDB;
00356
00357 $q = "UPDATE lm_data ".
00358 "SET ".
00359 "import_id = ".$ilDB->quote($a_import_id).",".
00360 "last_update = now() ".
00361 "WHERE obj_id = ".$ilDB->quote($a_id);
00362
00363 $ilDB->query($q);
00364 }
00365
00366 function create($a_upload = false)
00367 {
00368
00369 $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date) ".
00370 "VALUES ('".ilUtil::prepareDBString($this->getTitle())."','".$this->getType()."', ".$this->getLMId().",'".$this->getImportId().
00371 "', now())";
00372 $this->ilias->db->query($query);
00373 $this->setId($this->ilias->db->getLastInsertId());
00374
00375
00376 include_once("classes/class.ilHistory.php");
00377 ilHistory::_createEntry($this->getId(), "create", "",
00378 $this->content_object->getType().":pg");
00379
00380 if (!$a_upload)
00381 {
00382 $this->createMetaData();
00383 }
00384
00385 }
00386
00390 function update()
00391 {
00392 global $ilDB;
00393
00394 $this->updateMetaData();
00395
00396 $query = "UPDATE lm_data SET ".
00397 " lm_id = ".$ilDB->quote($this->getLMId()).
00398 " ,title = ".$ilDB->quote($this->getTitle()).
00399 " WHERE obj_id = ".$ilDB->quote($this->getId());
00400
00401 $ilDB->query($query);
00402 }
00403
00404
00413 function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
00414 {
00415 global $ilDB,$ilLog,$ilErr,$ilTree;
00416
00417 if (!is_array($a_pages))
00418 {$a_pages = array(0);
00419
00420
00421
00422
00423 }
00424
00425 if (empty($a_cont_obj_id))
00426 {
00427 $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
00428 $ilLog->write($message,$ilLog->WARNING);
00429 $ilErr->raiseError($message,$ilErr->MESSAGE);
00430 return false;
00431 }
00432
00433
00434 $lm_tree = new ilTree($a_cont_obj_id);
00435 $lm_tree->setTableNames('lm_tree','lm_data');
00436 $lm_tree->setTreeTablePK("lm_id");
00437 $lm_tree->readRootId();
00438
00439
00440 $q = "SELECT obj_id FROM lm_data " .
00441 "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00442 "AND type = 'st'";
00443 $r = $ilDB->query($q);
00444
00445
00446 while ($row = $r->fetchRow())
00447 {
00448 $childs = $lm_tree->getChilds($row[0]);
00449
00450 foreach ($childs as $page)
00451 {
00452 if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
00453 {
00454 array_push($a_pages, $row[0]);
00455 break;
00456 }
00457 }
00458 }
00459
00460
00461 $q = "UPDATE lm_data SET " .
00462 "public_access = CASE " .
00463 "WHEN obj_id IN (".implode(',',$a_pages).") " .
00464 "THEN 'y' ".
00465 "ELSE 'n' ".
00466 "END " .
00467 "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00468 "AND type IN ('pg','st')";
00469 $ilDB->query($q);
00470
00471 return true;
00472 }
00473
00474 function _isPagePublic($a_node_id,$a_check_public_mode = false)
00475 {
00476 global $ilDB,$ilLog;
00477
00478 if (empty($a_node_id))
00479 {
00480 $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00481 $ilLog->write($message,$ilLog->WARNING);
00482 return false;
00483 }
00484
00485 if ($a_check_public_mode === true)
00486 {
00487 $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00488
00489 $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00490 $r = $ilDB->query($q);
00491 $row = $r->fetchRow();
00492
00493 if ($row[0] == "complete")
00494 {
00495 return true;
00496 }
00497 }
00498
00499 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00500 $r = $ilDB->query($q);
00501 $row = $r->fetchRow();
00502
00503 return ilUtil::yn2tf($row[0]);
00504 }
00505
00509 function delete($a_delete_meta_data = true)
00510 {
00511 $query = "DELETE FROM lm_data WHERE obj_id= '".$this->getId()."'";
00512 $this->ilias->db->query($query);
00513
00514 $this->deleteMetaData();
00515 }
00516
00528 function _getIdForImportId($a_import_id)
00529 {
00530 global $ilDB;
00531
00532 $q = "SELECT * FROM lm_data WHERE import_id = '".$a_import_id."'".
00533 " ORDER BY create_date DESC LIMIT 1";
00534 $obj_set = $ilDB->query($q);
00535 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00536 {
00537 $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00538
00539
00540 if (ilObject::_hasUntrashedReference($lm_id))
00541 {
00542 return $obj_rec["obj_id"];
00543 }
00544 }
00545
00546 return 0;
00547 }
00548
00556 function _exists($a_id)
00557 {
00558 global $ilDB;
00559
00560 include_once("content/classes/Pages/class.ilInternalLink.php");
00561 if (is_int(strpos($a_id, "_")))
00562 {
00563 $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00564 }
00565
00566 $q = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00567 $obj_set = $ilDB->query($q);
00568 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00569 {
00570 return true;
00571 }
00572 else
00573 {
00574 return false;
00575 }
00576
00577 }
00578
00582 function getObjectList($lm_id, $type = "")
00583 {
00584 global $ilDB;
00585
00586 $type_str = ($type != "")
00587 ? "AND type = '$type' "
00588 : "";
00589 $query = "SELECT * FROM lm_data ".
00590 "WHERE lm_id= '".$lm_id."'".
00591 $type_str." ".
00592 "ORDER BY title";
00593 $obj_set = $ilDB->query($query);
00594 $obj_list = array();
00595 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00596 {
00597 $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00598 "title" => $obj_rec["title"],
00599 "type" => $obj_rec["type"]);
00600 }
00601 return $obj_list;
00602 }
00603
00604
00608 function _deleteAllObjectData(&$a_cobj)
00609 {
00610 include_once './classes/class.ilNestedSetXML.php';
00611
00612 $query = "SELECT * FROM lm_data ".
00613 "WHERE lm_id= '".$a_cobj->getId()."'";
00614 $obj_set = $this->ilias->db->query($query);
00615
00616 require_once("content/classes/class.ilLMObjectFactory.php");
00617 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00618 {
00619 $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
00620
00621 if (is_object($lm_obj))
00622 {
00623 $lm_obj->delete(true);
00624 }
00625 }
00626
00627 return true;
00628 }
00629
00633 function _lookupContObjID($a_id)
00634 {
00635 global $ilDB;
00636
00637 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00638 $obj_set = $ilDB->query($query);
00639 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00640
00641 return $obj_rec["lm_id"];
00642 }
00643
00644 }
00645 ?>