ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCMap.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPageContent.php");
6
18{
19 public $map_node;
20
24 public function init()
25 {
26 $this->setType("map");
27 }
28
32 public function setNode($a_node)
33 {
34 parent::setNode($a_node); // this is the PageContent node
35 $this->map_node = $a_node->first_child(); // this is the Map node
36 }
37
44 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
45 {
46 $this->node = $this->createPageContentNode();
47
48 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49 $this->map_node = $this->dom->create_element("Map");
50 $this->map_node = $this->node->append_child($this->map_node);
51 $this->map_node->set_attribute("Latitude", "0");
52 $this->map_node->set_attribute("Longitude", "0");
53 $this->map_node->set_attribute("Zoom", "3");
54 }
55
61 public function setLatitude($a_lat)
62 {
63 if (!empty($a_lat)) {
64 $this->map_node->set_attribute("Latitude", $a_lat);
65 } else {
66 if ($this->map_node->has_attribute("Latitude")) {
67 $this->map_node->remove_attribute("Latitude");
68 }
69 }
70 }
71
77 public function getLatitude()
78 {
79 if (is_object($this->map_node)) {
80 return $this->map_node->get_attribute("Latitude");
81 }
82 }
83
89 public function setLongitude($a_long)
90 {
91 if (!empty($a_long)) {
92 $this->map_node->set_attribute("Longitude", $a_long);
93 } else {
94 if ($this->map_node->has_attribute("Longitude")) {
95 $this->map_node->remove_attribute("Longitude");
96 }
97 }
98 }
99
105 public function getLongitude()
106 {
107 if (is_object($this->map_node)) {
108 return $this->map_node->get_attribute("Longitude");
109 }
110 }
111
117 public function setZoom($a_zoom)
118 {
119 if (!empty($a_zoom)) {
120 $this->map_node->set_attribute("Zoom", $a_zoom);
121 } else {
122 if ($this->map_node->has_attribute("Zoom")) {
123 $this->map_node->remove_attribute("Zoom");
124 }
125 }
126 }
127
133 public function getZoom()
134 {
135 if (is_object($this->map_node)) {
136 return $this->map_node->get_attribute("Zoom");
137 }
138 }
139
147 public function setLayout($a_width, $a_height, $a_horizontal_align)
148 {
149 if (is_object($this->map_node)) {
151 $this->dom,
152 $this->map_node,
153 "Layout",
154 array("MapCaption"),
155 "",
156 array("Width" => $a_width,
157 "Height" => $a_height, "HorizontalAlign" => $a_horizontal_align)
158 );
159 }
160 }
161
167 public function getWidth()
168 {
169 if (is_object($this->map_node)) {
170 $childs = $this->map_node->child_nodes();
171 foreach ($childs as $child) {
172 if ($child->node_name() == "Layout") {
173 return $child->get_attribute("Width");
174 }
175 }
176 }
177 }
178
184 public function getHeight()
185 {
186 if (is_object($this->map_node)) {
187 $childs = $this->map_node->child_nodes();
188 foreach ($childs as $child) {
189 if ($child->node_name() == "Layout") {
190 return $child->get_attribute("Height");
191 }
192 }
193 }
194 }
195
201 public function getHorizontalAlign()
202 {
203 if (is_object($this->map_node)) {
204 $childs = $this->map_node->child_nodes();
205 foreach ($childs as $child) {
206 if ($child->node_name() == "Layout") {
207 return $child->get_attribute("HorizontalAlign");
208 }
209 }
210 }
211 }
212
218 public function setCaption($a_caption)
219 {
220 if (is_object($this->map_node)) {
222 $this->dom,
223 $this->map_node,
224 "MapCaption",
225 array(),
226 $a_caption,
227 array()
228 );
229 }
230 }
231
237 public function getCaption()
238 {
239 if (is_object($this->map_node)) {
240 $childs = $this->map_node->child_nodes();
241 foreach ($childs as $child) {
242 if ($child->node_name() == "MapCaption") {
243 return $child->get_content();
244 }
245 }
246 }
247 }
248
249 public static function handleCaptionInput($a_text)
250 {
251 $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
252 $a_text = str_replace(chr(13), "<br />", $a_text);
253 $a_text = str_replace(chr(10), "<br />", $a_text);
254
255 return $a_text;
256 }
257
258 public static function handleCaptionFormOutput($a_text)
259 {
260 $a_text = str_replace("<br />", "\n", $a_text);
261 $a_text = str_replace("<br/>", "\n", $a_text);
262
263 return $a_text;
264 }
265
269 public function modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only = false)
270 {
271 $c_pos = 0;
272 $start = strpos($a_html, "[[[[[Map;");
273 if (is_int($start)) {
274 $end = strpos($a_html, "]]]]]", $start);
275 }
276 $i = 1;
277 while ($end > 0) {
278 $param = substr($a_html, $start + 9, $end - $start - 9);
279
280 $param = explode(";", $param);
281 if (is_numeric($param[0]) && is_numeric($param[1]) && is_numeric($param[2])) {
282 include_once("./Services/Maps/classes/class.ilMapUtil.php");
283 $map_gui = ilMapUtil::getMapGUI();
284 $map_gui->setMapId("map_" . $i)
285 ->setLatitude($param[0])
286 ->setLongitude($param[1])
287 ->setZoom($param[2])
288 ->setWidth($param[3] . "px")
289 ->setHeight($param[4] . "px")
290 ->setEnableTypeControl(true)
291 ->setEnableNavigationControl(true)
292 ->setEnableCentralMarker(true);
293 $h2 = substr($a_html, 0, $start) .
294 $map_gui->getHtml() .
295 substr($a_html, $end + 5);
296 $a_html = $h2;
297 $i++;
298 }
299 $start = strpos($a_html, "[[[[[Map;", $start + 5);
300 $end = 0;
301 if (is_int($start)) {
302 $end = strpos($a_html, "]]]]]", $start);
303 }
304 }
305
306 return $a_html;
307 }
308}
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
static setFirstOptionalElement( $doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $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.
Class ilPCMap.
setZoom($a_zoom)
Set zoom of map.
static handleCaptionFormOutput($a_text)
getHorizontalAlign()
Get Horizontal Alignment.
getLongitude()
Get longitude of map.
getHeight()
Get Height.
setLongitude($a_long)
Set longitude of map.
setLatitude($a_lat)
Set latitude of map.
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
@inheritDoc
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create map node in xml.
getWidth()
Get Width.
getZoom()
Get zoom of map.
setNode($a_node)
Set node.
setCaption($a_caption)
Set Caption.
static handleCaptionInput($a_text)
getCaption()
Get Caption.
getLatitude()
Get latitude of map.
init()
Init page content component.
setLayout($a_width, $a_height, $a_horizontal_align)
Set Layout.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
$i
Definition: metadata.php:24
$param
Definition: xapitoken.php:29