ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMapArea.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/Link/classes/class.ilInternalLink.php");
5 
6 define("IL_AREA_RECT", "Rect");
7 define("IL_AREA_CIRCLE", "Circle");
8 define("IL_AREA_POLY", "Poly");
9 define("IL_AREA_WHOLE_PICTURE", "WholePicture");
10 
11 define("IL_INT_LINK", "int");
12 define("IL_EXT_LINK", "ext");
13 define("IL_NO_LINK", "no");
14 
15 define("IL_LT_STRUCTURE", "StructureObject");
16 define("IL_LT_PAGE", "PageObject");
17 define("IL_LT_MEDIA", "MediaObject");
18 define("IL_LT_GLITEM", "GlossaryItem");
19 
20 define("IL_TF_MEDIA", "Media");
21 define("IL_TF_FAQ", "FAQ");
22 define("IL_TF_GLOSSARY", "Glossary");
23 define("IL_TF_NEW", "New");
24 
25 
36 class ilMapArea
37 {
38  const HL_NONE = "";
39  const HL_HOVER = "Hover";
40  const HL_ALWAYS = "Always";
41  const HLCL_ACCENTED = "";
42  const HLCL_LIGHT = "Light";
43  const HLCL_DARK = "Dark";
44 
45  var $item_id;
46  var $nr;
47  var $shape;
48  var $coords;
49  var $title;
50  var $linktype;
51  var $xl_title;
52  var $xl_href;
54  var $il_type;
56 
57 
64  function __construct($a_item_id = 0, $a_nr = 0)
65  {
66  $this->title = "";
67  if ($a_item_id !=0 && $a_nr != 0)
68  {
69  $this->setItemId($a_item_id);
70  $this->setNr($a_nr);
71  $this->read();
72  }
73  }
74 
78  function create()
79  {
80  global $ilDB;
81 
82  $q = "INSERT INTO map_area (item_id, nr, shape, ".
83  "coords, link_type, title, href, target, type, highlight_mode, highlight_class, target_frame) ".
84  " VALUES (".
85  $ilDB->quote($this->getItemId(), "integer").",".
86  $ilDB->quote($this->getNr(), "integer").",".
87  $ilDB->quote($this->getShape(), "text").",".
88  $ilDB->quote($this->getCoords(), "text").",".
89  $ilDB->quote($this->getLinkType(), "text").",".
90  $ilDB->quote($this->getTitle(), "text").",".
91  $ilDB->quote($this->getHref(), "text").",".
92  $ilDB->quote($this->getTarget(), "text").",".
93  $ilDB->quote($this->getType(), "text").",".
94  $ilDB->quote($this->getHighlightMode(), "text").",".
95  $ilDB->quote($this->getHighlightClass(), "text").",".
96  $ilDB->quote($this->getTargetFrame(), "text").")";
97  $ilDB->manipulate($q);
98  }
99 
107  static function _getMaxNr($a_item_id)
108  {
109  global $ilDB;
110 
111  $q = "SELECT max(nr) AS max_nr FROM map_area WHERE item_id = ".
112  $ilDB->quote($a_item_id, "integer");
113  $max_set = $ilDB->query($q);
114  $max_rec = $ilDB->fetchAssoc($max_set);
115 
116  return $max_rec["max_nr"];
117  }
118 
122  function read()
123  {
124  global $ilDB;
125 
126  $q = "SELECT * FROM map_area WHERE item_id = ".
127  $ilDB->quote($this->getItemId(), "integer").
128  " AND nr = ".$ilDB->quote($this->getNr(), "integer");
129  $area_set = $ilDB->query($q);
130  $area_rec = $ilDB->fetchAssoc($area_set);
131 
132  $this->setShape($area_rec["shape"]);
133 //echo $area_rec["Shape"];
134  $this->setNr($area_rec["nr"]);
135  $this->setCoords($area_rec["coords"]);
136  $this->setLinkType($area_rec["link_type"]);
137  $this->setTitle($area_rec["title"]);
138  $this->setHref($area_rec["href"]);
139  $this->setTarget($area_rec["target"]);
140  $this->setType($area_rec["type"]);
141  $this->setTargetFrame($area_rec["target_frame"]);
142  $this->setHighlightMode($area_rec["highlight_mode"]);
143  $this->setHighlightClass($area_rec["highlight_class"]);
144 
145  }
146 
150  function update()
151  {
152  global $ilDB;
153 
154  $q = "UPDATE map_area SET shape = ".$ilDB->quote($this->getShape(), "text").
155  ", coords = ".$ilDB->quote($this->getCoords(), "text").
156  ", link_type = ".$ilDB->quote($this->getLinkType(), "text").
157  ", title = ".$ilDB->quote($this->getTitle(), "text").
158  ", href = ".$ilDB->quote($this->getHref(), "text").
159  ", target = ".$ilDB->quote($this->getTarget(), "text").
160  ", type = ".$ilDB->quote($this->getType(), "text").
161  ", highlight_mode = ".$ilDB->quote($this->getHighlightMode(), "text").
162  ", highlight_class = ".$ilDB->quote($this->getHighlightClass(), "text").
163  ", target_frame = ".$ilDB->quote($this->getTargetFrame(), "text").
164  " WHERE item_id = ".$ilDB->quote($this->getItemId(), "integer").
165  " AND nr = ".$ilDB->quote($this->getNr(), "integer");
166  $ilDB->manipulate($q);
167  }
168 
172  static function _resolveIntLinks($a_item_id)
173  {
174  global $ilDB;
175 
176 //echo "maparea::resolve<br>";
177  $q = "SELECT * FROM map_area WHERE item_id = ".
178  $ilDB->quote($a_item_id, "integer");
179  $area_set = $ilDB->query($q);
180  while ($area_rec = $ilDB->fetchAssoc($area_set))
181  {
182  $target = $area_rec["target"];
183  $type = $area_rec["type"];
184  $item_id = $area_rec["item_id"];
185  $nr = $area_rec["nr"];
186 
187  if (($area_rec["link_type"] == IL_INT_LINK) && (!is_int(strpos($target, "__"))))
188  {
189  $new_target = ilInternalLink::_getIdForImportId($type, $target);
190  if ($new_target !== false)
191  {
192  $query = "UPDATE map_area SET ".
193  "target = ".$ilDB->quote($new_target, "text")." ".
194  "WHERE item_id = ".$ilDB->quote($item_id, "integer").
195  " AND nr = ".$ilDB->quote($nr, "integer");
196  $ilDB->manipulate($query);
197  }
198  }
199  }
200  }
201 
207  static function _getIntLinks($a_item_id)
208  {
209  global $ilDB;
210 
211  $q = "SELECT * FROM map_area WHERE item_id = ".
212  $ilDB->quote($a_item_id, "integer");
213  $area_set = $ilDB->query($q);
214 
215  $links = array();
216 
217  while ($area_rec = $ilDB->fetchAssoc($area_set))
218  {
219  $target = $area_rec["target"];
220  $type = $area_rec["type"];
221  $targetframe = $area_rec["target_frame"];
222 
223  if (($area_rec["link_type"] == IL_INT_LINK) && (is_int(strpos($target, "__"))))
224  {
225  $links[$target.":".$type.":".$targetframe] =
226  array("Target" => $target, "Type" => $type,
227  "TargetFrame" => $targetframe);
228  }
229  }
230  return $links;
231  }
232 
236  static function _getMobsForTarget($a_type, $a_target)
237  {
238  global $ilDB;
239 
240  $q = "SELECT * FROM map_area WHERE ".
241  " link_type = ".$ilDB->quote($a_type, "text").
242  " AND target = ".$ilDB->quote($a_target, "text");
243  $set = $ilDB->query($q);
244 
245  $mobs = array();
246  while($rec = $ilDB->fetchAssoc($set))
247  {
248  $mob_id = ilMediaItem::_lookupMobId($rec["item_id"]);
249  $mobs[$mob_id] = $mob_id;
250  }
251 
252  return $mobs;
253  }
254 
261  static function getAllHighlightModes()
262  {
263  global $lng;
264 
265  return array(
266  self::HL_NONE => $lng->txt("cont_none"),
267  self::HL_HOVER => $lng->txt("cont_hover"),
268  self::HL_ALWAYS => $lng->txt("cont_always")
269  );
270 
271  }
272 
273 
279  function setHighlightMode($a_val)
280  {
281  $this->highlight_mode = $a_val;
282  }
283 
289  function getHighlightMode()
290  {
291  return $this->highlight_mode;
292  }
293 
299  static function getAllHighlightClasses()
300  {
301  global $lng;
302 
303  return array(
304  self::HLCL_ACCENTED => $lng->txt("cont_accented"),
305  self::HLCL_LIGHT => $lng->txt("cont_light"),
306  self::HLCL_DARK => $lng->txt("cont_dark"),
307  );
308  }
309 
315  function setHighlightClass($a_val)
316  {
317  $this->highlight_class = $a_val;
318  }
319 
325  function getHighlightClass()
326  {
327  return $this->highlight_class;
328  }
329 
335  function setItemId($a_item_id)
336  {
337  $this->item_id = $a_item_id;
338  }
339 
345  function getItemId()
346  {
347  return $this->item_id;
348  }
349 
355  function setNr($a_nr)
356  {
357  $this->nr = $a_nr;
358  }
359 
365  function getNr()
366  {
367  return $this->nr;
368  }
369 
375  function setShape($a_shape)
376  {
377  $this->shape = $a_shape;
378  }
379 
385  function getShape()
386  {
387  return $this->shape;
388  }
389 
395  function setCoords($a_coords)
396  {
397  $this->coords = $a_coords;
398  }
399 
405  function getCoords()
406  {
407  return $this->coords;
408  }
409 
415  function setTitle($a_title)
416  {
417  $this->title = $a_title;
418  }
419 
425  function appendTitle($a_title_str)
426  {
427  $this->title.= $a_title_str;
428  }
429 
435  function getTitle()
436  {
437  return $this->title;
438  }
439 
445  function setLinkType($a_link_type)
446  {
447  $this->linktype = $a_link_type;
448  }
449 
455  function getLinkType()
456  {
457  return $this->linktype;
458  }
459 
465  function setHref($a_href)
466  {
467  $this->xl_href = $a_href;
468  }
469 
475  function getHref()
476  {
477  return $this->xl_href;
478  }
479 
485  function setExtTitle($a_title)
486  {
487  $this->xl_title = $a_title;
488  }
489 
495  function getExtTitle()
496  {
497  return $this->xl_title;
498  }
499 
505  function setTarget($a_target)
506  {
507  $this->il_target = $a_target;
508  }
509 
515  function getTarget($a_insert_inst = false)
516  {
518 
519  if ((substr($target, 0, 4) == "il__") && $a_insert_inst)
520  {
521  $target = "il_".IL_INST_ID."_".substr($target, 4, strlen($target) - 4);
522  }
523 
524  return $target;
525  }
526 
533  function setType($a_type)
534  {
535  $this->il_type = $a_type;
536  }
537 
543  function getType()
544  {
545  return $this->il_type;
546  }
547 
554  function setTargetFrame($a_target_frame)
555  {
556  $this->il_target_frame = $a_target_frame;
557  }
558 
565  function getTargetFrame()
566  {
567  return $this->il_target_frame;
568  }
569 
575  function draw(&$a_image, $a_col1, $a_col2, $a_close_poly = true,
576  $a_x_ratio = 1, $a_y_ratio = 1)
577  {
578  switch ($this->getShape())
579  {
580  case "Rect" :
581  $this->drawRect($a_image, $this->getCoords(), $a_col1, $a_col2,
582  $a_x_ratio, $a_y_ratio);
583  break;
584 
585  case "Circle" :
586  $this->drawCircle($a_image, $this->getCoords(), $a_col1, $a_col2,
587  $a_x_ratio, $a_y_ratio);
588  break;
589 
590  case "Poly" :
591  $this->drawPoly($a_image, $this->getCoords(), $a_col1, $a_col2, $a_close_poly,
592  $a_x_ratio, $a_y_ratio);
593  break;
594  }
595  }
596 
608  function drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
609  {
610  imageline($im, $x1+1, $y1, $x2+1, $y2, $c1);
611  imageline($im, $x1-1, $y1, $x2-1, $y2, $c1);
612  imageline($im, $x1, $y1+1, $x2, $y2+1, $c1);
613  imageline($im, $x1, $y1-1, $x2, $y2-1, $c1);
614  imageline($im, $x1, $y1, $x2, $y2, $c2);
615  }
616 
626  function drawRect(&$im,$coords,$c1,$c2,$a_x_ratio = 1, $a_y_ratio = 1)
627  {
628  $coord=explode(",", $coords);
629 
630  $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio,
631  $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
632  $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio,
633  $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
634  $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio,
635  $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
636  $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio,
637  $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
638  }
639 
640 
651  function drawPoly(&$im, $coords, $c1, $c2, $closed,$a_x_ratio = 1, $a_y_ratio = 1)
652  {
653  if ($closed)
654  {
655  $p = 0;
656  }
657  else
658  {
659  $p = 1;
660  }
661 
662  $anz = ilMapArea::countCoords($coords);
663 
664  if ($anz < (3 - $p))
665  {
666  return;
667  }
668 
669  $c = explode(",", $coords);
670 
671  for($i=0; $i<$anz-$p; $i++)
672  {
673  $this->drawLine($im, $c[$i*2] / $a_x_ratio, $c[$i*2+1] / $a_y_ratio,
674  $c[($i*2+2)%(2*$anz)] / $a_x_ratio,
675  $c[($i*2+3)%(2*$anz)] / $a_y_ratio, $c1, $c2);
676  }
677  }
678 
679 
689  function drawCircle(&$im, $coords, $c1, $c2,$a_x_ratio = 1, $a_y_ratio = 1)
690  {
691  $c = explode(",", $coords);
692  imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
693  ($c[2]+1)*2 / $a_x_ratio, ($c[2]+1)*2 / $a_y_ratio, 1, 360, $c1);
694  imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
695  ($c[2]-1)*2 / $a_x_ratio, ($c[2]-1)*2 / $a_y_ratio, 1, 360, $c1);
696  imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
697  $c[2]*2 / $a_x_ratio, $c[2]*2 / $a_y_ratio, 1, 360, $c2);
698  }
699 
706  static function countCoords($c)
707  {
708  if ($c == "")
709  {
710  return 0;
711  }
712  else
713  {
714  $coord_array = explode(",", $c);
715  return (count($coord_array) / 2);
716  }
717  }
718 
719 }
720 ?>
getTargetFrame()
get link target frame (internal link only)
update()
update map area
appendTitle($a_title_str)
append string to (tooltip) title of area
setHighlightClass($a_val)
Set highlight class.
setTarget($a_target)
set link target (internal link only)
setTargetFrame($a_target_frame)
set link target frame (internal link only)
drawCircle(&$im, $coords, $c1, $c2, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two colored circle
static getAllHighlightClasses()
Get all highlight classes.
getItemId()
get item id
setHref($a_href)
set hyper reference (external link only)
setCoords($a_coords)
set coords of area
getTitle()
get (tooltip) title
read()
read map area data into object (item id and nr must be set)
getHref()
get hyper reference url (external link only)
drawRect(&$im, $coords, $c1, $c2, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two color rectangle
setHighlightMode($a_val)
Set highlight mode.
__construct($a_item_id=0, $a_nr=0)
map area
getCoords()
get coords
static getAllHighlightModes()
Get all highlight modes.
const HLCL_LIGHT
$a_type
Definition: workflow.php:93
static _getIntLinks($a_item_id)
get all internal links of a media items map areas
getNr()
get area number
getHighlightMode()
Get highlight mode.
const IL_INT_LINK
$mobs
setType($a_type)
set link type (internal link only)
static _resolveIntLinks($a_item_id)
resolve internal links of an item id
create()
create persistent map area object in db
draw(&$a_image, $a_col1, $a_col2, $a_close_poly=true, $a_x_ratio=1, $a_y_ratio=1)
draw image to
setTitle($a_title)
set (tooltip)title of area
getExtTitle()
get link text (external link only)
getLinkType()
get link type
static _lookupMobId($a_med_id)
Lookup Mob ID.
static _getMobsForTarget($a_type, $a_target)
Get areas for a certain target.
const HLCL_ACCENTED
getShape()
get shape
Create styles array
The data for the language used.
drawPoly(&$im, $coords, $c1, $c2, $closed, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two color polygon
Class ilMapArea.
setShape($a_shape)
set shape (IL_AREA_RECT, IL_AREA_CIRCLE, IL_AREA_POLY, IL_AREA_WHOLE_PICTURE)
static _getMaxNr($a_item_id)
get maximum nr of media item (static)
global $lng
Definition: privfeed.php:17
global $ilDB
getHighlightClass()
Get highlight class.
setNr($a_nr)
set area number
getTarget($a_insert_inst=false)
get link target (internal link only)
setItemId($a_item_id)
set media item id
setLinkType($a_link_type)
set link type
static countCoords($c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,x3,y3,...")
setExtTitle($a_title)
set link text (external link only)
getType()
get link type (internal link only)
drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
draws an outlined two color line in an image