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

Modules/LearningModule/classes/class.ilObjDlBook.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("./Modules/LearningModule/classes/class.ilObjContentObject.php");
00025 
00034 class ilObjDlBook extends ilObjContentObject
00035 {
00036         var $bib_obj;
00037 
00042         function ilObjDlBook($a_id = 0,$a_call_by_reference = true)
00043         {
00044                 $this->type = "dbk";
00045                 parent::ilObjContentObject($a_id, $a_call_by_reference);
00046 
00047                 if($a_id)
00048                 {
00049                         $this->readAssignedTranslations();
00050                 }
00051         }
00052 
00053         
00057         function initBibItemObject()
00058         {
00059                 include_once("./Modules/LearningModule/classes/class.ilBibItem.php");
00060 
00061                 $this->bib_obj =& new ilBibItem($this);
00062                 $this->bib_obj->read();
00063 
00064                 return true;
00065         }
00066 
00077     function exportRekursiv($obj_id, $depth, $left, $right)
00078         {
00079                 global $ilDB;
00080                 
00081                 // Jetzt alle lm_data anhand der obj_id auslesen.
00082                 $query = "SELECT  *
00083                   FROM lm_tree, lm_data
00084                   WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id)." 
00085                   AND   lm_tree.child = lm_data.obj_id 
00086                   AND   ( lm_data.type =  'st' OR lm_data.type =  'pg' )
00087                   AND lm_tree.depth = ".$ilDB->quote($depth)."
00088                   AND lm_tree.lft > ".$ilDB->quote($left)." and lm_tree.rgt < ".$ilDB->quote($right)."
00089                   ORDER BY lm_tree.lft";
00090         $result = $this->ilias->db->query($query);
00091         while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) ) 
00092                 {
00093                         if ($row["type"] == "st") 
00094                         {
00095                                 $xml .= "<StructureObject>";
00096                 
00097                                 $nested = new ilNestedSetXML();
00098                                 $xml .= $nested->export($row["obj_id"],"st");
00099                                 $xml .= "\n";
00100 
00101                 $xml .= $this->exportRekursiv($obj_id, $depth+1, $row["lft"], $row["rgt"]);
00102                 
00103                                 $xml .= "</StructureObject>";
00104                         }            
00105 
00106             if ($row["type"] == "pg") 
00107             {
00108                 
00109                 $query = "SELECT * FROM page_object WHERE page_id= ".$ilDB->quote($row["obj_id"]);
00110                                 $result2 = $this->ilias->db->query($query);
00111                 
00112                                 $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC);
00113                                 
00114                                 $PO = $row2["content"]."\n";
00115 
00116                                 if (stristr($PO,"MediaObject")) 
00117                 {
00118 
00119                     $dom = domxml_open_mem($PO);
00120                     $xpc = xpath_new_context($dom);
00121                     $path = "//MediaObject/MediaAlias";
00122                     $res =& xpath_eval($xpc, $path);
00123                     for($i = 0; $i < count($res->nodeset); $i++)
00124                     {
00125                         $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00126                         $mob_id = $id_arr[count($id_arr) - 1];
00127                         $this->mob_ids[$mob_id] = true;
00128                     }
00129                 }
00130                 
00131                                 $nested = new ilNestedSetXML();
00132                                 $mdxml = $nested->export($row["obj_id"],"pg");
00133 
00134                                 $PO = str_replace("<PageObject>","<PageObject>\n$mdxml\n",$PO);
00135                                 
00136                                 $xml .= $PO;                
00137                 
00138             }
00139             
00140         }
00141 
00142         return($xml);
00143     }
00144 
00148         function export($a_deliver = true)
00149         {
00150                 global $ilDB;
00151                 
00152                 include_once("./classes/class.ilNestedSetXML.php");
00153                 // ------------------------------------------------------
00154                 // anhand der ref_id die obj_id ermitteln.
00155                 // ------------------------------------------------------
00156                 $query = "SELECT * FROM object_reference,object_data WHERE object_reference.ref_id= ".
00157                         $ilDB->quote($this->getRefId())." AND object_reference.obj_id=object_data.obj_id ";
00158         $result = $this->ilias->db->query($query);
00159 
00160                 $objRow = $result->fetchRow(DB_FETCHMODE_ASSOC);
00161 
00162                 $obj_id = $objRow["obj_id"];
00163 
00164         $this->mob_ids = array();
00165 
00166                 // ------------------------------------------------------
00167         // start xml-String
00168                 // ------------------------------------------------------
00169                 $xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE ContentObject SYSTEM \"ilias_co.dtd\">\n<ContentObject Type=\"LibObject\">\n";
00170 
00171                 // ------------------------------------------------------
00172         // get global meta-data
00173                 // ------------------------------------------------------
00174                 $nested = new ilNestedSetXML();
00175                 $xml .= $nested->export($obj_id,"dbk")."\n";
00176 
00177                 // ------------------------------------------------------
00178         // get all book-xml-data recursiv
00179                 // ------------------------------------------------------
00180 
00181                 $query = "SELECT  *
00182                   FROM lm_tree, lm_data
00183                   WHERE lm_tree.lm_id = ".$ilDB->quote($obj_id)."
00184                   AND   lm_tree.child = lm_data.obj_id
00185                   AND   ( lm_data.type =  'du' )
00186                   AND lm_tree.depth = 1
00187                   ORDER BY lm_tree.lft";
00188         $result = $this->ilias->db->query($query);
00189         $treeData = $result->fetchRow(DB_FETCHMODE_ASSOC);
00190 
00191         $xml .= $this->exportRekursiv($obj_id,2, $treeData["lft"], $treeData["rgt"]);
00192 
00193                 // ------------------------------------------------------
00194         // get or create export-directory
00195                 // ------------------------------------------------------
00196                 $this->createExportDirectory();
00197                 $export_dir = $this->getExportDirectory();
00198 
00199                 // ------------------------------------------------------
00200         // get mediaobject-xml-data
00201                 // ------------------------------------------------------
00202         $mob_ids = $this->mob_ids;
00203         if (is_array($mob_ids) && count($mob_ids)>0) 
00204         {
00205             reset ($mob_ids);
00206             while (list ($key, $val) = each ($mob_ids)) 
00207             {
00208 
00209                 $xml .= "<MediaObject>";
00210 
00211                 $query = "SELECT * FROM media_item WHERE mob_id= ".$ilDB->quote($key)." ";
00212                 //vd($query);
00213                 $first = true;
00214                 $result = $this->ilias->db->query($query);
00215                 while (is_array($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) )
00216                 {
00217                     if($first) 
00218                     {
00219                         //vd($row[purpose]);
00220                         $nested = new ilNestedSetXML();
00221                         $metaxml = $nested->export($key,"mob");
00222                         $metaxml = preg_replace("/Entry=\"(.*?)\"/","Entry=\"il__mob_".$key."\"",$metaxml);
00223 
00224                         $metaxml2 = "<Technical>";
00225                         $metaxml2 .= "<Format>".$row["format"]."</Format>";
00226                         $metaxml2 .= "<Size>14559</Size>";
00227                         $metaxml2 .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
00228                         $metaxml2 .= "</Technical>";
00229 
00230                         $metaxml = str_replace("</MetaData>",$metaxml2."</MetaData>",$metaxml);
00231 
00232                         $xml .= $metaxml;
00233 
00234                         $first = false;
00235                     }
00236 
00237                     $xml .= "<MediaItem Purpose=\"".$row["purpose"]."\">";
00238                     $xml .= "<Location Type=\"".$row["location_type"]."\">".$row["location"]."</Location>";
00239                     $xml .= "<Format>".$row["format"]."</Format>";
00240                     $xml .= "<Layout Width=\"".$row["width"]."\" Height=\"".$row["height"]."\"/>";
00241                     $xml .= "</MediaItem>";
00242 
00243                 }
00244                 $xml .= "</MediaObject>";
00245             }
00246         }
00247 
00248 
00249                 // ------------------------------------------------------
00250         // get bib-xml-data
00251                 // ------------------------------------------------------
00252                 $nested = new ilNestedSetXML();
00253                 $bib = $nested->export($obj_id,"bib");
00254 
00255                 $xml .= $bib."\n";
00256 
00257                 // ------------------------------------------------------
00258         // xml-ending
00259                 // ------------------------------------------------------
00260                 $xml .= "</ContentObject>";
00261 
00262                 // ------------------------------------------------------
00263         // filename and directory-creation
00264                 // ------------------------------------------------------
00265                 $fileName = $objRow["title"];
00266                 $fileName = str_replace(" ","_",$fileName);
00267 
00268                 if (!file_exists($export_dir."/".$fileName))
00269                 {
00270                         @mkdir($export_dir."/".$fileName);
00271                         @chmod($export_dir."/".$fileName,0755);
00272                 }
00273         
00274                 if (!file_exists($export_dir."/".$fileName."/objects"))
00275                 {
00276                         @mkdir($export_dir."/".$fileName."/objects");
00277                         @chmod($export_dir."/".$fileName."/objects",0755);
00278                 }
00279 
00280                 // ------------------------------------------------------
00281         // copy mob-files
00282                 // ------------------------------------------------------
00283         $mob_ids = $this->mob_ids;
00284         if (is_array($mob_ids) && count($mob_ids)>0) 
00285         {
00286             reset ($mob_ids);
00287             while (list ($key, $val) = each ($mob_ids)) 
00288             {
00289 
00290                 if (!file_exists($export_dir."/".$fileName."/objects/mm".$key))
00291                 {
00292                     @mkdir($export_dir."/".$fileName."/objects/mm".$key);
00293                     @chmod($export_dir."/".$fileName."/objects/mm".$key,0755);
00294                 }
00295 
00296                 $mobdir = "./data/mobs/mm_".$key;
00297                 ilUtil::rCopy($mobdir, $export_dir."/".$fileName."/objects/mm".$key);
00298             }
00299         }
00300 
00301                 // ------------------------------------------------------
00302         // save xml-file
00303                 // ------------------------------------------------------
00304                 $fp = fopen($export_dir."/".$fileName."/".$fileName.".xml","wb");
00305                 fwrite($fp,$xml);
00306                 fclose($fp);
00307 
00308                 // ------------------------------------------------------
00309         // zip all files
00310                 // ------------------------------------------------------
00311                 ilUtil::zip($export_dir."/".$fileName, $export_dir."/".$fileName.".zip");
00312 
00313                 // ------------------------------------------------------
00314         // deliver files
00315                 // ------------------------------------------------------
00316 
00317                 if($a_deliver)
00318                 {
00319                         ilUtil::deliverFile($export_dir."/".$fileName.".zip",$fileName);
00320                 }
00321                 else
00322                 {
00323                         return $export_dir."/".$fileName.".zip";
00324                 }
00325                 /*
00326                 header("Expires: Mon, 1 Jan 1990 00:00:00 GMT");
00327                 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00328                 header("Cache-Control: no-store, no-cache, must-revalidate");
00329                 header("Cache-Control: post-check=0, pre-check=0", false);
00330                 header("Pragma: no-cache");
00331                 header("Content-type: application/octet-stream");
00332                 if (stristr(" ".$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"],"MSIE") )
00333                 {
00334                         header ("Content-Disposition: attachment; filename=" . $fileName.".zip");
00335                 }
00336                 else
00337                 {
00338                         header ("Content-Disposition: inline; filename=".$fileName.".zip" );
00339                 }
00340                 header ("Content-length:".(string)( filesize($export_dir."/".$fileName.".zip")) );
00341 
00342                 readfile( $export_dir."/".$fileName.".zip" );
00343                 */
00344 
00345         }
00346 
00347 
00348         function addTranslation($a_ref_id)
00349         {
00350                 global $ilDB;
00351                 
00352                 $query = "REPLACE INTO dbk_translations ".
00353                         "SET id = ".$ilDB->quote($this->ref_id).", ".
00354                         "tr_id = ".$ilDB->quote($a_ref_id)." ";
00355                 $res = $this->ilias->db->query($query);
00356 
00357                 $query = "REPLACE INTO dbk_translations ".
00358                         "SET id = ".$ilDB->quote($a_ref_id).", ".
00359                         "tr_id = ".$ilDB->quote($this->ref_id)." ";
00360                 $res = $this->ilias->db->query($query);
00361 
00362                 // UPDATE MEMBER VARIABLE
00363                 $this->readAssignedTranslations();
00364 
00365                 return true;
00366         }
00367 
00368         function addTranslations($a_arr_ref_id)
00369         {
00370                 if(!is_array($a_arr_ref_id))
00371                 {
00372                         return false;
00373                 }
00374                 foreach($a_arr_ref_id as $ref_id)
00375                 {
00376                         $this->addTranslation($ref_id);
00377                 }
00378                 return true;
00379         }
00380         function deleteTranslation($a_ref_id)
00381         {
00382                 global $ilDB;
00383                 
00384                 if(!$a_ref_id)
00385                 {
00386                         return false;
00387                 }
00388 
00389                 $query = "DELETE FROM dbk_translations ".
00390                         "WHERE id = ".$ilDB->quote($this->ref_id)." ".
00391                         "AND tr_id = ".$ilDB->quote($a_ref_id)." ";
00392 
00393                 $res = $this->ilias->db->query($query);
00394 
00395                 $query = "DELETE FROM dbk_translations ".
00396                         "WHERE id = ".$ilDB->quote($a_ref_id)." ".
00397                         "AND tr_id = ".$ilDB->quote($this->ref_id)." ";
00398 
00399                 $res = $this->ilias->db->query($query);
00400 
00401                 // UPDATE MEMBER VARIABLE
00402                 $this->readAssignedTranslations();
00403 
00404                 return true;
00405         }
00406 
00407         function deleteTranslations($a_arr_ref_id)
00408         {
00409                 if(!is_array($a_arr_ref_id))
00410                 {
00411                         return false;
00412                 }
00413                 foreach($a_arr_ref_id as $ref_id)
00414                 {
00415                         $this->deleteTranslation($ref_id);
00416                 }
00417                 return true;
00418         }
00419         function getTranslations()
00420         {
00421                 return $this->tr_ids;
00422         }
00430         function _search(&$search_obj,$a_search_in)
00431         {
00432                 global $ilBench;
00433 
00434                 switch($a_search_in)
00435                 {
00436                         case 'meta':
00437                                 // FILTER ALL DBK OBJECTS
00438                                 $in             = $search_obj->getInStatement("r.ref_id");
00439                                 $where  = $search_obj->getWhereCondition("fulltext",array("xv.tag_value"));
00440 
00441                                 /* very slow on mysql < 4.0.18
00442                                 $query = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
00443                                         "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
00444                                         $where.
00445                                         $in.
00446                                         "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) OR ".
00447                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('dbk','bib'))) ".
00448                                         "AND xm.ns_tag_fk=xv.tag_fk ".
00449                                         "AND o.type= 'dbk'"; */
00450 
00451                                 $query1 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
00452                                         "xmlnestedset AS xm,xmlvalue AS xv ".
00453                                         $where.
00454                                         $in.
00455                                         "AND r.obj_id=o.obj_id AND ( ".
00456                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('dbk','bib'))) ".
00457                                         "AND xm.ns_tag_fk=xv.tag_fk ".
00458                                         "AND o.type= 'dbk'";
00459 
00460                                 // BEGINNING SELECT WITH SEARCH RESULTS IS MUCH FASTER
00461                                 $query1 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
00462                                         "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk=xv.tag_fk ".
00463                                         "LEFT JOIN object_data AS o ON o.obj_id = xm.ns_book_fk ".
00464                                         "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
00465                                         $where.
00466                                         $in.
00467                                         " AND o.type = 'dbk' AND xm.ns_type IN ('dbk','bib')";
00468 
00469                                 $query2 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
00470                                         "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
00471                                         $where.
00472                                         $in.
00473                                         "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) ".
00474                                         ") ".
00475                                         "AND xm.ns_tag_fk=xv.tag_fk ".
00476                                         "AND o.type= 'dbk'";
00477 
00478                                 $query2 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
00479                                         " LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk = xv.tag_fk ".
00480                                         " LEFT JOIN lm_data AS l ON l.obj_id = xm.ns_book_fk ".
00481                                         " LEFT JOIN object_data AS o ON o.obj_id = l.lm_id ".
00482                                         " LEFT JOIN object_reference AS r ON r.obj_id = o.obj_id ".
00483                                         $where.
00484                                         $in.
00485                                         "AND o.type = 'dbk'";
00486                                         
00487 
00488                                 /*
00489                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id FROM object_reference AS r ".
00490                                         "INNER JOIN object_data AS o ON r.obj_id=o.obj_id ".
00491                                         "INNER JOIN lm_data AS l ON l.lm_id = o.obj_id ".
00492                                         "INNER JOIN xmlnestedset AS xm ON (xm.ns_book_fk = l.obj_id OR xm.ns_type IN ('dbk','bib')) ".
00493                                         "INNER JOIN xmlvalue AS xv ON xm.ns_tag_fk = xv.tag_fk ".
00494                                         $where.
00495                                         $in.
00496                                         "AND o.type = 'dbk'";
00497                                 */
00498 
00499                                 $ilBench->start("Search", "ilObjDlBook_search_meta");
00500                                 $res1 = $search_obj->ilias->db->query($query1);
00501                                 $res2 = $search_obj->ilias->db->query($query2);
00502                                 $ilBench->stop("Search", "ilObjDlBook_search_meta");
00503 
00504                                 $counter = 0;
00505                                 $ids = array();
00506                                 while($row = $res1->fetchRow(DB_FETCHMODE_OBJECT))
00507                                 {
00508                                         $ids[] = $row->ref_id;
00509                                         $result[$counter]["id"]         =  $row->ref_id;
00510 
00511                                         ++$counter;
00512                                 }
00513                                 while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
00514                                 {
00515                                         if(in_array($row->ref_id,$ids))
00516                                         {
00517                                                 continue;
00518                                         }
00519                                         $result[$counter]["id"]         =  $row->ref_id;
00520 
00521                                         ++$counter;
00522                                 }
00523                                 break;
00524 
00525                         case 'content':
00526                                 $in             = $search_obj->getInStatement("ref_id");
00527                                 $where  = $search_obj->getWhereCondition("fulltext",array("pg.content"));
00528 
00529                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
00530                                         "INNER JOIN object_reference AS r ON pg.parent_id = r.obj_id ".
00531                                         $where.
00532                                         $in.
00533                                         "AND pg.parent_type = 'dbk' ";
00534 
00535                                 $ilBench->start("Search", "ilObjDlBook_search_content");
00536                                 $res = $search_obj->ilias->db->query($query);
00537                                 $ilBench->stop("Search", "ilObjDlBook_search_content");
00538 
00539                                 $counter = 0;
00540                                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00541                                 {
00542                                         $result[$counter]["id"]         = $row->ref_id;
00543                                         $result[$counter]["page_id"] = $row->page_id;
00544 
00545                                         ++$counter;
00546                                 }
00547                                 break;
00548                 }
00549                 return $result ? $result : array();
00550         }
00551 
00552         function getXMLZip()
00553         {
00554                 return $this->export(false);
00555         }
00556 
00557 
00558         // PRIVATE METHODS
00559         function readAssignedTranslations()
00560         {
00561                 global $ilDB;
00562                 
00563                 $query = "SELECT tr_id FROM dbk_translations ".
00564                         "WHERE id = ".$ilDB->quote($this->ref_id)." ";
00565 
00566                 $res = $this->ilias->db->query($query);
00567                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00568                 {
00569                         $tmp_tr_ids[] = $row->tr_id;
00570                 }
00571                 return $this->tr_ids = $tmp_tr_ids ? $tmp_tr_ids : array();
00572         }
00573 } // END class.ilObjDlBook
00574 
00575 ?>

Generated on Fri Dec 13 2013 17:56:52 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1