ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_once("./Services/Link/classes/class.ilInternalLink.php");
5
6define("IL_AREA_RECT", "Rect");
7define("IL_AREA_CIRCLE", "Circle");
8define("IL_AREA_POLY", "Poly");
9define("IL_AREA_WHOLE_PICTURE", "WholePicture");
10
11define("IL_INT_LINK", "int");
12define("IL_EXT_LINK", "ext");
13define("IL_NO_LINK", "no");
14
15define("IL_LT_STRUCTURE", "StructureObject");
16define("IL_LT_PAGE", "PageObject");
17define("IL_LT_MEDIA", "MediaObject");
18define("IL_LT_GLITEM", "GlossaryItem");
19
20define("IL_TF_MEDIA", "Media");
21define("IL_TF_FAQ", "FAQ");
22define("IL_TF_GLOSSARY", "Glossary");
23define("IL_TF_NEW", "New");
24
25
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
46 var $nr;
47 var $shape;
49 var $title;
56
57
64 function ilMapArea($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 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 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 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
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
290 {
291 return $this->highlight_mode;
292 }
293
301 {
302 global $lng;
303
304 return array(
305 self::HLCL_ACCENTED => $lng->txt("cont_accented"),
306 self::HLCL_LIGHT => $lng->txt("cont_light"),
307 self::HLCL_DARK => $lng->txt("cont_dark"),
308 );
309 }
310
316 function setHighlightClass($a_val)
317 {
318 $this->highlight_class = $a_val;
319 }
320
327 {
328 return $this->highlight_class;
329 }
330
336 function setItemId($a_item_id)
337 {
338 $this->item_id = $a_item_id;
339 }
340
346 function getItemId()
347 {
348 return $this->item_id;
349 }
350
356 function setNr($a_nr)
357 {
358 $this->nr = $a_nr;
359 }
360
366 function getNr()
367 {
368 return $this->nr;
369 }
370
376 function setShape($a_shape)
377 {
378 $this->shape = $a_shape;
379 }
380
386 function getShape()
387 {
388 return $this->shape;
389 }
390
396 function setCoords($a_coords)
397 {
398 $this->coords = $a_coords;
399 }
400
406 function getCoords()
407 {
408 return $this->coords;
409 }
410
416 function setTitle($a_title)
417 {
418 $this->title = $a_title;
419 }
420
426 function appendTitle($a_title_str)
427 {
428 $this->title.= $a_title_str;
429 }
430
436 function getTitle()
437 {
438 return $this->title;
439 }
440
446 function setLinkType($a_link_type)
447 {
448 $this->linktype = $a_link_type;
449 }
450
456 function getLinkType()
457 {
458 return $this->linktype;
459 }
460
466 function setHref($a_href)
467 {
468 $this->xl_href = $a_href;
469 }
470
476 function getHref()
477 {
478 return $this->xl_href;
479 }
480
486 function setExtTitle($a_title)
487 {
488 $this->xl_title = $a_title;
489 }
490
496 function getExtTitle()
497 {
498 return $this->xl_title;
499 }
500
506 function setTarget($a_target)
507 {
508 $this->il_target = $a_target;
509 }
510
516 function getTarget($a_insert_inst = false)
517 {
518 $target = $this->il_target;
519
520 if ((substr($target, 0, 4) == "il__") && $a_insert_inst)
521 {
522 $target = "il_".IL_INST_ID."_".substr($target, 4, strlen($target) - 4);
523 }
524
525 return $target;
526 }
527
534 function setType($a_type)
535 {
536 $this->il_type = $a_type;
537 }
538
544 function getType()
545 {
546 return $this->il_type;
547 }
548
555 function setTargetFrame($a_target_frame)
556 {
557 $this->il_target_frame = $a_target_frame;
558 }
559
566 function getTargetFrame()
567 {
569 }
570
576 function draw(&$a_image, $a_col1, $a_col2, $a_close_poly = true,
577 $a_x_ratio = 1, $a_y_ratio = 1)
578 {
579 switch ($this->getShape())
580 {
581 case "Rect" :
582 $this->drawRect($a_image, $this->getCoords(), $a_col1, $a_col2,
583 $a_x_ratio, $a_y_ratio);
584 break;
585
586 case "Circle" :
587 $this->drawCircle($a_image, $this->getCoords(), $a_col1, $a_col2,
588 $a_x_ratio, $a_y_ratio);
589 break;
590
591 case "Poly" :
592 $this->drawPoly($a_image, $this->getCoords(), $a_col1, $a_col2, $a_close_poly,
593 $a_x_ratio, $a_y_ratio);
594 break;
595 }
596 }
597
609 function drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
610 {
611 imageline($im, $x1+1, $y1, $x2+1, $y2, $c1);
612 imageline($im, $x1-1, $y1, $x2-1, $y2, $c1);
613 imageline($im, $x1, $y1+1, $x2, $y2+1, $c1);
614 imageline($im, $x1, $y1-1, $x2, $y2-1, $c1);
615 imageline($im, $x1, $y1, $x2, $y2, $c2);
616 }
617
627 function drawRect(&$im,$coords,$c1,$c2,$a_x_ratio = 1, $a_y_ratio = 1)
628 {
629 $coord=explode(",", $coords);
630
631 $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio,
632 $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
633 $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio,
634 $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
635 $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio,
636 $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
637 $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio,
638 $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
639 }
640
641
652 function drawPoly(&$im, $coords, $c1, $c2, $closed,$a_x_ratio = 1, $a_y_ratio = 1)
653 {
654 if ($closed)
655 {
656 $p = 0;
657 }
658 else
659 {
660 $p = 1;
661 }
662
664
665 if ($anz < (3 - $p))
666 {
667 return;
668 }
669
670 $c = explode(",", $coords);
671
672 for($i=0; $i<$anz-$p; $i++)
673 {
674 $this->drawLine($im, $c[$i*2] / $a_x_ratio, $c[$i*2+1] / $a_y_ratio,
675 $c[($i*2+2)%(2*$anz)] / $a_x_ratio,
676 $c[($i*2+3)%(2*$anz)] / $a_y_ratio, $c1, $c2);
677 }
678 }
679
680
690 function drawCircle(&$im, $coords, $c1, $c2,$a_x_ratio = 1, $a_y_ratio = 1)
691 {
692 $c = explode(",", $coords);
693 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
694 ($c[2]+1)*2 / $a_x_ratio, ($c[2]+1)*2 / $a_y_ratio, 1, 360, $c1);
695 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
696 ($c[2]-1)*2 / $a_x_ratio, ($c[2]-1)*2 / $a_y_ratio, 1, 360, $c1);
697 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
698 $c[2]*2 / $a_x_ratio, $c[2]*2 / $a_y_ratio, 1, 360, $c2);
699 }
700
706 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?>
const IL_INT_LINK
Class ilMapArea.
countCoords($c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,...
const HLCL_LIGHT
getShape()
get shape
setHighlightClass($a_val)
Set highlight class.
setTarget($a_target)
set link target (internal link only)
_resolveIntLinks($a_item_id)
resolve internal links of an item id
draw(&$a_image, $a_col1, $a_col2, $a_close_poly=true, $a_x_ratio=1, $a_y_ratio=1)
draw image to
getTitle()
get (tooltip) title
getCoords()
get coords
setExtTitle($a_title)
set link text (external link only)
setTargetFrame($a_target_frame)
set link target frame (internal link only)
setHighlightMode($a_val)
Set highlight mode.
getTarget($a_insert_inst=false)
get link target (internal link only)
getHref()
get hyper reference url (external link only)
getAllHighlightModes()
Get all highlight modes.
getHighlightMode()
Get highlight mode.
drawRect(&$im, $coords, $c1, $c2, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two color rectangle
getLinkType()
get link type
setTitle($a_title)
set (tooltip)title of area
setHref($a_href)
set hyper reference (external link only)
getTargetFrame()
get link target frame (internal link only)
create()
create persistent map area object in db
setNr($a_nr)
set area number
const HLCL_ACCENTED
static _getMobsForTarget($a_type, $a_target)
Get areas for a certain target.
appendTitle($a_title_str)
append string to (tooltip) title of area
drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
draws an outlined two color line in an image
getItemId()
get item id
_getIntLinks($a_item_id)
get all internal links of a media items map areas
getAllHighlightClasses()
Get all highlight classes.
ilMapArea($a_item_id=0, $a_nr=0)
map area
setShape($a_shape)
set shape (IL_AREA_RECT, IL_AREA_CIRCLE, IL_AREA_POLY, IL_AREA_WHOLE_PICTURE)
update()
update map area
_getMaxNr($a_item_id)
get maximum nr of media item (static)
setItemId($a_item_id)
set media item id
read()
read map area data into object (item id and nr must be set)
setType($a_type)
set link type (internal link only)
drawCircle(&$im, $coords, $c1, $c2, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two colored circle
getType()
get link type (internal link only)
setLinkType($a_link_type)
set link type
getNr()
get area number
setCoords($a_coords)
set coords of area
getExtTitle()
get link text (external link only)
drawPoly(&$im, $coords, $c1, $c2, $closed, $a_x_ratio=1, $a_y_ratio=1)
draws an outlined two color polygon
getHighlightClass()
Get highlight class.
static _lookupMobId($a_med_id)
Lookup Mob ID.
global $lng
Definition: privfeed.php:40
global $ilDB
$mobs