ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMapArea.php
Go to the documentation of this file.
1<?php
2
19define("IL_AREA_RECT", "Rect");
20define("IL_AREA_CIRCLE", "Circle");
21define("IL_AREA_POLY", "Poly");
22define("IL_AREA_WHOLE_PICTURE", "WholePicture");
23
24define("IL_INT_LINK", "int");
25define("IL_EXT_LINK", "ext");
26define("IL_NO_LINK", "no");
27
28define("IL_LT_STRUCTURE", "StructureObject");
29define("IL_LT_PAGE", "PageObject");
30define("IL_LT_MEDIA", "MediaObject");
31define("IL_LT_GLITEM", "GlossaryItem");
32
33define("IL_TF_MEDIA", "Media");
34define("IL_TF_FAQ", "FAQ");
35define("IL_TF_GLOSSARY", "Glossary");
36define("IL_TF_NEW", "New");
37
38
47{
48 public const HL_NONE = "";
49 public const HL_HOVER = "Hover";
50 public const HL_ALWAYS = "Always";
51 public const HLCL_ACCENTED = "";
52 public const HLCL_LIGHT = "Light";
53 public const HLCL_DARK = "Dark";
54 protected string $highlight_mode = "";
55 protected string $highlight_class = "";
56
57 protected ilDBInterface $db;
58 public int $item_id = 0;
59 public int $nr = 0;
60 public string $shape = "";
61 public string $coords = "";
62 public string $title = "";
63 public string $linktype = "";
64 public string $xl_title = "";
65 public string $xl_href = "";
66 public string $il_target = "";
67 public string $il_type = "";
68 public string $il_target_frame = "";
69
74 public function __construct(
75 int $a_item_id = 0,
76 int $a_nr = 0
77 ) {
78 global $DIC;
79
80 $this->db = $DIC->database();
81 $this->title = "";
82 if ($a_item_id != 0 && $a_nr != 0) {
83 $this->setItemId($a_item_id);
84 $this->setNr($a_nr);
85 $this->read();
86 }
87 }
88
92 public function create(): void
93 {
95
96 $q = "INSERT INTO map_area (item_id, nr, shape, " .
97 "coords, link_type, title, href, target, type, highlight_mode, highlight_class, target_frame) " .
98 " VALUES (" .
99 $ilDB->quote($this->getItemId(), "integer") . "," .
100 $ilDB->quote($this->getNr(), "integer") . "," .
101 $ilDB->quote($this->getShape(), "text") . "," .
102 $ilDB->quote($this->getCoords(), "text") . "," .
103 $ilDB->quote($this->getLinkType(), "text") . "," .
104 $ilDB->quote($this->getTitle(), "text") . "," .
105 $ilDB->quote($this->getHref(), "text") . "," .
106 $ilDB->quote($this->getTarget(), "text") . "," .
107 $ilDB->quote($this->getType(), "text") . "," .
108 $ilDB->quote($this->getHighlightMode(), "text") . "," .
109 $ilDB->quote($this->getHighlightClass(), "text") . "," .
110 $ilDB->quote($this->getTargetFrame(), "text") . ")";
111 $ilDB->manipulate($q);
112 }
113
117 public static function _getMaxNr(
118 int $a_item_id
119 ): int {
120 global $DIC;
121
122 $ilDB = $DIC->database();
123
124 $q = "SELECT max(nr) AS max_nr FROM map_area WHERE item_id = " .
125 $ilDB->quote($a_item_id, "integer");
126 $max_set = $ilDB->query($q);
127 $max_rec = $ilDB->fetchAssoc($max_set);
128
129 return (int) $max_rec["max_nr"];
130 }
131
132 public function read(): void
133 {
134 $ilDB = $this->db;
135
136 $q = "SELECT * FROM map_area WHERE item_id = " .
137 $ilDB->quote($this->getItemId(), "integer") .
138 " AND nr = " . $ilDB->quote($this->getNr(), "integer");
139 $area_set = $ilDB->query($q);
140 $area_rec = $ilDB->fetchAssoc($area_set);
141 $this->setShape((string) $area_rec["shape"]);
142 //echo $area_rec["Shape"];
143 $this->setNr((int) $area_rec["nr"]);
144 $this->setCoords((string) $area_rec["coords"]);
145 $this->setLinkType((string) $area_rec["link_type"]);
146 $this->setTitle((string) $area_rec["title"]);
147 $this->setHref((string) $area_rec["href"]);
148 $this->setTarget((string) $area_rec["target"]);
149 $this->setType((string) $area_rec["type"]);
150 $this->setTargetFrame((string) $area_rec["target_frame"]);
151 $this->setHighlightMode((string) $area_rec["highlight_mode"]);
152 $this->setHighlightClass((string) $area_rec["highlight_class"]);
153 }
154
155 public function update(): void
156 {
157 $ilDB = $this->db;
158
159 $q = "UPDATE map_area SET shape = " . $ilDB->quote($this->getShape(), "text") .
160 ", coords = " . $ilDB->quote($this->getCoords(), "text") .
161 ", link_type = " . $ilDB->quote($this->getLinkType(), "text") .
162 ", title = " . $ilDB->quote($this->getTitle(), "text") .
163 ", href = " . $ilDB->quote($this->getHref(), "text") .
164 ", target = " . $ilDB->quote($this->getTarget(), "text") .
165 ", type = " . $ilDB->quote($this->getType(), "text") .
166 ", highlight_mode = " . $ilDB->quote($this->getHighlightMode(), "text") .
167 ", highlight_class = " . $ilDB->quote($this->getHighlightClass(), "text") .
168 ", target_frame = " . $ilDB->quote($this->getTargetFrame(), "text") .
169 " WHERE item_id = " . $ilDB->quote($this->getItemId(), "integer") .
170 " AND nr = " . $ilDB->quote($this->getNr(), "integer");
171 $ilDB->manipulate($q);
172 }
173
177 public static function _resolveIntLinks(
178 int $a_item_id
179 ): void {
180 global $DIC;
181
182 $ilDB = $DIC->database();
183
184 //echo "maparea::resolve<br>";
185 $q = "SELECT * FROM map_area WHERE item_id = " .
186 $ilDB->quote($a_item_id, "integer");
187 $area_set = $ilDB->query($q);
188 while ($area_rec = $ilDB->fetchAssoc($area_set)) {
189 $target = (string) $area_rec["target"];
190 $type = $area_rec["type"];
191 $item_id = $area_rec["item_id"];
192 $nr = $area_rec["nr"];
193
194 if (($area_rec["link_type"] == IL_INT_LINK) && (!is_int(strpos($target, "__")))) {
195 $new_target = ilInternalLink::_getIdForImportId($type, $target);
196 if ($new_target !== false) {
197 $query = "UPDATE map_area SET " .
198 "target = " . $ilDB->quote($new_target, "text") . " " .
199 "WHERE item_id = " . $ilDB->quote($item_id, "integer") .
200 " AND nr = " . $ilDB->quote($nr, "integer");
201 $ilDB->manipulate($query);
202 }
203 }
204 }
205 }
206
212 public static function _getIntLinks(
213 int $a_item_id
214 ): array {
215 global $DIC;
216
217 $ilDB = $DIC->database();
218
219 $q = "SELECT * FROM map_area WHERE item_id = " .
220 $ilDB->quote($a_item_id, "integer");
221 $area_set = $ilDB->query($q);
222
223 $links = array();
224
225 while ($area_rec = $ilDB->fetchAssoc($area_set)) {
226 $target = $area_rec["target"];
227 $type = $area_rec["type"];
228 $targetframe = $area_rec["target_frame"];
229
230 if (($area_rec["link_type"] == IL_INT_LINK) && (is_int(strpos($target, "__")))) {
231 $links[$target . ":" . $type . ":" . $targetframe] =
232 array("Target" => $target, "Type" => $type,
233 "TargetFrame" => $targetframe);
234 }
235 }
236 return $links;
237 }
238
242 public static function _getMobsForTarget(
243 string $a_type,
244 string $a_target
245 ): array {
246 global $DIC;
247
248 $ilDB = $DIC->database();
249
250 $q = "SELECT * FROM map_area WHERE " .
251 " link_type = " . $ilDB->quote($a_type, "text") .
252 " AND target = " . $ilDB->quote($a_target, "text");
253 $set = $ilDB->query($q);
254
255 $mobs = array();
256 while ($rec = $ilDB->fetchAssoc($set)) {
257 $mob_id = ilMediaItem::_lookupMobId($rec["item_id"]);
258 $mobs[$mob_id] = $mob_id;
259 }
260
261 return $mobs;
262 }
263
264 public static function getAllHighlightModes(): array
265 {
266 global $DIC;
267
268 $lng = $DIC->language();
269
270 return array(
271 self::HL_NONE => $lng->txt("cont_none"),
272 self::HL_HOVER => $lng->txt("cont_hover"),
273 self::HL_ALWAYS => $lng->txt("cont_always")
274 );
275 }
276
277 public function setHighlightMode(
278 string $a_val
279 ): void {
280 $this->highlight_mode = $a_val;
281 }
282
283 public function getHighlightMode(): string
284 {
285 return $this->highlight_mode;
286 }
287
288 public static function getAllHighlightClasses(): array
289 {
290 global $DIC;
291
292 $lng = $DIC->language();
293
294 return array(
295 self::HLCL_ACCENTED => $lng->txt("cont_accented"),
296 self::HLCL_LIGHT => $lng->txt("cont_light"),
297 self::HLCL_DARK => $lng->txt("cont_dark"),
298 );
299 }
300
301 public function setHighlightClass(string $a_val): void
302 {
303 $this->highlight_class = $a_val;
304 }
305
306 public function getHighlightClass(): string
307 {
308 return $this->highlight_class;
309 }
310
311 public function setItemId(int $a_item_id): void
312 {
313 $this->item_id = $a_item_id;
314 }
315
316 public function getItemId(): int
317 {
318 return $this->item_id;
319 }
320
321 public function setNr(int $a_nr): void
322 {
323 $this->nr = $a_nr;
324 }
325
326 public function getNr(): int
327 {
328 return $this->nr;
329 }
330
334 public function setShape(string $a_shape): void
335 {
336 $this->shape = $a_shape;
337 }
338
339 public function getShape(): string
340 {
341 return $this->shape;
342 }
343
348 public function setCoords(string $a_coords): void
349 {
350 $this->coords = $a_coords;
351 }
352
353 public function getCoords(): string
354 {
355 return $this->coords;
356 }
357
361 public function setTitle(string $a_title): void
362 {
363 $this->title = $a_title;
364 }
365
366 public function appendTitle(string $a_title_str): void
367 {
368 $this->title .= $a_title_str;
369 }
370
371 public function getTitle(): string
372 {
373 return $this->title;
374 }
375
380 public function setLinkType(string $a_link_type): void
381 {
382 $this->linktype = $a_link_type;
383 }
384
385 public function getLinkType(): string
386 {
387 return $this->linktype;
388 }
389
393 public function setHref(string $a_href): void
394 {
395 $this->xl_href = $a_href;
396 }
397
398 public function getHref(): string
399 {
400 return $this->xl_href;
401 }
402
407 public function setExtTitle(string $a_title): void
408 {
409 $this->xl_title = $a_title;
410 }
411
412 public function getExtTitle(): string
413 {
414 return $this->xl_title;
415 }
416
421 public function setTarget(string $a_target): void
422 {
423 $this->il_target = $a_target;
424 }
425
429 public function getTarget(bool $a_insert_inst = false): string
430 {
431 $target = $this->il_target;
432
433 if ((substr($target, 0, 4) == "il__") && $a_insert_inst) {
434 $target = "il_" . IL_INST_ID . "_" . substr($target, 4, strlen($target) - 4);
435 }
436
437 return $target;
438 }
439
445 public function setType(string $a_type): void
446 {
447 $this->il_type = $a_type;
448 }
449
450 public function getType(): string
451 {
452 return $this->il_type;
453 }
454
461 public function setTargetFrame(string $a_target_frame): void
462 {
463 $this->il_target_frame = $a_target_frame;
464 }
465
466 public function getTargetFrame(): string
467 {
468 return $this->il_target_frame;
469 }
470
474 public function draw(
475 $a_image,
476 int $a_col1,
477 int $a_col2,
478 bool $a_close_poly = true,
479 float $a_x_ratio = 1,
480 float $a_y_ratio = 1
481 ): void {
482 switch ($this->getShape()) {
483 case "Rect":
484 $this->drawRect(
485 $a_image,
486 $this->getCoords(),
487 $a_col1,
488 $a_col2,
489 $a_x_ratio,
490 $a_y_ratio
491 );
492 break;
493
494 case "Circle":
495 $this->drawCircle(
496 $a_image,
497 $this->getCoords(),
498 $a_col1,
499 $a_col2,
500 $a_x_ratio,
501 $a_y_ratio
502 );
503 break;
504
505 case "Poly":
506 $this->drawPoly(
507 $a_image,
508 $this->getCoords(),
509 $a_col1,
510 $a_col2,
511 $a_close_poly,
512 $a_x_ratio,
513 $a_y_ratio
514 );
515 break;
516 }
517 }
518
529 public function drawLine(
530 $im,
531 int $x1,
532 int $y1,
533 int $x2,
534 int $y2,
535 int $c1,
536 int $c2
537 ): void {
538 imageline($im, $x1 + 1, $y1, $x2 + 1, $y2, $c1);
539 imageline($im, $x1 - 1, $y1, $x2 - 1, $y2, $c1);
540 imageline($im, $x1, $y1 + 1, $x2, $y2 + 1, $c1);
541 imageline($im, $x1, $y1 - 1, $x2, $y2 - 1, $c1);
542 imageline($im, $x1, $y1, $x2, $y2, $c2);
543 }
544
553 public function drawRect(
554 $im,
555 string $coords,
556 int $c1,
557 int $c2,
558 float $a_x_ratio = 1,
559 float $a_y_ratio = 1
560 ): void {
561 $coord = explode(",", $coords);
562
563 $this->drawLine(
564 $im,
565 $coord[0] / $a_x_ratio,
566 $coord[1] / $a_y_ratio,
567 $coord[0] / $a_x_ratio,
568 $coord[3] / $a_y_ratio,
569 $c1,
570 $c2
571 );
572 $this->drawLine(
573 $im,
574 $coord[0] / $a_x_ratio,
575 $coord[3] / $a_y_ratio,
576 $coord[2] / $a_x_ratio,
577 $coord[3] / $a_y_ratio,
578 $c1,
579 $c2
580 );
581 $this->drawLine(
582 $im,
583 $coord[2] / $a_x_ratio,
584 $coord[3] / $a_y_ratio,
585 $coord[2] / $a_x_ratio,
586 $coord[1] / $a_y_ratio,
587 $c1,
588 $c2
589 );
590 $this->drawLine(
591 $im,
592 $coord[2] / $a_x_ratio,
593 $coord[1] / $a_y_ratio,
594 $coord[0] / $a_x_ratio,
595 $coord[1] / $a_y_ratio,
596 $c1,
597 $c2
598 );
599 }
600
601
611 public function drawPoly(
612 $im,
613 string $coords,
614 int $c1,
615 int $c2,
616 bool $closed,
617 float $a_x_ratio = 1,
618 float $a_y_ratio = 1
619 ): void {
620 if ($closed) {
621 $p = 0;
622 } else {
623 $p = 1;
624 }
625
626 $anz = ilMapArea::countCoords($coords);
627
628 if ($anz < (3 - $p)) {
629 return;
630 }
631
632 $c = explode(",", $coords);
633
634 for ($i = 0; $i < $anz - $p; $i++) {
635 $this->drawLine(
636 $im,
637 $c[$i * 2] / $a_x_ratio,
638 $c[$i * 2 + 1] / $a_y_ratio,
639 $c[($i * 2 + 2) % (2 * $anz)] / $a_x_ratio,
640 $c[($i * 2 + 3) % (2 * $anz)] / $a_y_ratio,
641 $c1,
642 $c2
643 );
644 }
645 }
646
647
656 public function drawCircle(
657 $im,
658 string $coords,
659 int $c1,
660 int $c2,
661 float $a_x_ratio = 1,
662 float $a_y_ratio = 1
663 ): void {
664 $c = explode(",", $coords);
665 imagearc(
666 $im,
667 $c[0] / $a_x_ratio,
668 $c[1] / $a_y_ratio,
669 ($c[2] + 1) * 2 / $a_x_ratio,
670 ($c[2] + 1) * 2 / $a_y_ratio,
671 1,
672 360,
673 $c1
674 );
675 imagearc(
676 $im,
677 $c[0] / $a_x_ratio,
678 $c[1] / $a_y_ratio,
679 ($c[2] - 1) * 2 / $a_x_ratio,
680 ($c[2] - 1) * 2 / $a_y_ratio,
681 1,
682 360,
683 $c1
684 );
685 imagearc(
686 $im,
687 $c[0] / $a_x_ratio,
688 $c[1] / $a_y_ratio,
689 $c[2] * 2 / $a_x_ratio,
690 $c[2] * 2 / $a_y_ratio,
691 1,
692 360,
693 $c2
694 );
695 }
696
702 public static function countCoords(string $c): float
703 {
704 if ($c == "") {
705 return 0;
706 } else {
707 $coord_array = explode(",", $c);
708 return (count($coord_array) / 2);
709 }
710 }
711}
const IL_INT_LINK
Class ilMapArea.
setItemId(int $a_item_id)
drawPoly( $im, string $coords, int $c1, int $c2, bool $closed, float $a_x_ratio=1, float $a_y_ratio=1)
draws an outlined two color polygon
string $highlight_class
const HLCL_LIGHT
static getAllHighlightClasses()
setHref(string $a_href)
set hyper reference (external link only)
string $highlight_mode
drawCircle( $im, string $coords, int $c1, int $c2, float $a_x_ratio=1, float $a_y_ratio=1)
draws an outlined two colored circle
draw( $a_image, int $a_col1, int $a_col2, bool $a_close_poly=true, float $a_x_ratio=1, float $a_y_ratio=1)
setShape(string $a_shape)
set shape (IL_AREA_RECT, IL_AREA_CIRCLE, IL_AREA_POLY, IL_AREA_WHOLE_PICTURE)
string $il_target_frame
static _resolveIntLinks(int $a_item_id)
resolve internal links of an item id
string $xl_title
string $il_type
static _getMaxNr(int $a_item_id)
get maximum nr of media item (static)
setCoords(string $a_coords)
set coords of area
ilDBInterface $db
create()
create persistent map area object in db
string $il_target
const HLCL_ACCENTED
__construct(int $a_item_id=0, int $a_nr=0)
setTitle(string $a_title)
set (tooltip)title of area
string $xl_href
getTarget(bool $a_insert_inst=false)
get link target (internal link only)
drawRect( $im, string $coords, int $c1, int $c2, float $a_x_ratio=1, float $a_y_ratio=1)
draws an outlined two color rectangle
string $linktype
static _getIntLinks(int $a_item_id)
get all internal links of a media items map areas
setExtTitle(string $a_title)
set link text (external link only)
static _getMobsForTarget(string $a_type, string $a_target)
Get areas for a certain target.
appendTitle(string $a_title_str)
setType(string $a_type)
set link type (internal link only)
static getAllHighlightModes()
drawLine( $im, int $x1, int $y1, int $x2, int $y2, int $c1, int $c2)
draws an outlined two color line in an image
setTarget(string $a_target)
set link target (internal link only)
string $coords
setHighlightClass(string $a_val)
setHighlightMode(string $a_val)
setTargetFrame(string $a_target_frame)
set link target frame (internal link only)
static countCoords(string $c)
count the number of coordinates (x,y) in a coordinate string (format: "x1,y1,x2,y2,...
setNr(int $a_nr)
setLinkType(string $a_link_type)
set link type
static _lookupMobId(int $a_med_id)
const IL_INST_ID
Definition: constants.php:40
$c
Definition: deliver.php:25
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23