• Main Page
  • Related Pages
  • 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-2001 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 
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                                 // Update Title and description
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 //                                      ilLMObject::_writeDescription($this->getId(),$md_des->getDescription());
00094                                         break;
00095                                 }
00096 
00097                                 break;
00098 
00099                         default:
00100                 }
00101                 return true;
00102         }
00103 
00107         function createMetaData()
00108         {
00109                 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00110 
00111                 global $ilUser;
00112 
00113                 $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
00114                 $md_creator->setTitle($this->getTitle());
00115                 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00116                 $md_creator->setDescription($this->getDescription());
00117                 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00118                 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00119                 $md_creator->setLanguage($ilUser->getPref('language'));
00120                 $md_creator->create();
00121 
00122                 return true;
00123         }
00124 
00128         function updateMetaData()
00129         {
00130                 include_once("Services/MetaData/classes/class.ilMD.php");
00131                 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00132                 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00133 
00134                 $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
00135                 $md_gen =& $md->getGeneral();
00136                 $md_gen->setTitle($this->getTitle());
00137 
00138                 // sets first description (maybe not appropriate)
00139                 $md_des_ids =& $md_gen->getDescriptionIds();
00140                 if (count($md_des_ids) > 0)
00141                 {
00142                         $md_des =& $md_gen->getDescription($md_des_ids[0]);
00143 //                      $md_des->setDescription($this->getDescription());
00144                         $md_des->update();
00145                 }
00146                 $md_gen->update();
00147 
00148         }
00149 
00150 
00154         function deleteMetaData()
00155         {
00156                 // Delete meta data
00157                 include_once('Services/MetaData/classes/class.ilMD.php');
00158                 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
00159                 $md->deleteAll();
00160         }
00161 
00162 
00163 
00167         function setDataRecord($a_record)
00168         {
00169                 $this->data_record = $a_record;
00170         }
00171 
00172         function read()
00173         {
00174                 global $ilBench;
00175 
00176                 $ilBench->start("ContentPresentation", "ilLMObject_read");
00177 
00178                 if(!isset($this->data_record))
00179                 {
00180                         $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
00181                         $query = "SELECT * FROM lm_data WHERE obj_id = '".$this->id."'";
00182                         $obj_set = $this->ilias->db->query($query);
00183                         $this->data_record = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00184                         $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
00185                 }
00186 
00187                 $this->type = $this->data_record["type"];
00188 /*
00189                 $ilBench->start("ContentPresentation", "ilLMObject_read_getMeta");
00190                 $this->meta_data =& new ilMetaData($this->type, $this->id);
00191                 $ilBench->stop("ContentPresentation", "ilLMObject_read_getMeta");
00192 */
00193                 $this->setImportId($this->data_record["import_id"]);
00194                 $this->setTitle($this->data_record["title"]);
00195 
00196                 $ilBench->stop("ContentPresentation", "ilLMObject_read");
00197         }
00198 
00202         function setTitle($a_title)
00203         {
00204 //              $this->meta_data->setTitle($a_title);
00205                 $this->title = $a_title;
00206         }
00207 
00208         function getTitle()
00209         {
00210 //              return $this->title ? $this->title : $this->meta_data->getTitle();
00211                 return $this->title;
00212         }
00213 
00214 
00215         function _lookupTitle($a_obj_id)
00216         {
00217                 global $ilDB;
00218 
00219                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00220                 $obj_set = $ilDB->query($query);
00221                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00222 
00223                 return $obj_rec["title"];
00224         }
00225         
00226         function _lookupType($a_obj_id)
00227         {
00228                 global $ilDB;
00229 
00230                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00231                 $obj_set = $ilDB->query($query);
00232                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00233 
00234                 return $obj_rec["type"];
00235         }
00236 
00237 
00238         function _writeTitle($a_obj_id, $a_title)
00239         {
00240                 global $ilDB;
00241 
00242                 $query = "UPDATE lm_data SET ".
00243                         " title = ".$ilDB->quote($a_title).
00244                         " WHERE obj_id = ".$ilDB->quote($a_obj_id);
00245                 $ilDB->query($query);
00246         }
00247 
00248 /*
00249         function _writeDescription($a_obj_id, $a_desc)
00250         {
00251                 global $ilDB;
00252 
00253                 $query = "UPDATE lm_data SET ".
00254                         " description = ".$ilDB->quote($a_desc).
00255                         " WHERE obj_id = ".$ilDB->quote($a_obj_id);
00256                 $ilDB->query($query);
00257         }
00258 */
00259 
00260         function setDescription($a_description)
00261         {
00262 //              $this->meta_data->setDescription($a_description);
00263                 $this->description = $a_description;
00264         }
00265 
00266         function getDescription()
00267         {
00268 //              return $this->description ? $this->description : $this->meta_data->getDescription();
00269                 return $this->description;
00270         }
00271 
00272         function setType($a_type)
00273         {
00274                 $this->type = $a_type;
00275         }
00276 
00277         function getType()
00278         {
00279                 return $this->type;
00280         }
00281 
00282         function setLMId($a_lm_id)
00283         {
00284                 $this->lm_id = $a_lm_id;
00285 
00286         }
00287 
00288         function getLMId()
00289         {
00290                 return $this->lm_id;
00291         }
00292 
00293         function setContentObject(&$a_content_obj)
00294         {
00295                 $this->content_object =& $a_content_obj;
00296         }
00297 
00298         function &getContentObject()
00299         {
00300                 return $this->content_object;
00301         }
00302 
00303         function setId($a_id)
00304         {
00305                 $this->id = $a_id;
00306         }
00307 
00308         function getId()
00309         {
00310                 return $this->id;
00311         }
00312 
00313         function getImportId()
00314         {
00315                 return $this->import_id;
00316         }
00317 
00318         function setImportId($a_id)
00319         {
00320                 $this->import_id = $a_id;
00321         }
00322 
00330         function _writeImportId($a_id, $a_import_id)
00331         {
00332                 global $ilDB;
00333 
00334                 $q = "UPDATE lm_data ".
00335                         "SET ".
00336                         "import_id = ".$ilDB->quote($a_import_id).",".
00337                         "last_update = now() ".
00338                         "WHERE obj_id = ".$ilDB->quote($a_id);
00339 
00340                 $ilDB->query($q);
00341         }
00342 
00343         function create($a_upload = false)
00344         {
00345                 // insert object data
00346                 $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date) ".
00347                         "VALUES ('".ilUtil::prepareDBString($this->getTitle())."','".$this->getType()."', ".$this->getLMId().",'".$this->getImportId().
00348                         "', now())";
00349                 $this->ilias->db->query($query);
00350                 $this->setId($this->ilias->db->getLastInsertId());
00351 
00352                 // create history entry
00353                 include_once("classes/class.ilHistory.php");
00354                 ilHistory::_createEntry($this->getId(), "create", "",
00355                         $this->content_object->getType().":pg");
00356 
00357                 if (!$a_upload)
00358                 {
00359                         $this->createMetaData();
00360                 }
00361 
00362         }
00363 
00367         function update()
00368         {
00369                 global $ilDB;
00370 
00371                 $this->updateMetaData();
00372 
00373                 $query = "UPDATE lm_data SET ".
00374                         " lm_id = ".$ilDB->quote($this->getLMId()).
00375                         " ,title = ".$ilDB->quote($this->getTitle()).
00376                         " WHERE obj_id = ".$ilDB->quote($this->getId());
00377 
00378                 $ilDB->query($query);
00379         }
00380 
00381 
00390         function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
00391         {
00392                 global $ilDB,$ilLog,$ilErr,$ilTree;
00393                 
00394                 if (!is_array($a_pages))
00395                 {$a_pages = array(0);
00396                         /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
00397                         $ilLog->write($message,$ilLog->WARNING);
00398                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00399                         return false;*/
00400                 }
00401                 
00402                 if (empty($a_cont_obj_id))
00403                 {
00404                         $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
00405                         $ilLog->write($message,$ilLog->WARNING);
00406                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00407                         return false;
00408                 }
00409                 
00410                 // update structure entries: if at least one page of a chapter is public set chapter to public too
00411                 $lm_tree = new ilTree($a_cont_obj_id);
00412                 $lm_tree->setTableNames('lm_tree','lm_data');
00413                 $lm_tree->setTreeTablePK("lm_id");
00414                 $lm_tree->readRootId();
00415                 
00416                 // get all st entries of cont_obj
00417                 $q = "SELECT obj_id FROM lm_data " . 
00418                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00419                          "AND type = 'st'";
00420                 $r = $ilDB->query($q);
00421                 
00422                 // add chapters with a public page to a_pages
00423                 while ($row = $r->fetchRow())
00424                 {
00425                         $childs = $lm_tree->getChilds($row[0]);
00426                         
00427                         foreach ($childs as $page)
00428                         {
00429                                 if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
00430                                 {
00431                                         array_push($a_pages, $row[0]);
00432                                         break;
00433                                 }
00434                         }
00435                 }
00436                 
00437                 // update public access status of all pages of cont_obj
00438                 $q = "UPDATE lm_data SET " .
00439                          "public_access = CASE " .
00440                          "WHEN obj_id IN (".implode(',',$a_pages).") " .
00441                          "THEN 'y' ".
00442                          "ELSE 'n' ".
00443                          "END " .
00444                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00445                          "AND type IN ('pg','st')";
00446                 $ilDB->query($q);
00447                 
00448                 return true;
00449         }
00450         
00451         function _isPagePublic($a_node_id,$a_check_public_mode = false)
00452         {
00453                 global $ilDB,$ilLog;
00454 
00455                 if (empty($a_node_id))
00456                 {
00457                         $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00458                         $ilLog->write($message,$ilLog->WARNING);
00459                         return false;
00460                 }
00461                 
00462                 if ($a_check_public_mode === true)
00463                 {
00464                         $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00465 
00466                         $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00467                         $r = $ilDB->query($q);
00468                         $row = $r->fetchRow();
00469                         
00470                         if ($row[0] == "complete")
00471                         {
00472                                 return true;
00473                         }
00474                 }
00475 
00476                 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00477                 $r = $ilDB->query($q);
00478                 $row = $r->fetchRow();
00479                 
00480                 return ilUtil::yn2tf($row[0]);
00481         }
00482 
00486         function delete($a_delete_meta_data = true)
00487         {
00488                 $query = "DELETE FROM lm_data WHERE obj_id= '".$this->getId()."'";
00489                 $this->ilias->db->query($query);
00490 
00491                 $this->deleteMetaData();
00492         }
00493 
00505         function _getIdForImportId($a_import_id)
00506         {
00507                 global $ilDB;
00508                 
00509                 $q = "SELECT * FROM lm_data WHERE import_id = '".$a_import_id."'".
00510                         " ORDER BY create_date DESC LIMIT 1";
00511                 $obj_set = $ilDB->query($q);
00512                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00513                 {
00514                         $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00515 
00516                         // link only in learning module, that is not trashed
00517                         if (ilObject::_hasUntrashedReference($lm_id))
00518                         {
00519                                 return $obj_rec["obj_id"];
00520                         }
00521                 }
00522 
00523                 return 0;
00524         }
00525         
00533         function _exists($a_id)
00534         {
00535                 global $ilDB;
00536                 
00537                 include_once("content/classes/Pages/class.ilInternalLink.php");
00538                 if (is_int(strpos($a_id, "_")))
00539                 {
00540                         $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00541                 }
00542                 
00543                 $q = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00544                 $obj_set = $ilDB->query($q);
00545                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00546                 {
00547                         return true;
00548                 }
00549                 else
00550                 {
00551                         return false;
00552                 }
00553 
00554         }
00555 
00559         function getObjectList($lm_id, $type = "")
00560         {
00561                 $type_str = ($type != "")
00562                         ? "AND type = '$type' "
00563                         : "";
00564                 $query = "SELECT * FROM lm_data ".
00565                         "WHERE lm_id= '".$lm_id."'".
00566                         $type_str." ".
00567                         "ORDER BY title";
00568                 $obj_set = $this->ilias->db->query($query);
00569                 $obj_list = array();
00570                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00571                 {
00572                         $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00573                                                                 "title" => $obj_rec["title"],
00574                                                                 "type" => $obj_rec["type"]);
00575                 }
00576                 return $obj_list;
00577         }
00578 
00579 
00583         function _deleteAllObjectData(&$a_cobj)
00584         {
00585                 include_once './classes/class.ilNestedSetXML.php';
00586 
00587                 $query = "SELECT * FROM lm_data ".
00588                         "WHERE lm_id= '".$a_cobj->getId()."'";
00589                 $obj_set = $this->ilias->db->query($query);
00590 
00591                 require_once("content/classes/class.ilLMObjectFactory.php");
00592                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00593                 {
00594                         $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
00595 
00596                         if (is_object($lm_obj))
00597                         {
00598                                 $lm_obj->delete(true);
00599                         }
00600                 }
00601 
00602                 return true;
00603         }
00604 
00608         function _lookupContObjID($a_id)
00609         {
00610                 global $ilDB;
00611 
00612                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00613                 $obj_set = $ilDB->query($query);
00614                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00615 
00616                 return $obj_rec["lm_id"];
00617         }
00618 
00619 }
00620 ?>

Generated on Fri Dec 13 2013 10:18:29 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1