Added Google Maps Plugin with a map to show extra field coordinates markers - Refs BT#11371

remotes/angel/1.11.x
José Loguercio 8 years ago
parent c5986d080e
commit b662ece7f8
  1. 1
      main/inc/lib/template.lib.php
  2. 3
      plugin/google_maps/lang/english.php
  3. 3
      plugin/google_maps/lang/french.php
  4. 1
      plugin/google_maps/lang/spanish.php
  5. 4
      plugin/google_maps/src/GoogleMapsPluginPlugin.php
  6. 46
      plugin/google_maps/src/map_coordinates.php
  7. 50
      plugin/google_maps/view/map_coordinates.tpl

@ -137,6 +137,7 @@ class Template
$this->twig->addFilter('img', new Twig_Filter_Function('Template::get_image'));
$this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date'));
$this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time'));
$this->twig->addFilter('user_info', new Twig_Filter_Function('api_get_user_info'));
/*
$lexer = new Twig_Lexer($this->twig, array(

@ -1,4 +1,5 @@
<?php
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
$strings['plugin_comment'] = "Enable the functionality to show google maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

@ -1,4 +1,5 @@
<?php
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

@ -2,3 +2,4 @@
$strings['plugin_title'] = "Google Maps";
$strings['plugin_comment'] = "Enable the functionality to show google maps";
$strings['extra_field_name_help'] = "Ingrese aquí el nombre del campo extra de usuario del cual quiere obtener las localizaciones";

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* The google maps class allows to use
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
@ -14,7 +15,8 @@ class GoogleMapsPlugin extends Plugin
{
$parameters = array(
'enable_api' => 'boolean',
'api_key' => 'text'
'api_key' => 'text',
'extra_field_name' => 'text'
);
parent::__construct('1.0', 'José Loguercio Silva', $parameters);

@ -0,0 +1,46 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Show the map coordinates of all users geo extra field
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
* @package chamilo.plugin.google_maps
*/
$cidReset = true;
require_once __DIR__.'/../../../main/inc/global.inc.php';
api_protect_admin_script();
$plugin = GoogleMapsPlugin::create();
$apiIsEnable = $plugin->get('enable_api') === 'true';
$extraFieldName = $plugin->get('extra_field_name');
if ($apiIsEnable) {
$gmapsApiKey = $plugin->get('api_key');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key='. $gmapsApiKey . '" ></script>';
}
$em = Database::getManager();
$extraField = $em->getRepository('ChamiloCoreBundle:ExtraField');
$extraField = $extraField->findOneBy(['variable' => $extraFieldName]);
$extraFieldValues = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
$extraFieldValues = $extraFieldValues->findBy(['field' => $extraField->getId()]);
$templateName = get_lang('UsersCoordinatesMap');
$tpl = new Template($templateName);
$tpl->assign('extra_field_values', $extraFieldValues);
$content = $tpl->fetch('google_maps/view/map_coordinates.tpl');
$tpl->assign('header', $templateName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -0,0 +1,50 @@
<div id="map" style="width:100%; height:400px;">
</div>
<script>
$(document).ready(function() {
initMap();
});
function initMap() {
var center = new google.maps.LatLng(-3.480523, 7.866211);
var bounds = new google.maps.LatLngBounds();
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 2,
center: center,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
{% for field in extra_field_values %}
var latLng = '{{ field.value }}';
latLng = latLng.split(',');
var lat = latLng[0];
var lng = latLng[1];
var location = new google.maps.LatLng(lat, lng);
{% set userInfo = field.itemId | user_info %}
var marker = new google.maps.Marker({
map: map,
position: location,
label: "{{ userInfo.complete_name }}"
});
bounds.extend(marker.position);
map.fitBounds(bounds);
{% endfor %}
}
</script>
Loading…
Cancel
Save