• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/class.ilLMObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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;               // assoc array of lm_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                                 // Update Title and description
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 //                                      ilLMObject::_writeDescription($this->getId(),$md_des->getDescription());
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 //echo "-".$a_lm_id."-".$a_lm_obj_id."-".$a_type."-";
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                 // sets first description (maybe not appropriate)
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 //                      $md_des->setDescription($this->getDescription());
00168                         $md_des->update();
00169                 }
00170                 $md_gen->update();
00171 
00172         }
00173 
00174 
00178         function deleteMetaData()
00179         {
00180                 // Delete meta data
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 /*
00213                 $ilBench->start("ContentPresentation", "ilLMObject_read_getMeta");
00214                 $this->meta_data =& new ilMetaData($this->type, $this->id);
00215                 $ilBench->stop("ContentPresentation", "ilLMObject_read_getMeta");
00216 */
00217                 $this->setImportId($this->data_record["import_id"]);
00218                 $this->setTitle($this->data_record["title"]);
00219                 $this->setActive(ilUtil::yn2tf($this->data_record["active"]));
00220 
00221                 $ilBench->stop("ContentPresentation", "ilLMObject_read");
00222         }
00223 
00229         function setTitle($a_title)
00230         {
00231                 $this->title = $a_title;
00232         }
00233 
00239         function getTitle()
00240         {
00241                 return $this->title;
00242         }
00243 
00244 
00245         function _lookupTitle($a_obj_id)
00246         {
00247                 global $ilDB;
00248 
00249                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00250                 $obj_set = $ilDB->query($query);
00251                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00252 
00253                 return $obj_rec["title"];
00254         }
00255         
00256         function _lookupType($a_obj_id)
00257         {
00258                 global $ilDB;
00259 
00260                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00261                 $obj_set = $ilDB->query($query);
00262                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00263 
00264                 return $obj_rec["type"];
00265         }
00266 
00267 
00268         function _writeTitle($a_obj_id, $a_title)
00269         {
00270                 global $ilDB;
00271 
00272                 $query = "UPDATE lm_data SET ".
00273                         " title = ".$ilDB->quote($a_title).
00274                         " WHERE obj_id = ".$ilDB->quote($a_obj_id);
00275                 $ilDB->query($query);
00276         }
00277 
00278 
00279         function setDescription($a_description)
00280         {
00281                 $this->description = $a_description;
00282         }
00283 
00284         function getDescription()
00285         {
00286                 return $this->description;
00287         }
00288 
00289         function setType($a_type)
00290         {
00291                 $this->type = $a_type;
00292         }
00293 
00294         function getType()
00295         {
00296                 return $this->type;
00297         }
00298 
00299         function setLMId($a_lm_id)
00300         {
00301                 $this->lm_id = $a_lm_id;
00302 
00303         }
00304 
00305         function getLMId()
00306         {
00307                 return $this->lm_id;
00308         }
00309 
00310         function setContentObject(&$a_content_obj)
00311         {
00312                 $this->content_object =& $a_content_obj;
00313         }
00314 
00315         function &getContentObject()
00316         {
00317                 return $this->content_object;
00318         }
00319 
00320         function setId($a_id)
00321         {
00322                 $this->id = $a_id;
00323         }
00324 
00325         function getId()
00326         {
00327                 return $this->id;
00328         }
00329 
00330         function getImportId()
00331         {
00332                 return $this->import_id;
00333         }
00334 
00335         function setImportId($a_id)
00336         {
00337                 $this->import_id = $a_id;
00338         }
00339 
00345         function setActive($a_active)
00346         {
00347                 $this->active = $a_active;
00348         }
00349 
00355         function getActive()
00356         {
00357                 return $this->active;
00358         }
00359 
00367         function _writeImportId($a_id, $a_import_id)
00368         {
00369                 global $ilDB;
00370 
00371                 $q = "UPDATE lm_data ".
00372                         "SET ".
00373                         "import_id = ".$ilDB->quote($a_import_id).",".
00374                         "last_update = now() ".
00375                         "WHERE obj_id = ".$ilDB->quote($a_id);
00376 
00377                 $ilDB->query($q);
00378         }
00379 
00380         function create($a_upload = false)
00381         {
00382                 global $ilDB;
00383 
00384                 // insert object data
00385                 $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date, active) ".
00386                         "VALUES ('".ilUtil::prepareDBString($this->getTitle())."','".$this->getType()."', ".$this->getLMId().",'".$this->getImportId().
00387                         "', now(),".$ilDB->quote(ilUtil::tf2yn($this->getActive())).")";
00388                 $this->ilias->db->query($query);
00389                 $this->setId($this->ilias->db->getLastInsertId());
00390 
00391                 // create history entry
00392                 include_once("classes/class.ilHistory.php");
00393                 ilHistory::_createEntry($this->getId(), "create", "",
00394                         $this->content_object->getType().":".$this->getType());
00395 
00396                 if (!$a_upload)
00397                 {
00398                         $this->createMetaData();
00399                 }
00400 
00401         }
00402 
00406         function update()
00407         {
00408                 global $ilDB;
00409 
00410                 $this->updateMetaData();
00411 
00412                 $query = "UPDATE lm_data SET ".
00413                         " lm_id = ".$ilDB->quote($this->getLMId()).
00414                         " ,title = ".$ilDB->quote($this->getTitle()).
00415                         " ,active = ".$ilDB->quote(ilUtil::tf2yn($this->getActive())).
00416                         " WHERE obj_id = ".$ilDB->quote($this->getId());
00417 
00418                 $ilDB->query($query);
00419         }
00420 
00421 
00430         function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
00431         {
00432                 global $ilDB,$ilLog,$ilErr,$ilTree;
00433                 
00434                 if (!is_array($a_pages))
00435                 {$a_pages = array(0);
00436                         /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
00437                         $ilLog->write($message,$ilLog->WARNING);
00438                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00439                         return false;*/
00440                 }
00441                 
00442                 if (empty($a_cont_obj_id))
00443                 {
00444                         $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
00445                         $ilLog->write($message,$ilLog->WARNING);
00446                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00447                         return false;
00448                 }
00449                 
00450                 // update structure entries: if at least one page of a chapter is public set chapter to public too
00451                 $lm_tree = new ilTree($a_cont_obj_id);
00452                 $lm_tree->setTableNames('lm_tree','lm_data');
00453                 $lm_tree->setTreeTablePK("lm_id");
00454                 $lm_tree->readRootId();
00455 
00456                 // get all st entries of cont_obj
00457                 $q = "SELECT obj_id FROM lm_data " . 
00458                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00459                          "AND type = 'st'";
00460                 $r = $ilDB->query($q);
00461                 
00462                 // add chapters with a public page to a_pages
00463                 while ($row = $r->fetchRow())
00464                 {
00465                         $childs = $lm_tree->getChilds($row[0]);
00466                         
00467                         foreach ($childs as $page)
00468                         {
00469                                 if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
00470                                 {
00471                                         array_push($a_pages, $row[0]);
00472                                         break;
00473                                 }
00474                         }
00475                 }
00476                 
00477                 // update public access status of all pages of cont_obj
00478                 $q = "UPDATE lm_data SET " .
00479                          "public_access = CASE " .
00480                          "WHEN obj_id IN (".implode(',',$a_pages).") " .
00481                          "THEN 'y' ".
00482                          "ELSE 'n' ".
00483                          "END " .
00484                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00485                          "AND type IN ('pg','st')";
00486                 $ilDB->query($q);
00487                 
00488                 return true;
00489         }
00490         
00491         function _isPagePublic($a_node_id,$a_check_public_mode = false)
00492         {
00493                 global $ilDB,$ilLog;
00494 
00495                 if (empty($a_node_id))
00496                 {
00497                         $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00498                         $ilLog->write($message,$ilLog->WARNING);
00499                         return false;
00500                 }
00501                 
00502                 if ($a_check_public_mode === true)
00503                 {
00504                         $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00505 
00506                         $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00507                         $r = $ilDB->query($q);
00508                         $row = $r->fetchRow();
00509                         
00510                         if ($row[0] == "complete")
00511                         {
00512                                 return true;
00513                         }
00514                 }
00515 
00516                 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00517                 $r = $ilDB->query($q);
00518                 $row = $r->fetchRow();
00519                 
00520                 return ilUtil::yn2tf($row[0]);
00521         }
00522 
00526         function delete($a_delete_meta_data = true)
00527         {
00528                 $query = "DELETE FROM lm_data WHERE obj_id= '".$this->getId()."'";
00529                 $this->ilias->db->query($query);
00530 
00531                 $this->deleteMetaData();
00532         }
00533 
00545         function _getIdForImportId($a_import_id)
00546         {
00547                 global $ilDB;
00548                 
00549                 $q = "SELECT * FROM lm_data WHERE import_id = '".$a_import_id."'".
00550                         " ORDER BY create_date DESC LIMIT 1";
00551                 $obj_set = $ilDB->query($q);
00552                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00553                 {
00554                         $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00555 
00556                         // link only in learning module, that is not trashed
00557                         if (ilObject::_hasUntrashedReference($lm_id))
00558                         {
00559                                 return $obj_rec["obj_id"];
00560                         }
00561                 }
00562 
00563                 return 0;
00564         }
00565         
00573         function _exists($a_id)
00574         {
00575                 global $ilDB;
00576                 
00577                 include_once("content/classes/Pages/class.ilInternalLink.php");
00578                 if (is_int(strpos($a_id, "_")))
00579                 {
00580                         $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00581                 }
00582                 
00583                 $q = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00584                 $obj_set = $ilDB->query($q);
00585                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00586                 {
00587                         return true;
00588                 }
00589                 else
00590                 {
00591                         return false;
00592                 }
00593 
00594         }
00595 
00599         function getObjectList($lm_id, $type = "")
00600         {
00601                 global $ilDB;
00602                 
00603                 $type_str = ($type != "")
00604                         ? "AND type = '$type' "
00605                         : "";
00606                 $query = "SELECT * FROM lm_data ".
00607                         "WHERE lm_id= '".$lm_id."'".
00608                         $type_str." ".
00609                         "ORDER BY title";
00610                 $obj_set = $ilDB->query($query);
00611                 $obj_list = array();
00612                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00613                 {
00614                         $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00615                                                                 "title" => $obj_rec["title"],
00616                                                                 "type" => $obj_rec["type"]);
00617                 }
00618                 return $obj_list;
00619         }
00620 
00621 
00625         function _deleteAllObjectData(&$a_cobj)
00626         {
00627                 include_once './classes/class.ilNestedSetXML.php';
00628 
00629                 $query = "SELECT * FROM lm_data ".
00630                         "WHERE lm_id= '".$a_cobj->getId()."'";
00631                 $obj_set = $this->ilias->db->query($query);
00632 
00633                 require_once("content/classes/class.ilLMObjectFactory.php");
00634                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00635                 {
00636                         $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
00637 
00638                         if (is_object($lm_obj))
00639                         {
00640                                 $lm_obj->delete(true);
00641                         }
00642                 }
00643 
00644                 return true;
00645         }
00646 
00650         function _lookupContObjID($a_id)
00651         {
00652                 global $ilDB;
00653 
00654                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00655                 $obj_set = $ilDB->query($query);
00656                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00657 
00658                 return $obj_rec["lm_id"];
00659         }
00660 
00664         function _lookupActive($a_id)
00665         {
00666                 global $ilDB;
00667 
00668                 $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id);
00669                 $obj_set = $ilDB->query($query);
00670                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00671 
00672                 return ilUtil::yn2tf($obj_rec["active"]);
00673         }
00674 
00678         function _writeActive($a_id, $a_active)
00679         {
00680                 global $ilDB;
00681 
00682                 $query = "UPDATE lm_data ".
00683                         " SET active = ".$ilDB->quote(ilUtil::tf2yn($a_active)).
00684                         " WHERE obj_id = '".$a_id."'";
00685                 $ilDB->query($query);
00686         }
00687 
00688 }
00689 ?>

Generated on Fri Dec 13 2013 13:52:09 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1