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

Services/MediaObjects/classes/class.ilMediaItem.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("Services/MediaObjects/classes/class.ilMapArea.php");
00025 
00036 class ilMediaItem
00037 {
00038         var $ilias;
00039         var $id;
00040         var $purpose;
00041         var $location;
00042         var $location_type;
00043         var $format;
00044         var $width;
00045         var $height;
00046         var $caption;
00047         var $halign;
00048         var $parameters;
00049         var $mob_id;
00050         var $nr;
00051         var $mapareas;
00052         var $map_cnt;
00053         var $map_image;                 // image map work copy image
00054         var $color1;                    // map area line color 1
00055         var $color2;                    // map area line color 2
00056 
00057         function ilMediaItem($a_id = 0)
00058         {
00059                 global $ilias;
00060 
00061                 $this->ilias =& $ilias;
00062                 $this->parameters = array();
00063                 $this->mapareas = array();
00064                 $this->map_cnt = 0;
00065 
00066                 if ($a_id != 0)
00067                 {
00068                         $this->setId($a_id);
00069                         $this->read();
00070                 }
00071         }
00072 
00078         function setId($a_id)
00079         {
00080                 $this->id = $a_id;
00081         }
00082 
00088         function getId()
00089         {
00090                 return $this->id;
00091         }
00092 
00098         function setMobId($a_mob_id)
00099         {
00100                 $this->mob_id = $a_mob_id;
00101         }
00102 
00108         function getMobId()
00109         {
00110                 return $this->mob_id;
00111         }
00112 
00116         function setNr($a_nr)
00117         {
00118                 $this->nr = $a_nr;
00119         }
00120 
00121         function getNr()
00122         {
00123                 return $this->nr;
00124         }
00125 
00129         function create()
00130         {
00131                 global $ilDB;
00132 
00133                 $query = "INSERT INTO media_item (mob_id, purpose, location, ".
00134                         "location_type, format, width, ".
00135                         "height, halign, caption, nr) VALUES ".
00136                         "(".$ilDB->quote($this->getMobId()).",".
00137                         $ilDB->quote($this->getPurpose()).",".
00138                         $ilDB->quote($this->getLocation()).",".
00139                         $ilDB->quote($this->getLocationType()).",".
00140                         $ilDB->quote($this->getFormat()).",".
00141                         $ilDB->quote($this->getWidth()).",".
00142                         $ilDB->quote($this->getHeight()).",".
00143                         $ilDB->quote($this->getHAlign()).",".
00144                         $ilDB->quote($this->getCaption()).",".
00145                         $ilDB->quote($this->getNr()).")";
00146                 $this->ilias->db->query($query);
00147 #echo "create_mob:$query:<br>";
00148                 $item_id = $this->ilias->db->getLastInsertId();
00149                 $this->setId($item_id);
00150 
00151                 // create mob parameters
00152                 $params = $this->getParameters();
00153                 foreach($params as $name => $value)
00154                 {
00155                         $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
00156                                 "(".$ilDB->quote($item_id).",".
00157                                 $ilDB->quote($name).",".
00158                                 $ilDB->quote($value).")";
00159                         $this->ilias->db->query($query);
00160                 }
00161 
00162                 // create map areas
00163                 for ($i=0; $i < count($this->mapareas); $i++)
00164                 {
00165                         $this->mapareas[$i]->setItemId($this->getId());
00166                         $this->mapareas[$i]->setNr($i + 1);
00167                         $this->mapareas[$i]->create();
00168                 }
00169         }
00170 
00174         function update()
00175         {
00176                 global $ilDB;
00177 
00178                 $query = "UPDATE media_item SET ".
00179                         " mob_id = ".$ilDB->quote($this->getMobId()).",".
00180                         " purpose = ".$ilDB->quote($this->getPurpose()).",".
00181                         " location = ".$ilDB->quote($this->getLocation()).",".
00182                         " location_type = ".$ilDB->quote($this->getLocationType()).",".
00183                         " format = ".$ilDB->quote($this->getFormat()).",".
00184                         " width = ".$ilDB->quote($this->getWidth()).",".
00185                         " height = ".$ilDB->quote($this->getHeight()).",".
00186                         " halign = ".$ilDB->quote($this->getHAlign()).",".
00187                         " caption = ".$ilDB->quote($this->getCaption()).",".
00188                         " nr = ".$ilDB->quote($this->getNr()).
00189                         " WHERE id = ".$ilDB->quote($this->getId());
00190                 $this->ilias->db->query($query);
00191 
00192                 // delete mob parameters
00193                 $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
00194                         $ilDB->quote($this->getId());
00195 
00196                 // create mob parameters
00197                 $params = $this->getParameters();
00198                 foreach($params as $name => $value)
00199                 {
00200                         $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
00201                                 "(".$ilDB->quote($this->getId()).",".
00202                                 $ilDB->quote($name).",".
00203                                 $ilDB->quote($value).")";
00204                         $this->ilias->db->query($query);
00205                 }
00206         }
00207 
00211         function read()
00212         {
00213                 global $ilDB;
00214                 
00215                 $item_id = $this->getId();
00216                 $mob_id = $this->getMobId();
00217                 $nr = $this->getNr();
00218                 $query = "";
00219                 if($item_id > 0)
00220                 {
00221                         $query = "SELECT * FROM media_item WHERE id = ".$ilDB->quote($this->getId());
00222                 }
00223                 else if ($mob_id > 0 && $nr > 0)
00224                 {
00225                         $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($this->getMobId())." ".
00226                                 "AND nr=".$ilDB->quote($this->getNr());
00227                 }
00228                 if ($query != "")
00229                 {
00230                         $item_set = $this->ilias->db->query($query);
00231                         $item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC);
00232 
00233                         $this->setLocation($item_rec["location"]);
00234                         $this->setLocationType($item_rec["location_type"]);
00235                         $this->setFormat($item_rec["format"]);
00236                         $this->setWidth($item_rec["width"]);
00237                         $this->setHeight($item_rec["height"]);
00238                         $this->setHAlign($item_rec["halign"]);
00239                         $this->setCaption($item_rec["caption"]);
00240                         $this->setPurpose($item_rec["purpose"]);
00241                         $this->setNr($item_rec["nr"]);
00242                         $this->setMobId($item_rec["mob_id"]);
00243                         $this->setId($item_rec["id"]);
00244                         $this->setThumbTried($item_rec["tried_thumb"]);
00245 
00246                         // get item parameter
00247                         $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
00248                                 $ilDB->quote($this->getId());
00249                         $par_set = $this->ilias->db->query($query);
00250                         while ($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
00251                         {
00252                                 $this->setParameter($par_rec["name"], $par_rec["value"]);
00253                         }
00254 
00255                         // get item map areas
00256                         $max = ilMapArea::_getMaxNr($this->getId());
00257                         for ($i = 1; $i <= $max; $i++)
00258                         {
00259                                 $area =& new ilMapArea($this->getId(), $i);
00260                                 $this->addMapArea($area);
00261                         }
00262                 }
00263 
00264         }
00265         
00269         function writeThumbTried($a_tried)
00270         {
00271                 global $ilDB;
00272                 
00273                 $q = "UPDATE media_item SET tried_thumb=".
00274                         $ilDB->quote($a_tried).
00275                         " WHERE id = ".$ilDB->quote($this->getId());
00276                         
00277                 $ilDB->query($q);
00278         }
00279 
00286         static function _lookupLocationForMobId($a_mob_id, $a_purpose)
00287         {
00288                 global $ilDB;
00289                 
00290                 // read media_object record
00291                 $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob_id)." ".
00292                         "AND purpose = ".$ilDB->quote($a_purpose);
00293                 $set = $ilDB->query($query);
00294                 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00295                 {
00296                         return $rec["location"];
00297                 }
00298 
00299                 return "";
00300         }
00301         
00302         
00308         function _getMediaItemsOfMOb(&$a_mob)
00309         {
00310                 global $ilDB;
00311                 
00312                 // read media_object record
00313                 $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob->getId())." ".
00314                         "ORDER BY nr";
00315                 $item_set = $this->ilias->db->query($query);
00316                 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
00317                 {
00318                         $media_item =& new ilMediaItem();
00319                         $media_item->setNr($item_rec["nr"]);
00320                         $media_item->setId($item_rec["id"]);
00321                         $media_item->setLocation($item_rec["location"]);
00322                         $media_item->setLocationType($item_rec["location_type"]);
00323                         $media_item->setFormat($item_rec["format"]);
00324                         $media_item->setWidth($item_rec["width"]);
00325                         $media_item->setHeight($item_rec["height"]);
00326                         $media_item->setHAlign($item_rec["halign"]);
00327                         $media_item->setCaption($item_rec["caption"]);
00328                         $media_item->setPurpose($item_rec["purpose"]);
00329                         $media_item->setMobId($item_rec["mob_id"]);
00330                         $media_item->setThumbTried($item_rec["tried_thumb"]);
00331 
00332                         // get item parameter
00333                         $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
00334                                 $ilDB->quote($item_rec["id"]);
00335                         $par_set = $this->ilias->db->query($query);
00336                         while ($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
00337                         {
00338                                 $media_item->setParameter($par_rec["name"], $par_rec["value"]);
00339                         }
00340 
00341                         // get item map areas
00342                         $max = ilMapArea::_getMaxNr($media_item->getId());
00343                         for ($i = 1; $i <= $max; $i++)
00344                         {
00345                                 $area =& new ilMapArea($media_item->getId(), $i);
00346                                 $media_item->addMapArea($area);
00347                         }
00348 
00349                         // add media item to media object
00350                         $a_mob->addMediaItem($media_item);
00351                 }
00352         }
00353 
00357         function deleteAllItemsOfMob($a_mob_id)
00358         {
00359                 global $ilDB;
00360                 
00361                 // iterate all media items ob mob
00362                 $query = "SELECT * FROM media_item WHERE mob_id = ".
00363                         $ilDB->quote($a_mob_id);
00364                 $item_set = $this->ilias->db->query($query);
00365                 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
00366                 {
00367                         // delete all parameters of media item
00368                         $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
00369                                 $ilDB->quote($item_rec["id"]);
00370                         $this->ilias->db->query($query);
00371 
00372                         // delete all map areas of media item
00373                         $query = "DELETE FROM map_area WHERE item_id = ".
00374                                 $ilDB->quote($item_rec["id"]);
00375                         $this->ilias->db->query($query);
00376                 }
00377 
00378                 // delete media items
00379                 $query = "DELETE FROM media_item WHERE mob_id = ".
00380                         $ilDB->quote($a_mob_id);
00381                 $this->ilias->db->query($query);
00382         }
00383 
00384         function setPurpose($a_purpose)
00385         {
00386                 $this->purpose = $a_purpose;
00387         }
00388 
00389         function getPurpose()
00390         {
00391                 return $this->purpose;
00392         }
00393 
00394         function setLocation($a_location)
00395         {
00396                 $this->location = $a_location;
00397         }
00398 
00399         function getLocation()
00400         {
00401                 return $this->location;
00402         }
00403 
00404         function setLocationType($a_type)
00405         {
00406                 $this->location_type = $a_type;
00407         }
00408 
00409         function getLocationType()
00410         {
00411                 return $this->location_type;
00412         }
00413 
00414         function setFormat($a_format)
00415         {
00416                 $this->format = $a_format;
00417         }
00418 
00419         function getFormat()
00420         {
00421                 return $this->format;
00422         }
00423 
00424         function setThumbTried($a_tried)
00425         {
00426                 $this->tried_thumb = $a_tried;
00427         }
00428 
00429         function getThumbTried()
00430         {
00431                 return $this->tried_thumb;
00432         }
00433 
00434         function addMapArea(&$a_map_area)
00435         {
00436                 $this->mapareas[$this->map_cnt] =& $a_map_area;
00437                 $this->map_cnt++;
00438         }
00439 
00443         function deleteMapArea($nr)
00444         {
00445                 for ($i=1; $i<=$this->map_cnt; $i++)
00446                 {
00447                         if($i > $nr)
00448                         {
00449                                 $this->mapareas[$i-2] =& $this->mapareas[$i-1];
00450                                 $this->mapareas[$i-2]->setNr($i-1);
00451                         }
00452                 }
00453                 if($nr <= $this->map_cnt)
00454                 {
00455                         unset($this->mapareas[$this->map_cnt - 1]);
00456                         $this->map_cnt--;
00457                 }
00458         }
00459 
00463         function &getMapArea($nr)
00464         {
00465                 return $this->mapareas[$nr-1];
00466         }
00467 
00471         function getWidth()
00472         {
00473                 return $this->width;
00474         }
00475 
00479         function setWidth($a_width)
00480         {
00481                 $this->width = $a_width;
00482         }
00483 
00487         function getHeight()
00488         {
00489                 return $this->height;
00490         }
00491 
00495         function setHeight($a_height)
00496         {
00497                 $this->height = $a_height;
00498         }
00499 
00503         function getOriginalSize()
00504         {
00505                 $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
00506 
00507                 if ($this->getLocationType() == "LocalFile" &&
00508                         ilUtil::deducibleSize($this->getFormat()))
00509                 {
00510                         $file = $mob_dir."/".$this->getLocation();
00511                         if (is_file($file))
00512                         {
00513                                 $size = getimagesize($file);
00514                         }
00515                         else
00516                         {
00517                                 $size[0] = $size[1] = 0;
00518                         }
00519                         $size = array("width" => $size[0], "height" => $size[1]);
00520                         
00521                         return $size;
00522                 }
00523 
00524                 return false;
00525         }
00526 
00530         function setCaption($a_caption)
00531         {
00532                 $this->caption = $a_caption;
00533         }
00534 
00538         function getCaption()
00539         {
00540                 return $this->caption;
00541         }
00542 
00546         function setHAlign($a_halign)
00547         {
00548                 $this->halign = $a_halign;
00549         }
00550 
00554         function getHAlign()
00555         {
00556                 return $this->halign;
00557         }
00558 
00559 
00566         function setParameter($a_name, $a_value)
00567         {
00568                 $this->parameters[$a_name] = $a_value;
00569         }
00570 
00574         function resetParameters()
00575         {
00576                 $this->parameters = array();
00577         }
00578 
00584         function setParameters($a_par)
00585         {
00586                 $this->resetParameters();
00587                 $par_arr = ilUtil::extractParameterString($a_par);
00588                 if(is_array($par_arr))
00589                 {
00590                         foreach($par_arr as $par => $val)
00591                         {
00592                                 $this->setParameter($par, $val);
00593                         }
00594                 }
00595         }
00596 
00597 
00601         function getParameters()
00602         {
00603                 return $this->parameters;
00604         }
00605 
00606 
00610         function getParameterString()
00611         {
00612                 return ilUtil::assembleParameterString($this->parameters);
00613         }
00614 
00615 
00619         function getParameter($a_name)
00620         {
00621                 return $this->parameters[$a_name];
00622         }
00623 
00627         function getWorkDirectory()
00628         {
00629                 return ilUtil::getDataDir()."/map_workfiles/item_".$this->getId();
00630         }
00631 
00635         function createWorkDirectory()
00636         {
00637                 if(!@is_dir(ilUtil::getDataDir()."/map_workfiles"))
00638                 {
00639                         ilUtil::createDirectory(ilUtil::getDataDir()."/map_workfiles");
00640                 }
00641                 $work_dir = $this->getWorkDirectory();
00642                 if(!@is_dir($work_dir))
00643                 {
00644                         ilUtil::createDirectory($work_dir);
00645                 }
00646         }
00647 
00651         function getSuffix()
00652         {
00653                 $loc_arr = explode(".", $this->getLocation());
00654 
00655                 return $loc_arr[count($loc_arr) - 1];
00656         }
00657 
00661         function getMapWorkCopyType()
00662         {
00663                 return ilUtil::getGDSupportedImageType($this->getSuffix());
00664         }
00665 
00671         function getMapWorkCopyName($a_reference_copy = false)
00672         {
00673                 $file_arr = explode("/", $this->getLocation());
00674                 $o_file = $file_arr[count($file_arr) - 1];
00675                 $file_arr = explode(".", $o_file);
00676                 unset($file_arr[count($file_arr) - 1]);
00677                 $file = implode($file_arr, ".");
00678 
00679                 if (!$a_reference_copy)
00680                 {
00681                         return $this->getWorkDirectory()."/".$file.".".$this->getMapWorkCopyType();
00682                 }
00683                 else
00684                 {
00685                         return $this->getWorkDirectory()."/l_copy_".$o_file;
00686                 }
00687         }
00688 
00692         function getDirectory()
00693         {
00694                 return ilObjMediaObject::_getDirectory($this->getMobId());
00695         }
00696 
00700         function getThumbnailDirectory($a_mode = "filesystem")
00701         {
00702                 return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
00703         }
00704 
00708         function getThumbnailTarget($a_size = "")
00709         {
00710                 if (is_int(strpos($this->getFormat(), "image")))
00711                 {
00712                         $thumb_file = $this->getThumbnailDirectory()."/".
00713                                 $this->getPurpose().".jpeg";
00714 
00715                         $thumb_file_small = $this->getThumbnailDirectory()."/".
00716                                 $this->getPurpose()."_small.jpeg";
00717 
00718                         // generate thumbnail (if not tried before)
00719                         if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile")
00720                         {
00721                                 if (is_file($thumb_file))
00722                                 {
00723                                         unlink($thumb_file);
00724                                 }
00725                                 if (is_file($thumb_file_small))
00726                                 {
00727                                         unlink($thumb_file_small);
00728                                 }
00729                                 $this->writeThumbTried("y");
00730                                 ilObjMediaObject::_createThumbnailDirectory($this->getMobId());
00731                                 $med_file = $this->getDirectory()."/".$this->getLocation();
00732 
00733                                 if (is_file($med_file))
00734                                 {
00735                                         ilUtil::convertImage($med_file, $thumb_file, "jpeg", "80");
00736                                         ilUtil::convertImage($med_file, $thumb_file_small, "jpeg", "40");
00737                                 }
00738                         }
00739 
00740                         if ($a_size == "small")
00741                         {
00742                                 if (is_file($thumb_file_small))
00743                                 {
00744                                         return $this->getThumbnailDirectory("output")."/".
00745                                                 $this->getPurpose()."_small.jpeg?dummy=".rand(1, 999999);
00746                                 }
00747                         }
00748                         else
00749                         {
00750                                 if (is_file($thumb_file))
00751                                 {
00752                                         return $this->getThumbnailDirectory("output")."/".
00753                                                 $this->getPurpose().".jpeg?dummy=".rand(1, 999999);
00754                                 }
00755                         }
00756                 }
00757 
00758                 return "";
00759         }
00760 
00761 
00768         function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
00769         {
00770                 global $lng;
00771                 
00772                 $this->createWorkDirectory();
00773                 
00774 //echo "-".$this->getLocationType()."-";
00775 //echo "-".$this->getLocation()."-";
00776                 if ($this->getLocationType() != "Reference")
00777                 {
00778                         ilUtil::convertImage($this->getDirectory()."/".$this->getLocation(),
00779                                 $this->getMapWorkCopyName(),
00780                                 $this->getMapWorkCopyType());
00781                 }
00782                 else
00783                 {
00784                         // first copy the external file, if necessary
00785                         if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0))
00786                         {
00787                                 $handle = @fopen($this->getLocation(), "r");
00788                                 $lcopy = fopen($this->getMapWorkCopyName(true), "w");
00789                                 if ($handle && $lcopy)
00790                                 {
00791                                         while (!feof($handle))
00792                                         {
00793                                                 $content = fread($handle, 4096);
00794                                                 fwrite($lcopy, $content);
00795                                         }
00796                                 }
00797                                 @fclose($lcopy);
00798                                 @fclose($handle);
00799                         }
00800                         
00801                         // now, create working copy
00802                         ilUtil::convertImage($this->getMapWorkCopyName(true),
00803                                 $this->getMapWorkCopyName(),
00804                                 $this->getMapWorkCopyType());
00805                 }
00806 
00807                 if (!is_file($this->getMapWorkCopyName()))
00808                 {
00809                         ilUtil::sendInfo($lng->txt("cont_map_file_not_generated"));
00810                         return false;
00811                 }
00812                 
00813                 $this->buildMapWorkImage();
00814                 
00815                 // determine ratios
00816                 $size = @getimagesize($this->getMapWorkCopyName());
00817                 $x_ratio = 1;
00818                 if ($size[0] > 0 && $this->getWidth() > 0)
00819                 {
00820                         $x_ratio = $this->getWidth() / $size[0];
00821                 }
00822                 $y_ratio = 1;
00823                 if ($size[1] > 0 && $this->getHeight() > 0)
00824                 {
00825                         $y_ratio = $this->getHeight() / $size[1];
00826                 }
00827 
00828                 // draw map areas
00829                 for ($i=0; $i < count($this->mapareas); $i++)
00830                 {
00831                         if (    ((($i+1) == $a_area_nr) && !$a_exclude) ||
00832                                         ((($i+1) != $a_area_nr) && $a_exclude) ||
00833                                         ($a_area_nr == 0)
00834                                 )
00835                         {
00836                                 $area =& $this->mapareas[$i];
00837                                 $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, true,
00838                                         $x_ratio, $y_ratio);
00839                         }
00840                 }
00841 
00842                 $this->saveMapWorkImage();
00843                 
00844                 return true;
00845         }
00846 
00847 
00854         function addAreaToMapWorkCopy($a_shape, $a_coords)
00855         {
00856                 $this->buildMapWorkImage();
00857 
00858                 // determine ratios
00859                 $size = @getimagesize($this->getMapWorkCopyName());
00860                 $x_ratio = 1;
00861                 if ($size[0] > 0 && $this->getWidth() > 0)
00862                 {
00863                         $x_ratio = $this->getWidth() / $size[0];
00864                 }
00865                 $y_ratio = 1;
00866                 if ($size[1] > 0 && $this->getHeight() > 0)
00867                 {
00868                         $y_ratio = $this->getHeight() / $size[1];
00869                 }
00870 
00871                 // add new area to work image
00872                 $area = new ilMapArea();
00873                 $area->setShape($a_shape);
00874 //echo "addAreaToMap:".$a_shape.":<br>";
00875                 $area->setCoords($a_coords);
00876                 $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, false,
00877                         $x_ratio, $y_ratio);
00878 
00879                 $this->saveMapWorkImage();
00880         }
00881 
00885         function outputMapWorkCopy()
00886         {
00887                 if ($this->getMapWorkCopyType() != "")
00888                 {
00889                         header("Pragma: no-cache");
00890                         header("Expires: 0");
00891                         header("Content-type: image/".strtolower($this->getMapWorkCopyType()));
00892                         readfile($this->getMapWorkCopyName());
00893                 }
00894                 exit;
00895         }
00896 
00900         function buildMapWorkImage()
00901         {
00902                 $im_type = strtolower($this->getMapWorkCopyType());
00903 
00904                 switch ($im_type)
00905                 {
00906                         case "gif":
00907                                 $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
00908                                 break;
00909 
00910                         case "jpg":
00911                                 $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
00912                                 break;
00913 
00914                         case "png":
00915                                 $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
00916                                 break;
00917                 }
00918 
00919                 // try to allocate black and white as color. if this is not possible, get the closest colors
00920                 if (imagecolorstotal($this->map_image) > 250)
00921                 {
00922                         $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
00923                         $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
00924                 }
00925                 else
00926                 {
00927                         $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
00928                         $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
00929                 }
00930         }
00931 
00935         function saveMapWorkImage()
00936         {
00937                 $im_type = strtolower($this->getMapWorkCopyType());
00938 
00939                 // save image work-copy and free memory
00940                 switch ($im_type)
00941                 {
00942                         case "gif":
00943                                 ImageGIF($this->map_image, $this->getMapWorkCopyName());
00944                                 break;
00945 
00946                         case "jpg":
00947                                 ImageJPEG($this->map_image, $this->getMapWorkCopyName());
00948                                 break;
00949 
00950                         case "png":
00951                                 ImagePNG($this->map_image, $this->getMapWorkCopyName());
00952                                 break;
00953                 }
00954 
00955                 ImageDestroy($this->map_image);
00956         }
00957 
00961         function &getMapWorkImage()
00962         {
00963                 return $this->map_image;
00964         }
00965 
00966 
00970         function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
00971         {
00972                 $xml = "";
00973 
00974                 // build xml of map areas
00975                 for ($i=0; $i < count($this->mapareas); $i++)
00976                 {
00977                         $area =& $this->mapareas[$i];
00978                         $xml .= "<MapArea Shape=\"".$area->getShape()."\" Coords=\"".$area->getCoords()."\">";
00979                         if ($area->getLinkType() == IL_INT_LINK)
00980                         {
00981                                 $target_frame = $area->getTargetFrame();
00982 
00983                                 if ($area->getType() == "GlossaryItem" && $target_frame == "")
00984                                 {
00985                                         $target_frame = "Glossary";
00986                                 }
00987 
00988                                 $tf_str = ($target_frame == "")
00989                                         ? ""
00990                                         : "TargetFrame=\"".$target_frame."\"";
00991                                 
00992                                 $xml .= "<IntLink Target=\"".$area->getTarget($a_insert_inst, $a_inst)."\" Type=\"".
00993                                         $area->getType()."\" $tf_str>";
00994                                 $xml .= $area->getTitle();
00995                                 $xml .="</IntLink>";
00996                         }
00997                         else
00998                         {
00999                                 $xml .= "<ExtLink Href=\"".str_replace("&", "&amp;",$area->getHref())."\" Title=\"".
01000                                         $area->getExtTitle()."\">";
01001                                 $xml .= $area->getTitle();
01002                                 $xml .="</ExtLink>";
01003                         }
01004                         $xml .= "</MapArea>";
01005                 }
01006 
01007                 return $xml;
01008         }
01009 
01010 
01016         function _resolveMapAreaLinks($a_mob_id)
01017         {
01018                 global $ilDB;
01019                 
01020 //echo "mediaItems::resolve<br>";
01021                 // read media_object record
01022                 $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob_id)." ".
01023                         "ORDER BY nr";
01024                 $item_set = $this->ilias->db->query($query);
01025                 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
01026                 {
01027                         ilMapArea::_resolveIntLinks($item_rec["id"]);
01028                 }
01029         }
01030 
01036         function _getMapAreasIntLinks($a_mob_id)
01037         {
01038                 global $ilDB;
01039                 
01040                 // read media_items records
01041                 $query = "SELECT * FROM media_item WHERE mob_id = ".
01042                         $ilDB->quote($a_mob_id)." ORDER BY nr";
01043 
01044                 $item_set = $this->ilias->db->query($query);
01045                 $links = array();
01046                 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
01047                 {
01048                         $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
01049                         foreach($map_links as $key => $map_link)
01050                         {
01051                                 $links[$key] = $map_link;
01052                         }
01053                 }
01054                 return $links;
01055         }
01056 
01057 }
01058 ?>

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