• 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,$ilTree;
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 structure entries: if at least one page of a chapter is public set chapter to public too
00301                 $lm_tree = new ilTree($a_cont_obj_id);
00302                 $lm_tree->setTableNames('lm_tree','lm_data');
00303                 $lm_tree->setTreeTablePK("lm_id");
00304                 $lm_tree->readRootId();
00305                 
00306                 // get all st entries of cont_obj
00307                 $q = "SELECT obj_id FROM lm_data " . 
00308                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00309                          "AND type = 'st'";
00310                 $r = $ilDB->query($q);
00311                 
00312                 // add chapters with a public page to a_pages
00313                 while ($row = $r->fetchRow())
00314                 {
00315                         $childs = $lm_tree->getChilds($row[0]);
00316                         
00317                         foreach ($childs as $page)
00318                         {
00319                                 if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
00320                                 {
00321                                         array_push($a_pages, $row[0]);
00322                                         break;
00323                                 }
00324                         }
00325                 }
00326                 
00327                 // update public access status of all pages of cont_obj
00328                 $q = "UPDATE lm_data SET " .
00329                          "public_access = CASE " .
00330                          "WHEN obj_id IN (".implode(',',$a_pages).") " .
00331                          "THEN 'y' ".
00332                          "ELSE 'n' ".
00333                          "END " .
00334                          "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
00335                          "AND type IN ('pg','st')";
00336                 $ilDB->query($q);
00337                 
00338                 return true;
00339         }
00340         
00341         function _isPagePublic($a_node_id,$a_check_public_mode = false)
00342         {
00343                 global $ilDB,$ilLog;
00344 
00345                 if (empty($a_node_id))
00346                 {
00347                         $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
00348                         $ilLog->write($message,$ilLog->WARNING);
00349                         return false;
00350                 }
00351                 
00352                 if ($a_check_public_mode === true)
00353                 {
00354                         $lm_id = ilLMObject::_lookupContObjId($a_node_id);
00355 
00356                         $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
00357                         $r = $ilDB->query($q);
00358                         $row = $r->fetchRow();
00359                         
00360                         if ($row[0] == "complete")
00361                         {
00362                                 return true;
00363                         }
00364                 }
00365 
00366                 $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
00367                 $r = $ilDB->query($q);
00368                 $row = $r->fetchRow();
00369                 
00370                 return ilUtil::yn2tf($row[0]);
00371         }
00372 
00376         function delete($a_delete_meta_data = true)
00377         {
00378                 if ($a_delete_meta_data)
00379                 {
00380                         /* Delete meta data in nested set table for given object and type */
00381                         $nested = new ilNestedSetXML();
00382                         $nested->init($this->getId(), $this->getType());
00383                         $nested->deleteAllDBData();
00384                 }
00385                 $query = "DELETE FROM lm_data WHERE obj_id= '".$this->getId()."'";
00386                 $this->ilias->db->query($query);
00387         }
00388 
00400         function _getIdForImportId($a_import_id)
00401         {
00402                 global $ilDB;
00403                 
00404                 $q = "SELECT * FROM lm_data WHERE import_id = '".$a_import_id."'".
00405                         " ORDER BY create_date DESC LIMIT 1";
00406                 $obj_set = $ilDB->query($q);
00407                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00408                 {
00409                         $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
00410 
00411                         // link only in learning module, that is not trashed
00412                         if (ilObject::_hasUntrashedReference($lm_id))
00413                         {
00414                                 return $obj_rec["obj_id"];
00415                         }
00416                 }
00417 
00418                 return 0;
00419         }
00420         
00428         function _exists($a_id)
00429         {
00430                 global $ilDB;
00431                 
00432                 include_once("content/classes/Pages/class.ilInternalLink.php");
00433                 if (is_int(strpos($a_id, "_")))
00434                 {
00435                         $a_id = ilInternalLink::_extractObjIdOfTarget($a_id);
00436                 }
00437                 
00438                 $q = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00439                 $obj_set = $ilDB->query($q);
00440                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00441                 {
00442                         return true;
00443                 }
00444                 else
00445                 {
00446                         return false;
00447                 }
00448 
00449         }
00450 
00454         function getObjectList($lm_id, $type = "")
00455         {
00456                 $type_str = ($type != "")
00457                         ? "AND type = '$type' "
00458                         : "";
00459                 $query = "SELECT * FROM lm_data ".
00460                         "WHERE lm_id= '".$lm_id."'".
00461                         $type_str." ".
00462                         "ORDER BY title";
00463                 $obj_set = $this->ilias->db->query($query);
00464                 $obj_list = array();
00465                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00466                 {
00467                         $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
00468                                                                 "title" => $obj_rec["title"],
00469                                                                 "type" => $obj_rec["type"]);
00470                 }
00471                 return $obj_list;
00472         }
00473 
00474 
00478         function _deleteAllObjectData(&$a_cobj)
00479         {
00480                 include_once './classes/class.ilNestedSetXML.php';
00481 
00482                 $page_ids = ilNestedSetXML::_getAllChildIds($a_cobj->getId());
00483 
00484                 $query = "SELECT * FROM lm_data ".
00485                         "WHERE lm_id= '".$a_cobj->getId()."'";
00486                 $obj_set = $this->ilias->db->query($query);
00487 
00488                 require_once("content/classes/class.ilLMObjectFactory.php");
00489                 while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00490                 {
00491                         $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
00492 
00493                         if (is_object($lm_obj))
00494                         {
00495                                 $lm_obj->delete(false);
00496                         }
00497                 }
00498                 ilNestedSetXML::_deleteAllChildMetaData($page_ids);
00499 
00500                 return true;
00501         }
00502 
00506         function _lookupContObjID($a_id)
00507         {
00508                 global $ilDB;
00509 
00510                 $query = "SELECT * FROM lm_data WHERE obj_id = '".$a_id."'";
00511                 $obj_set = $ilDB->query($query);
00512                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00513 
00514                 return $obj_rec["lm_id"];
00515         }
00516 
00517 }
00518 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1