ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCMap.php
Go to the documentation of this file.
1<?php
2
25{
26 public function init(): void
27 {
28 $this->setType("map");
29 }
30
31 public function create(
32 ilPageObject $a_pg_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ): void {
37 $a_hier_id,
38 $a_pc_id,
39 "Map",
40 ["Latitude" => "0","Longitude" => "0","Zoom" => "3"]
41 );
42 }
43
44 public function setLatitude(?float $a_lat = null): void
45 {
46 if (!is_null($a_lat)) {
47 $this->getChildNode()->setAttribute("Latitude", (string) $a_lat);
48 } else {
49 if ($this->getChildNode()->hasAttribute("Latitude")) {
50 $this->getChildNode()->removeAttribute("Latitude");
51 }
52 }
53 }
54
55 public function getLatitude(): ?float
56 {
57 if (is_object($this->getChildNode())) {
58 return (float) $this->getChildNode()->getAttribute("Latitude");
59 }
60 return null;
61 }
62
63 public function setLongitude(?float $a_long = null): void
64 {
65 if (!is_null($a_long)) {
66 $this->getChildNode()->setAttribute("Longitude", $a_long);
67 } else {
68 if ($this->getChildNode()->hasAttribute("Longitude")) {
69 $this->getChildNode()->removeAttribute("Longitude");
70 }
71 }
72 }
73
74 public function getLongitude(): ?float
75 {
76 if (is_object($this->getChildNode())) {
77 return (float) $this->getChildNode()->getAttribute("Longitude");
78 }
79 return null;
80 }
81
82 public function setZoom(?int $a_zoom): void
83 {
84 //if (!empty($a_zoom)) {
85 $this->getChildNode()->setAttribute("Zoom", (int) $a_zoom);
86 /*} else {
87 if ($this->map_node->has_attribute("Zoom")) {
88 $this->map_node->remove_attribute("Zoom");
89 }
90 }*/
91 }
92
93 public function getZoom(): ?int
94 {
95 if (is_object($this->getChildNode())) {
96 return (int) $this->getChildNode()->getAttribute("Zoom");
97 }
98 return null;
99 }
100
101 public function setLayout(
102 ?int $a_width,
103 ?int $a_height,
104 string $a_horizontal_align
105 ): void {
106 if (is_object($this->getChildNode())) {
107 $this->dom_util->setFirstOptionalElement(
108 $this->getChildNode(),
109 "Layout",
110 array("MapCaption"),
111 "",
112 array("Width" => (string) $a_width,
113 "Height" => (string) $a_height, "HorizontalAlign" => $a_horizontal_align)
114 );
115 }
116 }
117
118 public function getWidth(): ?int
119 {
120 if (is_object($this->getChildNode())) {
121 foreach ($this->getChildNode()->childNodes as $child) {
122 if ($child->nodeName == "Layout") {
123 $w = $child->getAttribute("Width")
124 ? (int) $child->getAttribute("Width")
125 : null;
126 return $w;
127 }
128 }
129 }
130 return null;
131 }
132
133 public function getHeight(): ?int
134 {
135 if (is_object($this->getChildNode())) {
136 foreach ($this->getChildNode()->childNodes as $child) {
137 if ($child->nodeName == "Layout") {
138 $h = $child->getAttribute("Height")
139 ? (int) $child->getAttribute("Height")
140 : null;
141 return $h;
142 }
143 }
144 }
145 return null;
146 }
147
148 public function getHorizontalAlign(): string
149 {
150 if (is_object($this->getChildNode())) {
151 foreach ($this->getChildNode()->childNodes as $child) {
152 if ($child->nodeName == "Layout") {
153 return $child->getAttribute("HorizontalAlign");
154 }
155 }
156 }
157 return "";
158 }
159
160 public function setCaption(string $a_caption): void
161 {
162 if (is_object($this->getChildNode())) {
163 $this->dom_util->setFirstOptionalElement(
164 $this->getChildNode(),
165 "MapCaption",
166 array(),
167 $a_caption,
168 array()
169 );
170 }
171 }
172
173 public function getCaption(): string
174 {
175 if (is_object($this->getChildNode())) {
176 foreach ($this->getChildNode()->childNodes as $child) {
177 if ($child->nodeName == "MapCaption") {
178 return $this->dom_util->getContent($child);
179 }
180 }
181 }
182 return "";
183 }
184
185 public static function handleCaptionInput(
186 string $a_text
187 ): string {
188 $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
189 $a_text = str_replace(chr(13), "<br />", $a_text);
190 $a_text = str_replace(chr(10), "<br />", $a_text);
191
192 return $a_text;
193 }
194
195 public static function handleCaptionFormOutput(
196 string $a_text
197 ): string {
198 $a_text = str_replace("<br />", "\n", $a_text);
199 $a_text = str_replace("<br/>", "\n", $a_text);
200
201 return $a_text;
202 }
203
205 string $a_output,
206 string $a_mode,
207 bool $a_abstract_only = false
208 ): string {
209 $end = 0;
210 $start = strpos($a_output, "[[[[[Map;");
211 if (is_int($start)) {
212 $end = strpos($a_output, "]]]]]", $start);
213 }
214 $i = 1;
215 while ($end > 0) {
216 $param = substr($a_output, $start + 9, $end - $start - 9);
217
218 $param = explode(";", $param);
219 if (is_numeric($param[0]) && is_numeric($param[1]) && is_numeric($param[2])) {
220 $map_gui = ilMapUtil::getMapGUI();
221 $map_gui->setMapId("map_" . $i)
222 ->setLatitude($param[0])
223 ->setLongitude($param[1])
224 ->setZoom($param[2])
225 ->setWidth($param[3] . "px")
226 ->setHeight($param[4] . "px")
227 ->setEnableTypeControl(true)
228 ->setEnableNavigationControl(true)
229 ->setEnableCentralMarker(true);
230 $h2 = substr($a_output, 0, $start) .
231 $map_gui->getHtml() .
232 substr($a_output, $end + 5);
233 $a_output = $h2;
234 $i++;
235 }
236 $start = strpos($a_output, "[[[[[Map;", $start + 5);
237 $end = 0;
238 if (is_int($start)) {
239 $end = strpos($a_output, "]]]]]", $start);
240 }
241 }
242
243 return $a_output;
244 }
245}
static getMapGUI()
Get an instance of the GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLayout(?int $a_width, ?int $a_height, string $a_horizontal_align)
setLongitude(?float $a_long=null)
static handleCaptionInput(string $a_text)
getHorizontalAlign()
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
static handleCaptionFormOutput(string $a_text)
setZoom(?int $a_zoom)
setLatitude(?float $a_lat=null)
setCaption(string $a_caption)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
init()
Init object.
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
if(!file_exists('../ilias.ini.php'))
$param
Definition: xapitoken.php:46