ILIAS  release_8 Revision v8.24
class.ilPCMap.php
Go to the documentation of this file.
1<?php
2
25{
27
28 public function init(): void
29 {
30 $this->setType("map");
31 }
32
33 public function setNode(php4DOMElement $a_node): void
34 {
35 parent::setNode($a_node); // this is the PageContent node
36 $this->map_node = $a_node->first_child(); // this is the Map node
37 }
38
39 public function create(
40 ilPageObject $a_pg_obj,
41 string $a_hier_id,
42 string $a_pc_id = ""
43 ): void {
44 $this->node = $this->createPageContentNode();
45
46 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
47 $this->map_node = $this->dom->create_element("Map");
48 $this->map_node = $this->node->append_child($this->map_node);
49 $this->map_node->set_attribute("Latitude", "0");
50 $this->map_node->set_attribute("Longitude", "0");
51 $this->map_node->set_attribute("Zoom", "3");
52 }
53
54 public function setLatitude(?float $a_lat = null): void
55 {
56 if (!is_null($a_lat)) {
57 $this->map_node->set_attribute("Latitude", (string) $a_lat);
58 } else {
59 if ($this->map_node->has_attribute("Latitude")) {
60 $this->map_node->remove_attribute("Latitude");
61 }
62 }
63 }
64
65 public function getLatitude(): ?float
66 {
67 if (is_object($this->map_node)) {
68 return (float) $this->map_node->get_attribute("Latitude");
69 }
70 return null;
71 }
72
73 public function setLongitude(?float $a_long = null): void
74 {
75 if (!is_null($a_long)) {
76 $this->map_node->set_attribute("Longitude", $a_long);
77 } else {
78 if ($this->map_node->has_attribute("Longitude")) {
79 $this->map_node->remove_attribute("Longitude");
80 }
81 }
82 }
83
84 public function getLongitude(): ?float
85 {
86 if (is_object($this->map_node)) {
87 return (float) $this->map_node->get_attribute("Longitude");
88 }
89 return null;
90 }
91
92 public function setZoom(?int $a_zoom): void
93 {
94 //if (!empty($a_zoom)) {
95 $this->map_node->set_attribute("Zoom", (int) $a_zoom);
96 /*} else {
97 if ($this->map_node->has_attribute("Zoom")) {
98 $this->map_node->remove_attribute("Zoom");
99 }
100 }*/
101 }
102
103 public function getZoom(): ?int
104 {
105 if (is_object($this->map_node)) {
106 return (int) $this->map_node->get_attribute("Zoom");
107 }
108 return null;
109 }
110
111 public function setLayout(
112 ?int $a_width,
113 ?int $a_height,
114 string $a_horizontal_align
115 ): void {
116 if (is_object($this->map_node)) {
118 $this->dom,
119 $this->map_node,
120 "Layout",
121 array("MapCaption"),
122 "",
123 array("Width" => (string) $a_width,
124 "Height" => (string) $a_height, "HorizontalAlign" => $a_horizontal_align)
125 );
126 }
127 }
128
129 public function getWidth(): ?int
130 {
131 if (is_object($this->map_node)) {
132 $childs = $this->map_node->child_nodes();
133 foreach ($childs as $child) {
134 if ($child->node_name() == "Layout") {
135 $w = $child->get_attribute("Width")
136 ? (int) $child->get_attribute("Width")
137 : null;
138 return $w;
139 }
140 }
141 }
142 return null;
143 }
144
145 public function getHeight(): ?int
146 {
147 if (is_object($this->map_node)) {
148 $childs = $this->map_node->child_nodes();
149 foreach ($childs as $child) {
150 if ($child->node_name() == "Layout") {
151 $h = $child->get_attribute("Height")
152 ? (int) $child->get_attribute("Height")
153 : null;
154 return $h;
155 }
156 }
157 }
158 return null;
159 }
160
161 public function getHorizontalAlign(): string
162 {
163 if (is_object($this->map_node)) {
164 $childs = $this->map_node->child_nodes();
165 foreach ($childs as $child) {
166 if ($child->node_name() == "Layout") {
167 return $child->get_attribute("HorizontalAlign");
168 }
169 }
170 }
171 return "";
172 }
173
174 public function setCaption(string $a_caption): void
175 {
176 if (is_object($this->map_node)) {
178 $this->dom,
179 $this->map_node,
180 "MapCaption",
181 array(),
182 $a_caption,
183 array()
184 );
185 }
186 }
187
188 public function getCaption(): string
189 {
190 if (is_object($this->map_node)) {
191 $childs = $this->map_node->child_nodes();
192 foreach ($childs as $child) {
193 if ($child->node_name() == "MapCaption") {
194 return $child->get_content();
195 }
196 }
197 }
198 return "";
199 }
200
201 public static function handleCaptionInput(
202 string $a_text
203 ): string {
204 $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
205 $a_text = str_replace(chr(13), "<br />", $a_text);
206 $a_text = str_replace(chr(10), "<br />", $a_text);
207
208 return $a_text;
209 }
210
211 public static function handleCaptionFormOutput(
212 string $a_text
213 ): string {
214 $a_text = str_replace("<br />", "\n", $a_text);
215 $a_text = str_replace("<br/>", "\n", $a_text);
216
217 return $a_text;
218 }
219
221 string $a_output,
222 string $a_mode,
223 bool $a_abstract_only = false
224 ): string {
225 $end = 0;
226 $start = strpos($a_output, "[[[[[Map;");
227 if (is_int($start)) {
228 $end = strpos($a_output, "]]]]]", $start);
229 }
230 $i = 1;
231 while ($end > 0) {
232 $param = substr($a_output, $start + 9, $end - $start - 9);
233
234 $param = explode(";", $param);
235 if (is_numeric($param[0]) && is_numeric($param[1]) && is_numeric($param[2])) {
236 $map_gui = ilMapUtil::getMapGUI();
237 $map_gui->setMapId("map_" . $i)
238 ->setLatitude($param[0])
239 ->setLongitude($param[1])
240 ->setZoom($param[2])
241 ->setWidth($param[3] . "px")
242 ->setHeight($param[4] . "px")
243 ->setEnableTypeControl(true)
244 ->setEnableNavigationControl(true)
245 ->setEnableCentralMarker(true);
246 $h2 = substr($a_output, 0, $start) .
247 $map_gui->getHtml() .
248 substr($a_output, $end + 5);
249 $a_output = $h2;
250 $i++;
251 }
252 $start = strpos($a_output, "[[[[[Map;", $start + 5);
253 $end = 0;
254 if (is_int($start)) {
255 $end = strpos($a_output, "]]]]]", $start);
256 }
257 }
258
259 return $a_output;
260 }
261}
const IL_INSERT_AFTER
static setFirstOptionalElement(php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes, bool $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
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)
php4DOMElement $map_node
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.
setNode(php4DOMElement $a_node)
Set xml node of page content.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$i
Definition: metadata.php:41
$param
Definition: xapitoken.php:46