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

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

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