ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilGoogleMapGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 class ilGoogleMapGUI extends ilMapGUI
27 {
28  protected string $css_row = "";
29 
30  public function __construct()
31  {
33  }
34 
35  public function getHtml(): string
36  {
37  $html_tpl = new ilTemplate(
38  "tpl.google_map.html",
39  true,
40  true,
41  "Services/Maps"
42  );
43 
44  $js_tpl = new ilTemplate(
45  "tpl.google_map.js",
46  true,
47  true,
48  "Services/Maps"
49  );
50 
51  $this->tpl->addJavaScript("//maps.google.com/maps/api/js?key=" . ilMapUtil::getApiKey(), false);
52 
53  // add user markers
54  $cnt = 0;
55  foreach ($this->user_marker as $user_id) {
56  if (ilObject::_exists($user_id)) {
57  $user = new ilObjUser($user_id);
58  if ($user->getLatitude() != 0 && $user->getLongitude() != 0 &&
59  $user->getPref("public_location") == "y") {
60  $js_tpl->setCurrentBlock("user_marker");
61  $js_tpl->setVariable(
62  "UMAP_ID",
63  $this->getMapId()
64  );
65  $js_tpl->setVariable("CNT", $cnt);
66 
67  $js_tpl->setVariable("ULAT", htmlspecialchars($user->getLatitude()));
68  $js_tpl->setVariable("ULONG", htmlspecialchars($user->getLongitude()));
69  $info = htmlspecialchars($user->getFirstName() . " " . $user->getLastName());
70  $delim = "<br />";
71  if ($user->getPref("public_institution") == "y") {
72  $info .= $delim . htmlspecialchars($user->getInstitution());
73  $delim = ", ";
74  }
75  if ($user->getPref("public_department") == "y") {
76  $info .= $delim . htmlspecialchars($user->getDepartment());
77  }
78  $delim = "<br />";
79  if ($user->getPref("public_street") == "y") {
80  $info .= $delim . htmlspecialchars($user->getStreet());
81  }
82  if ($user->getPref("public_zip") == "y") {
83  $info .= $delim . htmlspecialchars($user->getZipcode());
84  $delim = " ";
85  }
86  if ($user->getPref("public_city") == "y") {
87  $info .= $delim . htmlspecialchars($user->getCity());
88  }
89  $delim = "<br />";
90  if ($user->getPref("public_country") == "y") {
91  $info .= $delim . htmlspecialchars($user->getCountry());
92  }
93  $js_tpl->setVariable(
94  "USER_INFO",
95  $info
96  );
97  $js_tpl->setVariable(
98  "IMG_USER",
99  $user->getPersonalPicturePath("xsmall")
100  );
101  $js_tpl->parseCurrentBlock();
102  $cnt++;
103  }
104  }
105  }
106 
107  $html_tpl->setVariable("MAP_ID", $this->getMapId());
108  $html_tpl->setVariable("WIDTH", $this->getWidth());
109  $html_tpl->setVariable("HEIGHT", $this->getHeight());
110 
111  $js_tpl->setVariable("MAP_ID", $this->getMapId());
112  $js_tpl->setVariable("LAT", $this->getLatitude());
113  $js_tpl->setVariable("LONG", $this->getLongitude());
114  $js_tpl->setVariable("ZOOM", (int) $this->getZoom());
115  $type_control = $this->getEnableTypeControl()
116  ? "true"
117  : "false";
118  $js_tpl->setVariable("TYPE_CONTROL", $type_control);
119  $nav_control = $this->getEnableNavigationControl()
120  ? "true"
121  : "false";
122  $js_tpl->setVariable("NAV_CONTROL", $nav_control);
123  $update_listener = $this->getEnableUpdateListener()
124  ? "true"
125  : "false";
126  $js_tpl->setVariable("UPDATE_LISTENER", $update_listener);
128  ? "true"
129  : "false";
130  $js_tpl->setVariable("LARGE_CONTROL", $large_map_control);
132  ? "true"
133  : "false";
134  $js_tpl->setVariable("CENTRAL_MARKER", $central_marker);
135 
136  $this->tpl->addOnLoadCode($js_tpl->get());
137 
138  return $html_tpl->get();
139  }
140 
144  public function getUserListHtml(): string
145  {
146  $list_tpl = new ilTemplate(
147  "tpl.google_map_user_list.html",
148  true,
149  true,
150  "Services/Maps"
151  );
152 
153  $cnt = 0;
154  foreach ($this->user_marker as $user_id) {
155  if (ilObject::_exists($user_id)) {
156  $user = new ilObjUser($user_id);
157  $this->css_row = ($this->css_row != "tblrow1_mo")
158  ? "tblrow1_mo"
159  : "tblrow2_mo";
160  if ($user->getLatitude() != 0 && $user->getLongitude() != 0
161  && $user->getPref("public_location") == "y") {
162  $list_tpl->setCurrentBlock("item");
163  $list_tpl->setVariable("MARKER_CNT", $cnt);
164  $list_tpl->setVariable("MAP_ID", $this->getMapId());
165  $cnt++;
166  } else {
167  $list_tpl->setCurrentBlock("item_no_link");
168  }
169  $list_tpl->setVariable("CSS_ROW", $this->css_row);
170  $list_tpl->setVariable("TXT_USER", $user->getLogin());
171  $list_tpl->setVariable(
172  "IMG_USER",
173  $user->getPersonalPicturePath("xxsmall")
174  );
175  $list_tpl->parseCurrentBlock();
176  $list_tpl->touchBlock("row");
177  }
178  }
179 
180  return $list_tpl->get();
181  }
182 }
bool $central_marker
getEnableCentralMarker()
getEnableUpdateListener()
getEnableLargeMapControl()
static getApiKey()
getEnableNavigationControl()
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getUserListHtml()
Get User List HTML (to be displayed besides the map)
bool $large_map_control
getEnableTypeControl()
__construct(Container $dic, ilPlugin $plugin)
User interface class for maps.