ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMediaItem.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("Services/MediaObjects/classes/class.ilMapArea.php");
25 
37 {
38  var $ilias;
39  var $id;
40  var $purpose;
41  var $location;
43  var $format;
44  var $width;
45  var $height;
46  var $caption;
47  var $halign;
49  var $mob_id;
50  var $nr;
51  var $mapareas;
52  var $map_cnt;
53  var $map_image; // image map work copy image
54  var $color1; // map area line color 1
55  var $color2; // map area line color 2
56 
57  function ilMediaItem($a_id = 0)
58  {
59  global $ilias;
60 
61  $this->ilias =& $ilias;
62  $this->parameters = array();
63  $this->mapareas = array();
64  $this->map_cnt = 0;
65 
66  if ($a_id != 0)
67  {
68  $this->setId($a_id);
69  $this->read();
70  }
71  }
72 
78  function setId($a_id)
79  {
80  $this->id = $a_id;
81  }
82 
88  function getId()
89  {
90  return $this->id;
91  }
92 
98  function setMobId($a_mob_id)
99  {
100  $this->mob_id = $a_mob_id;
101  }
102 
108  function getMobId()
109  {
110  return $this->mob_id;
111  }
112 
116  function setNr($a_nr)
117  {
118  $this->nr = $a_nr;
119  }
120 
121  function getNr()
122  {
123  return $this->nr;
124  }
125 
129  function create()
130  {
131  global $ilDB;
132 
133  $query = "INSERT INTO media_item (mob_id, purpose, location, ".
134  "location_type, format, width, ".
135  "height, halign, caption, nr) VALUES ".
136  "(".$ilDB->quote($this->getMobId()).",".
137  $ilDB->quote($this->getPurpose()).",".
138  $ilDB->quote($this->getLocation()).",".
139  $ilDB->quote($this->getLocationType()).",".
140  $ilDB->quote($this->getFormat()).",".
141  $ilDB->quote($this->getWidth()).",".
142  $ilDB->quote($this->getHeight()).",".
143  $ilDB->quote($this->getHAlign()).",".
144  $ilDB->quote($this->getCaption()).",".
145  $ilDB->quote($this->getNr()).")";
146  $this->ilias->db->query($query);
147 #echo "create_mob:$query:<br>";
148  $item_id = $this->ilias->db->getLastInsertId();
149  $this->setId($item_id);
150 
151  // create mob parameters
152  $params = $this->getParameters();
153  foreach($params as $name => $value)
154  {
155  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
156  "(".$ilDB->quote($item_id).",".
157  $ilDB->quote($name).",".
158  $ilDB->quote($value).")";
159  $this->ilias->db->query($query);
160  }
161 
162  // create map areas
163  for ($i=0; $i < count($this->mapareas); $i++)
164  {
165  $this->mapareas[$i]->setItemId($this->getId());
166  $this->mapareas[$i]->setNr($i + 1);
167  $this->mapareas[$i]->create();
168  }
169  }
170 
174  function update()
175  {
176  global $ilDB;
177 
178  $query = "UPDATE media_item SET ".
179  " mob_id = ".$ilDB->quote($this->getMobId()).",".
180  " purpose = ".$ilDB->quote($this->getPurpose()).",".
181  " location = ".$ilDB->quote($this->getLocation()).",".
182  " location_type = ".$ilDB->quote($this->getLocationType()).",".
183  " format = ".$ilDB->quote($this->getFormat()).",".
184  " width = ".$ilDB->quote($this->getWidth()).",".
185  " height = ".$ilDB->quote($this->getHeight()).",".
186  " halign = ".$ilDB->quote($this->getHAlign()).",".
187  " caption = ".$ilDB->quote($this->getCaption()).",".
188  " nr = ".$ilDB->quote($this->getNr()).
189  " WHERE id = ".$ilDB->quote($this->getId());
190  $this->ilias->db->query($query);
191 
192  // delete mob parameters
193  $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
194  $ilDB->quote($this->getId());
195 
196  // create mob parameters
197  $params = $this->getParameters();
198  foreach($params as $name => $value)
199  {
200  $query = "INSERT INTO mob_parameter (med_item_id, name, value) VALUES ".
201  "(".$ilDB->quote($this->getId()).",".
202  $ilDB->quote($name).",".
203  $ilDB->quote($value).")";
204  $this->ilias->db->query($query);
205  }
206  }
207 
211  function read()
212  {
213  global $ilDB;
214 
215  $item_id = $this->getId();
216  $mob_id = $this->getMobId();
217  $nr = $this->getNr();
218  $query = "";
219  if($item_id > 0)
220  {
221  $query = "SELECT * FROM media_item WHERE id = ".$ilDB->quote($this->getId());
222  }
223  else if ($mob_id > 0 && $nr > 0)
224  {
225  $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($this->getMobId())." ".
226  "AND nr=".$ilDB->quote($this->getNr());
227  }
228  if ($query != "")
229  {
230  $item_set = $this->ilias->db->query($query);
231  $item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC);
232 
233  $this->setLocation($item_rec["location"]);
234  $this->setLocationType($item_rec["location_type"]);
235  $this->setFormat($item_rec["format"]);
236  $this->setWidth($item_rec["width"]);
237  $this->setHeight($item_rec["height"]);
238  $this->setHAlign($item_rec["halign"]);
239  $this->setCaption($item_rec["caption"]);
240  $this->setPurpose($item_rec["purpose"]);
241  $this->setNr($item_rec["nr"]);
242  $this->setMobId($item_rec["mob_id"]);
243  $this->setId($item_rec["id"]);
244  $this->setThumbTried($item_rec["tried_thumb"]);
245 
246  // get item parameter
247  $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
248  $ilDB->quote($this->getId());
249  $par_set = $this->ilias->db->query($query);
250  while ($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
251  {
252  $this->setParameter($par_rec["name"], $par_rec["value"]);
253  }
254 
255  // get item map areas
256  $max = ilMapArea::_getMaxNr($this->getId());
257  for ($i = 1; $i <= $max; $i++)
258  {
259  $area =& new ilMapArea($this->getId(), $i);
260  $this->addMapArea($area);
261  }
262  }
263 
264  }
265 
269  function writeThumbTried($a_tried)
270  {
271  global $ilDB;
272 
273  $q = "UPDATE media_item SET tried_thumb=".
274  $ilDB->quote($a_tried).
275  " WHERE id = ".$ilDB->quote($this->getId());
276 
277  $ilDB->query($q);
278  }
279 
286  static function _lookupLocationForMobId($a_mob_id, $a_purpose)
287  {
288  global $ilDB;
289 
290  // read media_object record
291  $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob_id)." ".
292  "AND purpose = ".$ilDB->quote($a_purpose);
293  $set = $ilDB->query($query);
294  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
295  {
296  return $rec["location"];
297  }
298 
299  return "";
300  }
301 
307  static function _lookupMobId($a_med_id)
308  {
309  global $ilDB;
310 
311  // read media_object record
312  $query = "SELECT * FROM media_item WHERE id = ".$ilDB->quote($a_med_id);
313  $set = $ilDB->query($query);
314  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
315  {
316  return $rec["mob_id"];
317  }
318 
319  return "";
320  }
321 
322  /* read media item with specific purpose and mobId
323  *
324  * @param integer $a_mobId media object id
325  * @param string $a_purpose media object purpose
326  * @return array $mob media object
327  */
328  function _getMediaItemsOfMObId($a_mobId, $a_purpose)
329  {
330  global $ilDB;
331 
332  // read media_object record
333  $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mobId)." ".
334  "AND purpose=" . $ilDB->quote($a_purpose) . " ORDER BY nr";
335  $item_set = $ilDB->query($query);
336 
337  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
338  {
339  return $item_rec;
340  }
341  return false;
342  }
343 
349  function _getMediaItemsOfMOb(&$a_mob)
350  {
351  global $ilDB;
352 
353  // read media_object record
354  $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob->getId())." ".
355  "ORDER BY nr";
356  $item_set = $this->ilias->db->query($query);
357  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
358  {
359  $media_item =& new ilMediaItem();
360  $media_item->setNr($item_rec["nr"]);
361  $media_item->setId($item_rec["id"]);
362  $media_item->setLocation($item_rec["location"]);
363  $media_item->setLocationType($item_rec["location_type"]);
364  $media_item->setFormat($item_rec["format"]);
365  $media_item->setWidth($item_rec["width"]);
366  $media_item->setHeight($item_rec["height"]);
367  $media_item->setHAlign($item_rec["halign"]);
368  $media_item->setCaption($item_rec["caption"]);
369  $media_item->setPurpose($item_rec["purpose"]);
370  $media_item->setMobId($item_rec["mob_id"]);
371  $media_item->setThumbTried($item_rec["tried_thumb"]);
372 
373  // get item parameter
374  $query = "SELECT * FROM mob_parameter WHERE med_item_id = ".
375  $ilDB->quote($item_rec["id"]);
376  $par_set = $this->ilias->db->query($query);
377  while ($par_rec = $par_set->fetchRow(DB_FETCHMODE_ASSOC))
378  {
379  $media_item->setParameter($par_rec["name"], $par_rec["value"]);
380  }
381 
382  // get item map areas
383  $max = ilMapArea::_getMaxNr($media_item->getId());
384  for ($i = 1; $i <= $max; $i++)
385  {
386  $area =& new ilMapArea($media_item->getId(), $i);
387  $media_item->addMapArea($area);
388  }
389 
390  // add media item to media object
391  $a_mob->addMediaItem($media_item);
392  }
393  }
394 
398  function deleteAllItemsOfMob($a_mob_id)
399  {
400  global $ilDB;
401 
402  // iterate all media items ob mob
403  $query = "SELECT * FROM media_item WHERE mob_id = ".
404  $ilDB->quote($a_mob_id);
405  $item_set = $this->ilias->db->query($query);
406  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
407  {
408  // delete all parameters of media item
409  $query = "DELETE FROM mob_parameter WHERE med_item_id = ".
410  $ilDB->quote($item_rec["id"]);
411  $this->ilias->db->query($query);
412 
413  // delete all map areas of media item
414  $query = "DELETE FROM map_area WHERE item_id = ".
415  $ilDB->quote($item_rec["id"]);
416  $this->ilias->db->query($query);
417  }
418 
419  // delete media items
420  $query = "DELETE FROM media_item WHERE mob_id = ".
421  $ilDB->quote($a_mob_id);
422  $this->ilias->db->query($query);
423  }
424 
425  function setPurpose($a_purpose)
426  {
427  $this->purpose = $a_purpose;
428  }
429 
430  function getPurpose()
431  {
432  return $this->purpose;
433  }
434 
435  function setLocation($a_location)
436  {
437  $this->location = $a_location;
438  }
439 
440  function getLocation()
441  {
442  return $this->location;
443  }
444 
445  function setLocationType($a_type)
446  {
447  $this->location_type = $a_type;
448  }
449 
450  function getLocationType()
451  {
452  return $this->location_type;
453  }
454 
455  function setFormat($a_format)
456  {
457  $this->format = $a_format;
458  }
459 
460  function getFormat()
461  {
462  return $this->format;
463  }
464 
465  function setThumbTried($a_tried)
466  {
467  $this->tried_thumb = $a_tried;
468  }
469 
470  function getThumbTried()
471  {
472  return $this->tried_thumb;
473  }
474 
475  function addMapArea(&$a_map_area)
476  {
477  $this->mapareas[$this->map_cnt] =& $a_map_area;
478  $this->map_cnt++;
479  }
480 
484  function deleteMapArea($nr)
485  {
486  for ($i=1; $i<=$this->map_cnt; $i++)
487  {
488  if($i > $nr)
489  {
490  $this->mapareas[$i-2] =& $this->mapareas[$i-1];
491  $this->mapareas[$i-2]->setNr($i-1);
492  }
493  }
494  if($nr <= $this->map_cnt)
495  {
496  unset($this->mapareas[$this->map_cnt - 1]);
497  $this->map_cnt--;
498  }
499  }
500 
504  function &getMapArea($nr)
505  {
506  return $this->mapareas[$nr-1];
507  }
508 
512  function getMapAreas()
513  {
514  return $this->mapareas;
515  }
516 
520  function getWidth()
521  {
522  return $this->width;
523  }
524 
528  function setWidth($a_width)
529  {
530  $this->width = $a_width;
531  }
532 
536  function getHeight()
537  {
538  return $this->height;
539  }
540 
544  function setHeight($a_height)
545  {
546  $this->height = $a_height;
547  }
548 
552  function getOriginalSize()
553  {
554  $mob_dir = ilObjMediaObject::_getDirectory($this->getMobId());
555 
556  if ($this->getLocationType() == "LocalFile" &&
558  {
559  $file = $mob_dir."/".$this->getLocation();
560  if (is_file($file))
561  {
562  $size = getimagesize($file);
563  }
564  else
565  {
566  $size[0] = $size[1] = 0;
567  }
568  $size = array("width" => $size[0], "height" => $size[1]);
569 
570  return $size;
571  }
572 
573  return false;
574  }
575 
579  function setCaption($a_caption)
580  {
581  $this->caption = $a_caption;
582  }
583 
587  function getCaption()
588  {
589  return $this->caption;
590  }
591 
595  function setHAlign($a_halign)
596  {
597  $this->halign = $a_halign;
598  }
599 
603  function getHAlign()
604  {
605  return $this->halign;
606  }
607 
608 
615  function setParameter($a_name, $a_value)
616  {
617  $this->parameters[$a_name] = $a_value;
618  }
619 
623  function resetParameters()
624  {
625  $this->parameters = array();
626  }
627 
633  function setParameters($a_par)
634  {
635  $this->resetParameters();
636  $par_arr = ilUtil::extractParameterString($a_par);
637  if(is_array($par_arr))
638  {
639  foreach($par_arr as $par => $val)
640  {
641  $this->setParameter($par, $val);
642  }
643  }
644  }
645 
646 
650  function getParameters()
651  {
652  return $this->parameters;
653  }
654 
655 
660  {
661  return ilUtil::assembleParameterString($this->parameters);
662  }
663 
664 
668  function getParameter($a_name)
669  {
670  return $this->parameters[$a_name];
671  }
672 
676  function getWorkDirectory()
677  {
678  return ilUtil::getDataDir()."/map_workfiles/item_".$this->getId();
679  }
680 
685  {
686  if(!@is_dir(ilUtil::getDataDir()."/map_workfiles"))
687  {
688  ilUtil::createDirectory(ilUtil::getDataDir()."/map_workfiles");
689  }
690  $work_dir = $this->getWorkDirectory();
691  if(!@is_dir($work_dir))
692  {
693  ilUtil::createDirectory($work_dir);
694  }
695  }
696 
700  function getSuffix()
701  {
702  $loc_arr = explode(".", $this->getLocation());
703 
704  return $loc_arr[count($loc_arr) - 1];
705  }
706 
711  {
713  }
714 
720  function getMapWorkCopyName($a_reference_copy = false)
721  {
722  $file_arr = explode("/", $this->getLocation());
723  $o_file = $file_arr[count($file_arr) - 1];
724  $file_arr = explode(".", $o_file);
725  unset($file_arr[count($file_arr) - 1]);
726  $file = implode($file_arr, ".");
727 
728  if (!$a_reference_copy)
729  {
730  return $this->getWorkDirectory()."/".$file.".".$this->getMapWorkCopyType();
731  }
732  else
733  {
734  return $this->getWorkDirectory()."/l_copy_".$o_file;
735  }
736  }
737 
741  function getDirectory()
742  {
743  return ilObjMediaObject::_getDirectory($this->getMobId());
744  }
745 
749  function getThumbnailDirectory($a_mode = "filesystem")
750  {
751  return ilObjMediaObject::_getThumbnailDirectory($this->getMobId(), $a_mode);
752  }
753 
757  function getThumbnailTarget($a_size = "")
758  {
759  if (is_int(strpos($this->getFormat(), "image")))
760  {
761  $thumb_file = $this->getThumbnailDirectory()."/".
762  $this->getPurpose().".jpeg";
763 
764  $thumb_file_small = $this->getThumbnailDirectory()."/".
765  $this->getPurpose()."_small.jpeg";
766 
767  // generate thumbnail (if not tried before)
768  if ($this->getThumbTried() == "n" && $this->getLocationType() == "LocalFile")
769  {
770  if (is_file($thumb_file))
771  {
772  unlink($thumb_file);
773  }
774  if (is_file($thumb_file_small))
775  {
776  unlink($thumb_file_small);
777  }
778  $this->writeThumbTried("y");
780  $med_file = $this->getDirectory()."/".$this->getLocation();
781 
782  if (is_file($med_file))
783  {
784  ilUtil::convertImage($med_file, $thumb_file, "jpeg", "80");
785  ilUtil::convertImage($med_file, $thumb_file_small, "jpeg", "40");
786  }
787  }
788 
789  if ($a_size == "small")
790  {
791  if (is_file($thumb_file_small))
792  {
793  return $this->getThumbnailDirectory("output")."/".
794  $this->getPurpose()."_small.jpeg?dummy=".rand(1, 999999);
795  }
796  }
797  else
798  {
799  if (is_file($thumb_file))
800  {
801  return $this->getThumbnailDirectory("output")."/".
802  $this->getPurpose().".jpeg?dummy=".rand(1, 999999);
803  }
804  }
805  }
806 
807  return "";
808  }
809 
810 
814  function copyOriginal()
815  {
816  global $lng;
817  $this->createWorkDirectory();
818 
819  if ($this->getLocationType() != "Reference")
820  {
821  ilUtil::convertImage($this->getDirectory()."/".$this->getLocation(),
822  $this->getMapWorkCopyName(),
823  $this->getMapWorkCopyType());
824  }
825  else
826  {
827  // first copy the external file, if necessary
828  if (!is_file($this->getMapWorkCopyName(true)) || (filesize($this->getMapWorkCopyName(true)) == 0))
829  {
830  $handle = @fopen($this->getLocation(), "r");
831  $lcopy = fopen($this->getMapWorkCopyName(true), "w");
832  if ($handle && $lcopy)
833  {
834  while (!feof($handle))
835  {
836  $content = fread($handle, 4096);
837  fwrite($lcopy, $content);
838  }
839  }
840  @fclose($lcopy);
841  @fclose($handle);
842  }
843 
844  // now, create working copy
846  $this->getMapWorkCopyName(),
847  $this->getMapWorkCopyType());
848  }
849 
850  if (!is_file($this->getMapWorkCopyName()))
851  {
852 
853  ilUtil::sendInfo($lng->txt("cont_map_file_not_generated"));
854  return false;
855  }
856  return true;
857  }
858 
865  function makeMapWorkCopy($a_area_nr = 0, $a_exclude = false)
866  {
867  global $lng;
868 
869  if (!$this->copyOriginal())
870  {
871  return false;
872  }
873  $this->buildMapWorkImage();
874 
875  // determine ratios
876  $size = @getimagesize($this->getMapWorkCopyName());
877  $x_ratio = 1;
878  if ($size[0] > 0 && $this->getWidth() > 0)
879  {
880  $x_ratio = $this->getWidth() / $size[0];
881  }
882  $y_ratio = 1;
883  if ($size[1] > 0 && $this->getHeight() > 0)
884  {
885  $y_ratio = $this->getHeight() / $size[1];
886  }
887 
888  // draw map areas
889  for ($i=0; $i < count($this->mapareas); $i++)
890  {
891  if ( ((($i+1) == $a_area_nr) && !$a_exclude) ||
892  ((($i+1) != $a_area_nr) && $a_exclude) ||
893  ($a_area_nr == 0)
894  )
895  {
896  $area =& $this->mapareas[$i];
897  $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, true,
898  $x_ratio, $y_ratio);
899  }
900  }
901 
902  $this->saveMapWorkImage();
903 
904  return true;
905  }
906 
907 
914  function addAreaToMapWorkCopy($a_shape, $a_coords)
915  {
916  $this->buildMapWorkImage();
917 
918  // determine ratios
919  $size = @getimagesize($this->getMapWorkCopyName());
920  $x_ratio = 1;
921  if ($size[0] > 0 && $this->getWidth() > 0)
922  {
923  $x_ratio = $this->getWidth() / $size[0];
924  }
925  $y_ratio = 1;
926  if ($size[1] > 0 && $this->getHeight() > 0)
927  {
928  $y_ratio = $this->getHeight() / $size[1];
929  }
930 
931  // add new area to work image
932  $area = new ilMapArea();
933  $area->setShape($a_shape);
934  $area->setCoords($a_coords);
935  $area->draw($this->getMapWorkImage(), $this->color1, $this->color2, false,
936  $x_ratio, $y_ratio);
937 
938  $this->saveMapWorkImage();
939  }
940 
944  function outputMapWorkCopy()
945  {
946  if ($this->getMapWorkCopyType() != "")
947  {
948  header("Pragma: no-cache");
949  header("Expires: 0");
950  header("Content-type: image/".strtolower($this->getMapWorkCopyType()));
951  readfile($this->getMapWorkCopyName());
952  }
953  exit;
954  }
955 
959  function buildMapWorkImage()
960  {
961  $im_type = strtolower($this->getMapWorkCopyType());
962 
963  switch ($im_type)
964  {
965  case "gif":
966  $this->map_image = ImageCreateFromGIF($this->getMapWorkCopyName());
967  break;
968 
969  case "jpg":
970  $this->map_image = ImageCreateFromJPEG($this->getMapWorkCopyName());
971  break;
972 
973  case "png":
974  $this->map_image = ImageCreateFromPNG($this->getMapWorkCopyName());
975  break;
976  }
977 
978  // try to allocate black and white as color. if this is not possible, get the closest colors
979  if (imagecolorstotal($this->map_image) > 250)
980  {
981  $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
982  $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
983  }
984  else
985  {
986  $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
987  $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
988  }
989  }
990 
994  function saveMapWorkImage()
995  {
996  $im_type = strtolower($this->getMapWorkCopyType());
997 
998  // save image work-copy and free memory
999  switch ($im_type)
1000  {
1001  case "gif":
1002  ImageGIF($this->map_image, $this->getMapWorkCopyName());
1003  break;
1004 
1005  case "jpg":
1006  ImageJPEG($this->map_image, $this->getMapWorkCopyName());
1007  break;
1008 
1009  case "png":
1010  ImagePNG($this->map_image, $this->getMapWorkCopyName());
1011  break;
1012  }
1013 
1014  ImageDestroy($this->map_image);
1015  }
1016 
1020  function &getMapWorkImage()
1021  {
1022  return $this->map_image;
1023  }
1024 
1025 
1029  function getMapAreasXML($a_insert_inst = false, $a_inst = 0)
1030  {
1031  $xml = "";
1032 
1033  // build xml of map areas
1034  for ($i=0; $i < count($this->mapareas); $i++)
1035  {
1036  $area =& $this->mapareas[$i];
1037  $xml .= "<MapArea Shape=\"".$area->getShape()."\" Coords=\"".$area->getCoords()."\">";
1038  if ($area->getLinkType() == IL_INT_LINK)
1039  {
1040  $target_frame = $area->getTargetFrame();
1041 
1042  if ($area->getType() == "GlossaryItem" && $target_frame == "")
1043  {
1044  $target_frame = "Glossary";
1045  }
1046 
1047  $tf_str = ($target_frame == "")
1048  ? ""
1049  : "TargetFrame=\"".$target_frame."\"";
1050 
1051  $xml .= "<IntLink Target=\"".$area->getTarget($a_insert_inst, $a_inst)."\" Type=\"".
1052  $area->getType()."\" $tf_str>";
1053  $xml .= $area->getTitle();
1054  $xml .="</IntLink>";
1055  }
1056  else
1057  {
1058  $xml .= "<ExtLink Href=\"".str_replace("&", "&amp;",$area->getHref())."\" Title=\"".
1059  $area->getExtTitle()."\">";
1060  $xml .= $area->getTitle();
1061  $xml .="</ExtLink>";
1062  }
1063  $xml .= "</MapArea>";
1064  }
1065 
1066  return $xml;
1067  }
1068 
1069 
1075  function _resolveMapAreaLinks($a_mob_id)
1076  {
1077  global $ilDB;
1078 
1079 //echo "mediaItems::resolve<br>";
1080  // read media_object record
1081  $query = "SELECT * FROM media_item WHERE mob_id = ".$ilDB->quote($a_mob_id)." ".
1082  "ORDER BY nr";
1083  $item_set = $this->ilias->db->query($query);
1084  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
1085  {
1086  ilMapArea::_resolveIntLinks($item_rec["id"]);
1087  }
1088  }
1089 
1095  function _getMapAreasIntLinks($a_mob_id)
1096  {
1097  global $ilDB;
1098 
1099  // read media_items records
1100  $query = "SELECT * FROM media_item WHERE mob_id = ".
1101  $ilDB->quote($a_mob_id)." ORDER BY nr";
1102 
1103  $item_set = $this->ilias->db->query($query);
1104  $links = array();
1105  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
1106  {
1107  $map_links = ilMapArea::_getIntLinks($item_rec["id"]);
1108  foreach($map_links as $key => $map_link)
1109  {
1110  $links[$key] = $map_link;
1111  }
1112  }
1113  return $links;
1114  }
1115 
1120  {
1121  include_once("./Services/MediaObjects/classes/class.ilExternalMediaAnalyzer.php");
1123  $this->getLocation(), $this->getParameters());
1124  foreach ($par as $k => $v)
1125  {
1126  $this->setParameter($k, $v);
1127  }
1128  }
1129 }
1130 ?>