ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
41  protected $db;
42 
43  const HL_NONE = "";
44  const HL_HOVER = "Hover";
45  const HL_ALWAYS = "Always";
46  const HLCL_ACCENTED = "";
47  const HLCL_LIGHT = "Light";
48  const HLCL_DARK = "Dark";
49 
50  public $item_id;
51  public $nr;
52  public $shape;
53  public $coords;
54  public $title;
55  public $linktype;
56  public $xl_title;
57  public $xl_href;
58  public $il_target;
59  public $il_type;
61 
62 
69  public function __construct($a_item_id = 0, $a_nr = 0)
70  {
71  global $DIC;
72 
73  $this->db = $DIC->database();
74  $this->title = "";
75  if ($a_item_id != 0 && $a_nr != 0) {
76  $this->setItemId($a_item_id);
77  $this->setNr($a_nr);
78  $this->read();
79  }
80  }
81 
85  public function create()
86  {
87  $ilDB = $this->db;
88 
89  $q = "INSERT INTO map_area (item_id, nr, shape, " .
90  "coords, link_type, title, href, target, type, highlight_mode, highlight_class, target_frame) " .
91  " VALUES (" .
92  $ilDB->quote($this->getItemId(), "integer") . "," .
93  $ilDB->quote($this->getNr(), "integer") . "," .
94  $ilDB->quote($this->getShape(), "text") . "," .
95  $ilDB->quote($this->getCoords(), "text") . "," .
96  $ilDB->quote($this->getLinkType(), "text") . "," .
97  $ilDB->quote($this->getTitle(), "text") . "," .
98  $ilDB->quote($this->getHref(), "text") . "," .
99  $ilDB->quote($this->getTarget(), "text") . "," .
100  $ilDB->quote($this->getType(), "text") . "," .
101  $ilDB->quote($this->getHighlightMode(), "text") . "," .
102  $ilDB->quote($this->getHighlightClass(), "text") . "," .
103  $ilDB->quote($this->getTargetFrame(), "text") . ")";
104  $ilDB->manipulate($q);
105  }
106 
114  public static function _getMaxNr($a_item_id)
115  {
116  global $DIC;
117 
118  $ilDB = $DIC->database();
119 
120  $q = "SELECT max(nr) AS max_nr FROM map_area WHERE item_id = " .
121  $ilDB->quote($a_item_id, "integer");
122  $max_set = $ilDB->query($q);
123  $max_rec = $ilDB->fetchAssoc($max_set);
124 
125  return $max_rec["max_nr"];
126  }
127 
131  public function read()
132  {
133  $ilDB = $this->db;
134 
135  $q = "SELECT * FROM map_area WHERE item_id = " .
136  $ilDB->quote($this->getItemId(), "integer") .
137  " AND nr = " . $ilDB->quote($this->getNr(), "integer");
138  $area_set = $ilDB->query($q);
139  $area_rec = $ilDB->fetchAssoc($area_set);
140 
141  $this->setShape($area_rec["shape"]);
142  //echo $area_rec["Shape"];
143  $this->setNr($area_rec["nr"]);
144  $this->setCoords($area_rec["coords"]);
145  $this->setLinkType($area_rec["link_type"]);
146  $this->setTitle($area_rec["title"]);
147  $this->setHref($area_rec["href"]);
148  $this->setTarget($area_rec["target"]);
149  $this->setType($area_rec["type"]);
150  $this->setTargetFrame($area_rec["target_frame"]);
151  $this->setHighlightMode($area_rec["highlight_mode"]);
152  $this->setHighlightClass($area_rec["highlight_class"]);
153  }
154 
158  public function update()
159  {
160  $ilDB = $this->db;
161 
162  $q = "UPDATE map_area SET shape = " . $ilDB->quote($this->getShape(), "text") .
163  ", coords = " . $ilDB->quote($this->getCoords(), "text") .
164  ", link_type = " . $ilDB->quote($this->getLinkType(), "text") .
165  ", title = " . $ilDB->quote($this->getTitle(), "text") .
166  ", href = " . $ilDB->quote($this->getHref(), "text") .
167  ", target = " . $ilDB->quote($this->getTarget(), "text") .
168  ", type = " . $ilDB->quote($this->getType(), "text") .
169  ", highlight_mode = " . $ilDB->quote($this->getHighlightMode(), "text") .
170  ", highlight_class = " . $ilDB->quote($this->getHighlightClass(), "text") .
171  ", target_frame = " . $ilDB->quote($this->getTargetFrame(), "text") .
172  " WHERE item_id = " . $ilDB->quote($this->getItemId(), "integer") .
173  " AND nr = " . $ilDB->quote($this->getNr(), "integer");
174  $ilDB->manipulate($q);
175  }
176 
180  public static function _resolveIntLinks($a_item_id)
181  {
182  global $DIC;
183 
184  $ilDB = $DIC->database();
185 
186  //echo "maparea::resolve<br>";
187  $q = "SELECT * FROM map_area WHERE item_id = " .
188  $ilDB->quote($a_item_id, "integer");
189  $area_set = $ilDB->query($q);
190  while ($area_rec = $ilDB->fetchAssoc($area_set)) {
191  $target = $area_rec["target"];
192  $type = $area_rec["type"];
193  $item_id = $area_rec["item_id"];
194  $nr = $area_rec["nr"];
195 
196  if (($area_rec["link_type"] == IL_INT_LINK) && (!is_int(strpos($target, "__")))) {
198  if ($new_target !== false) {
199  $query = "UPDATE map_area SET " .
200  "target = " . $ilDB->quote($new_target, "text") . " " .
201  "WHERE item_id = " . $ilDB->quote($item_id, "integer") .
202  " AND nr = " . $ilDB->quote($nr, "integer");
203  $ilDB->manipulate($query);
204  }
205  }
206  }
207  }
208 
214  public static function _getIntLinks($a_item_id)
215  {
216  global $DIC;
217 
218  $ilDB = $DIC->database();
219 
220  $q = "SELECT * FROM map_area WHERE item_id = " .
221  $ilDB->quote($a_item_id, "integer");
222  $area_set = $ilDB->query($q);
223 
224  $links = array();
225 
226  while ($area_rec = $ilDB->fetchAssoc($area_set)) {
227  $target = $area_rec["target"];
228  $type = $area_rec["type"];
229  $targetframe = $area_rec["target_frame"];
230 
231  if (($area_rec["link_type"] == IL_INT_LINK) && (is_int(strpos($target, "__")))) {
232  $links[$target . ":" . $type . ":" . $targetframe] =
233  array("Target" => $target, "Type" => $type,
234  "TargetFrame" => $targetframe);
235  }
236  }
237  return $links;
238  }
239 
243  public static function _getMobsForTarget($a_type, $a_target)
244  {
245  global $DIC;
246 
247  $ilDB = $DIC->database();
248 
249  $q = "SELECT * FROM map_area WHERE " .
250  " link_type = " . $ilDB->quote($a_type, "text") .
251  " AND target = " . $ilDB->quote($a_target, "text");
252  $set = $ilDB->query($q);
253 
254  $mobs = array();
255  while ($rec = $ilDB->fetchAssoc($set)) {
256  $mob_id = ilMediaItem::_lookupMobId($rec["item_id"]);
257  $mobs[$mob_id] = $mob_id;
258  }
259 
260  return $mobs;
261  }
262 
269  public static function getAllHighlightModes()
270  {
271  global $DIC;
272 
273  $lng = $DIC->language();
274 
275  return array(
276  self::HL_NONE => $lng->txt("cont_none"),
277  self::HL_HOVER => $lng->txt("cont_hover"),
278  self::HL_ALWAYS => $lng->txt("cont_always")
279  );
280  }
281 
282 
288  public function setHighlightMode($a_val)
289  {
290  $this->highlight_mode = $a_val;
291  }
292 
298  public function getHighlightMode()
299  {
300  return $this->highlight_mode;
301  }
302 
308  public static function getAllHighlightClasses()
309  {
310  global $DIC;
311 
312  $lng = $DIC->language();
313 
314  return array(
315  self::HLCL_ACCENTED => $lng->txt("cont_accented"),
316  self::HLCL_LIGHT => $lng->txt("cont_light"),
317  self::HLCL_DARK => $lng->txt("cont_dark"),
318  );
319  }
320 
326  public function setHighlightClass($a_val)
327  {
328  $this->highlight_class = $a_val;
329  }
330 
336  public function getHighlightClass()
337  {
338  return $this->highlight_class;
339  }
340 
346  public function setItemId($a_item_id)
347  {
348  $this->item_id = $a_item_id;
349  }
350 
356  public function getItemId()
357  {
358  return $this->item_id;
359  }
360 
366  public function setNr($a_nr)
367  {
368  $this->nr = $a_nr;
369  }
370 
376  public function getNr()
377  {
378  return $this->nr;
379  }
380 
386  public function setShape($a_shape)
387  {
388  $this->shape = $a_shape;
389  }
390 
396  public function getShape()
397  {
398  return $this->shape;
399  }
400 
406  public function setCoords($a_coords)
407  {
408  $this->coords = $a_coords;
409  }
410 
416  public function getCoords()
417  {
418  return $this->coords;
419  }
420 
426  public function setTitle($a_title)
427  {
428  $this->title = $a_title;
429  }
430 
436  public function appendTitle($a_title_str)
437  {
438  $this->title .= $a_title_str;
439  }
440 
446  public function getTitle()
447  {
448  return $this->title;
449  }
450 
456  public function setLinkType($a_link_type)
457  {
458  $this->linktype = $a_link_type;
459  }
460 
466  public function getLinkType()
467  {
468  return $this->linktype;
469  }
470 
476  public function setHref($a_href)
477  {
478  $this->xl_href = $a_href;
479  }
480 
486  public function getHref()
487  {
488  return $this->xl_href;
489  }
490 
496  public function setExtTitle($a_title)
497  {
498  $this->xl_title = $a_title;
499  }
500 
506  public function getExtTitle()
507  {
508  return $this->xl_title;
509  }
510 
516  public function setTarget($a_target)
517  {
518  $this->il_target = $a_target;
519  }
520 
526  public function getTarget($a_insert_inst = false)
527  {
529 
530  if ((substr($target, 0, 4) == "il__") && $a_insert_inst) {
531  $target = "il_" . IL_INST_ID . "_" . substr($target, 4, strlen($target) - 4);
532  }
533 
534  return $target;
535  }
536 
543  public function setType($a_type)
544  {
545  $this->il_type = $a_type;
546  }
547 
553  public function getType()
554  {
555  return $this->il_type;
556  }
557 
564  public function setTargetFrame($a_target_frame)
565  {
566  $this->il_target_frame = $a_target_frame;
567  }
568 
575  public function getTargetFrame()
576  {
577  return $this->il_target_frame;
578  }
579 
585  public function draw(
586  &$a_image,
587  $a_col1,
588  $a_col2,
589  $a_close_poly = true,
590  $a_x_ratio = 1,
591  $a_y_ratio = 1
592  ) {
593  switch ($this->getShape()) {
594  case "Rect":
595  $this->drawRect(
596  $a_image,
597  $this->getCoords(),
598  $a_col1,
599  $a_col2,
600  $a_x_ratio,
601  $a_y_ratio
602  );
603  break;
604 
605  case "Circle":
606  $this->drawCircle(
607  $a_image,
608  $this->getCoords(),
609  $a_col1,
610  $a_col2,
611  $a_x_ratio,
612  $a_y_ratio
613  );
614  break;
615 
616  case "Poly":
617  $this->drawPoly(
618  $a_image,
619  $this->getCoords(),
620  $a_col1,
621  $a_col2,
622  $a_close_poly,
623  $a_x_ratio,
624  $a_y_ratio
625  );
626  break;
627  }
628  }
629 
641  public function drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
642  {
643  imageline($im, $x1 + 1, $y1, $x2 + 1, $y2, $c1);
644  imageline($im, $x1 - 1, $y1, $x2 - 1, $y2, $c1);
645  imageline($im, $x1, $y1 + 1, $x2, $y2 + 1, $c1);
646  imageline($im, $x1, $y1 - 1, $x2, $y2 - 1, $c1);
647  imageline($im, $x1, $y1, $x2, $y2, $c2);
648  }
649 
659  public function drawRect(&$im, $coords, $c1, $c2, $a_x_ratio = 1, $a_y_ratio = 1)
660  {
661  $coord = explode(",", $coords);
662 
663  $this->drawLine(
664  $im,
665  $coord[0] / $a_x_ratio,
666  $coord[1] / $a_y_ratio,
667  $coord[0] / $a_x_ratio,
668  $coord[3] / $a_y_ratio,
669  $c1,
670  $c2
671  );
672  $this->drawLine(
673  $im,
674  $coord[0] / $a_x_ratio,
675  $coord[3] / $a_y_ratio,
676  $coord[2] / $a_x_ratio,
677  $coord[3] / $a_y_ratio,
678  $c1,
679  $c2
680  );
681  $this->drawLine(
682  $im,
683  $coord[2] / $a_x_ratio,
684  $coord[3] / $a_y_ratio,
685  $coord[2] / $a_x_ratio,
686  $coord[1] / $a_y_ratio,
687  $c1,
688  $c2
689  );
690  $this->drawLine(
691  $im,
692  $coord[2] / $a_x_ratio,
693  $coord[1] / $a_y_ratio,
694  $coord[0] / $a_x_ratio,
695  $coord[1] / $a_y_ratio,
696  $c1,
697  $c2
698  );
699  }
700 
701 
712  public function drawPoly(&$im, $coords, $c1, $c2, $closed, $a_x_ratio = 1, $a_y_ratio = 1)
713  {
714  if ($closed) {
715  $p = 0;
716  } else {
717  $p = 1;
718  }
719 
721 
722  if ($anz < (3 - $p)) {
723  return;
724  }
725 
726  $c = explode(",", $coords);
727 
728  for ($i = 0; $i < $anz - $p; $i++) {
729  $this->drawLine(
730  $im,
731  $c[$i * 2] / $a_x_ratio,
732  $c[$i * 2 + 1] / $a_y_ratio,
733  $c[($i * 2 + 2) % (2 * $anz)] / $a_x_ratio,
734  $c[($i * 2 + 3) % (2 * $anz)] / $a_y_ratio,
735  $c1,
736  $c2
737  );
738  }
739  }
740 
741 
751  public function drawCircle(&$im, $coords, $c1, $c2, $a_x_ratio = 1, $a_y_ratio = 1)
752  {
753  $c = explode(",", $coords);
754  imagearc(
755  $im,
756  $c[0] / $a_x_ratio,
757  $c[1] / $a_y_ratio,
758  ($c[2] + 1) * 2 / $a_x_ratio,
759  ($c[2] + 1) * 2 / $a_y_ratio,
760  1,
761  360,
762  $c1
763  );
764  imagearc(
765  $im,
766  $c[0] / $a_x_ratio,
767  $c[1] / $a_y_ratio,
768  ($c[2] - 1) * 2 / $a_x_ratio,
769  ($c[2] - 1) * 2 / $a_y_ratio,
770  1,
771  360,
772  $c1
773  );
774  imagearc(
775  $im,
776  $c[0] / $a_x_ratio,
777  $c[1] / $a_y_ratio,
778  $c[2] * 2 / $a_x_ratio,
779  $c[2] * 2 / $a_y_ratio,
780  1,
781  360,
782  $c2
783  );
784  }
785 
792  public static function countCoords($c)
793  {
794  if ($c == "") {
795  return 0;
796  } else {
797  $coord_array = explode(",", $c);
798  return (count($coord_array) / 2);
799  }
800  }
801 }
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.
$type
global $DIC
Definition: saml.php:7
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:92
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)
$lng
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
$query
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
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 $ilDB
$i
Definition: disco.tpl.php:19
getHighlightClass()
Get highlight class.
setNr($a_nr)
set area number
getTarget($a_insert_inst=false)
get link target (internal link only)
$links
setItemId($a_item_id)
set media item id
setLinkType($a_link_type)
set link type
$target
Definition: test.php:19
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