• 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 
00068         function setDataRecord($a_record)
00069         {
00070                 $this->data_record = $a_record;
00071         }
00072 
00073         function read()
00074         {
00075                 global $ilBench;
00076 
00077                 $ilBench->start("ContentPresentation", "ilLMObject_read");
00078 
00079                 if(!isset($this->data_record))
00080                 {
00081                         $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
00082                         $query = "SELECT * FROM lm_data WHERE obj_id = '".$this->id."'";
00083                         $obj_set = $this->ilias->db->query($query);
00084                         $this->data_record = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00085                         $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
00086                 }
00087 
00088                 $this->type = $this->data_record["type"];
00089                 $ilBench->start("ContentPresentation", "ilLMObject_read_getMeta");
00090                 $this->meta_data =& new ilMetaData($this->type, $this->id);
00091                 $ilBench->stop("ContentPresentation", "ilLMObject_read_getMeta");
00092                 $this->setImportId($this->data_record["import_id"]);
00093                 $this->setTitle($this->data_record["title"]);
00094 
00095                 $ilBench->stop("ContentPresentation", "ilLMObject_read");
00096         }
00097 
00101         function setTitle($a_title)
00102         {
00103                 $this->meta_data->setTitle($a_title);
00104                 $this->title = $a_title;
00105         }
00106 
00107         function getTitle()
00108         {
00109                 return $this->title ? $this->title : $this->meta_data->getTitle();
00110         }
00111 
00112 
00113         function _lookupTitle($a_obj_id)
00114         {
00115                 global $ilDB;
00116 
00117                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_obj_id."'";
00118                 $obj_set = $ilDB->query($query);
00119                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00120 
00121                 return $obj_rec["title"];
00122         }
00123 
00124         function setDescription($a_description)
00125         {
00126                 $this->meta_data->setDescription($a_description);
00127                 $this->description = $a_description;
00128         }
00129 
00130         function getDescription()
00131         {
00132                 return $this->description ? $this->description : $this->meta_data->getDescription();
00133         }
00134 
00135         function setType($a_type)
00136         {
00137                 $this->type = $a_type;
00138         }
00139 
00140         function getType()
00141         {
00142                 return $this->type;
00143         }
00144 
00145         function setLMId($a_lm_id)
00146         {
00147                 $this->lm_id = $a_lm_id;
00148 
00149         }
00150 
00151         function getLMId()
00152         {
00153                 return $this->lm_id;
00154         }
00155 
00156         function setContentObject(&$a_content_obj)
00157         {
00158                 $this->content_object =& $a_content_obj;
00159         }
00160 
00161         function &getContentObject()
00162         {
00163                 return $this->content_object;
00164         }
00165 
00166         function setId($a_id)
00167         {
00168                 $this->id = $a_id;
00169         }
00170 
00171         function getId()
00172         {
00173                 return $this->id;
00174         }
00175 
00176         function getImportId()
00177         {
00178                 return $this->meta_data->getImportIdentifierEntryID();
00179         }
00180 
00181         function setImportId($a_id)
00182         {
00183                 $this->meta_data->setImportIdentifierEntryID($a_id);
00184         }
00185 
00186 
00187         function create($a_upload = false)
00188         {
00189                 // insert object data
00190                 $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date) ".
00191                         "VALUES ('".ilUtil::prepareDBString($this->getTitle())."','".$this->getType()."', ".$this->getLMId().",'".$this->getImportId().
00192                         "', now())";
00193                 $this->ilias->db->query($query);
00194                 $this->setId($this->ilias->db->getLastInsertId());
00195                 
00196                 // create history entry
00197                 include_once("classes/class.ilHistory.php");
00198                 ilHistory::_createEntry($this->getId(), "create", "",
00199                         $this->content_object->getType().":pg");
00200 
00201                 if (!$a_upload)
00202                 {
00203                         // create meta data
00204                         $this->meta_data->setId($this->getId());
00205                         $this->meta_data->setType($this->getType());
00206                         $this->meta_data->setTitle($this->getTitle());
00207                         $this->meta_data->setDescription($this->getDescription());
00208                         $this->meta_data->setObject($this);
00209                         $this->meta_data->create();
00210                 }
00211         }
00212 
00213 
00214         function assignMetaData(&$a_meta_data)
00215         {
00216                 $this->meta_data =& $a_meta_data;
00217         }
00218 
00219         function &getMetaData()
00220         {
00221                 return $this->meta_data;
00222         }
00223 
00224 
00228         function updateMetaData()
00229         {
00230                 global $ilDB;
00231 
00232 //$f = fopen("/opt/iliasdata/bb.txt", "a"); fwrite($f, "LMObject::updateMetaData(), start\n"); fclose($f);
00233 
00234                 //$this->meta_data->update();
00235                 if ($this->meta_data->section != "General")
00236                 {
00237                         $meta = $this->meta_data->getElement("Title", "General");
00238                         $this->title = $meta[0]["Value"];
00239                         $meta = $this->meta_data->getElement("Description", "General");
00240                         $this->description = $meta[0]["Value"];
00241                 }
00242                 else
00243                 {
00244                         $this->setTitle($this->meta_data->getTitle());
00245                         $this->setDescription($this->meta_data->getDescription());
00246                 }
00247                 $query = "UPDATE lm_data SET ".
00248                         " title = ".$ilDB->quote($this->getTitle()).
00249                         ", last_update = now() WHERE obj_id = ".$ilDB->quote($this->getId());
00250 
00251                 $this->ilias->db->query($query);
00252                 $this->meta_data->update();
00253 //$f = fopen("/opt/iliasdata/bb.txt", "a"); fwrite($f, "LMObject::updateMetaData(), end\n"); fclose($f);
00254         }
00255 
00259         function update()
00260         {
00261                 global $ilDB;
00262 
00263                 $query = "UPDATE lm_data SET ".
00264                         " lm_id = ".$ilDB->quote($this->getLMId()).
00265                         " WHERE obj_id = ".$ilDB->quote($this->getId());
00266                 $ilDB->query($query);
00267 
00268                 $this->updateMetaData();
00269 
00270         }
00271         
00280         function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
00281         {
00282                 global $ilDB,$ilLog,$ilErr;
00283                 
00284                 if (!is_array($a_pages))
00285                 {$a_pages = array(0);
00286                         /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
00287                         $ilLog->write($message,$ilLog->WARNING);
00288                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00289                         return false;*/
00290                 }
00291                 
00292                 if (empty($a_cont_obj_id))
00293                 {
00294                         $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
00295                         $ilLog->write($message,$ilLog->WARNING);
00296                         $ilErr->raiseError($message,$ilErr->MESSAGE);
00297                         return false;
00298                 }
00299                 
00300                 // update public access status of all pages of cont_obj
00301                 $q = "UPDATE lm_data SET " .
00302                          "public_access = CASE " .
00303                          "WHEN obj_id IN (".implode(',',$a_pages).") " .
00304                          "THEN 'y' ".
00305                          "ELSE 'n' ".
00306                          "END " .
00307                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00308                          "AND type = 'pg'";
00309                 $ilDB->query($q);
00310 
00311                 return true;
00312         }
00313         
00314         function _isPagePublic($a_node_id,$a_check_public_mode = false)
00315         {
00316                 global $ilDB,$ilLog;
00317 
00318                 if (empty($a_node_id))
00319                 {
00320                         $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00321                         $ilLog->write($message,$ilLog->WARNING);
00322                         return false;
00323                 }
00324                 
00325                 if ($a_check_public_mode === true)
00326                 {
00327                         $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00328 
00329                         $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00330                         $r = $ilDB->query($q);
00331                         $row = $r->fetchRow();
00332                         
00333                         if ($row[0] == "complete")
00334                         {
00335                                 return true;
00336                         }
00337                 }
00338 
00339                 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00340                 $r = $ilDB->query($q);
00341                 $row = $r->fetchRow();
00342                 
00343                 return ilUtil::yn2tf($row[0]);
00344         }
00345 
00349         function delete($a_delete_meta_data = true)
00350         {
00351                 if ($a_delete_meta_data)
00352                 {
00353                         /* Delete meta data in nested set table for given object and type */
00354                         $nested = new ilNestedSetXML();
00355                         $nested->init($this->getId(), $this->getType());
00356                         $nested->deleteAllDBData();
00357                 }
00358 
00359                 $query = "DELETE FROM lm_data WHERE obj_id= '".$this->getId()."'";
00360                 $this->ilias->db->query($query);
00361         }
00362 
00374         function _getIdForImportId($a_import_id)
00375         {
00376                 global $ilDB;
00377                 
00378                 $q = "SELECT * FROM lm_data WHERE import_id = '".$a_import_id."'".
00379                         " ORDER BY create_date DESC LIMIT 1";
00380                 $obj_set = $ilDB->query($q);
00381                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00382                 {
00383                         $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00384 
00385                         // link only in learning module, that is not trashed
00386                         if (ilObject::_hasUntrashedReference($lm_id))
00387                         {
00388                                 return $obj_rec["obj_id"];
00389                         }
00390                 }
00391 
00392                 return 0;
00393         }
00394         
00402         function _exists($a_id)
00403         {
00404                 global $ilDB;
00405                 
00406                 include_once("content/classes/Pages/class.ilInternalLink.php");
00407                 if (is_int(strpos($a_id, "_")))
00408                 {
00409                         $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00410                 }
00411                 
00412                 $q = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00413                 $obj_set = $ilDB->query($q);
00414                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00415                 {
00416                         return true;
00417                 }
00418                 else
00419                 {
00420                         return false;
00421                 }
00422 
00423         }
00424 
00428         function getObjectList($lm_id, $type = "")
00429         {
00430                 $type_str = ($type != "")
00431                         ? "AND type = '$type' "
00432                         : "";
00433                 $query = "SELECT * FROM lm_data ".
00434                         "WHERE lm_id= '".$lm_id."'".
00435                         $type_str." ".
00436                         "ORDER BY title";
00437                 $obj_set = $this->ilias->db->query($query);
00438                 $obj_list = array();
00439                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00440                 {
00441                         $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00442                                                                 "title" => $obj_rec["title"],
00443                                                                 "type" => $obj_rec["type"]);
00444                 }
00445                 return $obj_list;
00446         }
00447 
00448 
00452         function _deleteAllObjectData(&$a_cobj)
00453         {
00454                 include_once './classes/class.ilNestedSetXML.php';
00455 
00456                 $page_ids = ilNestedSetXML::_getAllChildIds($a_cobj->getId());
00457 
00458                 $query = "SELECT * FROM lm_data ".
00459                         "WHERE lm_id= '".$a_cobj->getId()."'";
00460                 $obj_set = $this->ilias->db->query($query);
00461 
00462                 require_once("content/classes/class.ilLMObjectFactory.php");
00463                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00464                 {
00465                         $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"]);
00466                         if (is_object($lm_obj))
00467                         {
00468                                 $lm_obj->delete(false);
00469                         }
00470                 }
00471                 ilNestedSetXML::_deleteAllChildMetaData($page_ids);
00472 
00473                 return true;
00474         }
00475 
00479         function _lookupContObjID($a_id)
00480         {
00481                 global $ilDB;
00482 
00483                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00484                 $obj_set = $ilDB->query($query);
00485                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00486 
00487                 return $obj_rec["lm_id"];
00488         }
00489 
00490 }
00491 ?>

Generated on Fri Dec 13 2013 08:00:16 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1