upgrade
This commit is contained in:
4
plugin/google_maps/README.md
Normal file
4
plugin/google_maps/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Google Maps Plugin
|
||||
===================
|
||||
|
||||
Activa la funcionalidad de mostrar mapas usando el api de google maps
|
||||
10
plugin/google_maps/config.php
Normal file
10
plugin/google_maps/config.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Config the plugin.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
define('TABLE_GOOGLE_MAPS', 'plugin_google_maps');
|
||||
12
plugin/google_maps/index.php
Normal file
12
plugin/google_maps/index.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Config the plugin.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
$googleMapsPlugin = GoogleMapsPlugin::create();
|
||||
12
plugin/google_maps/install.php
Normal file
12
plugin/google_maps/install.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Initialization install.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
GoogleMapsPlugin::create()->install();
|
||||
13
plugin/google_maps/lang/english.php
Normal file
13
plugin/google_maps/lang/english.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$strings['plugin_title'] = "Google Maps";
|
||||
$strings['plugin_comment'] = "Enable the functionality to show google maps";
|
||||
$strings['extra_field_name_help'] = "Enter one or many extra user fields name separated by a comma (,) from which you want to obtain the locations, you can get up to 5 geolocation fields (the rest will be ignored) which will be marked with the following icons respectively:
|
||||
<br><br>
|
||||
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
|
||||
<br><br>
|
||||
Follow the link below to see the map : <a href='".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php'>".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php</a>";
|
||||
$strings['enable_api'] = "Enable API";
|
||||
$strings['api_key'] = "Api Key";
|
||||
$strings['extra_field_name'] = "Extra field name";
|
||||
$strings['UsersCoordinatesMap'] = "Users location Map";
|
||||
13
plugin/google_maps/lang/french.php
Normal file
13
plugin/google_maps/lang/french.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$strings['plugin_title'] = "Google Maps";
|
||||
$strings['plugin_comment'] = "Active la fonctionnalité pour afficher Google Maps";
|
||||
$strings['extra_field_name_help'] = "Entrez ici le ou les nom(s) des champs extra d'utilisateur séparés par une virgule (,) desquels on souhaite obtenir la géolocalisation, vous pouvez définir jusqu'à 5 champs pour la géolocalisation (le reste est ignoré). Ils seront associés dans l'ordre avec les icônes suivantes :
|
||||
<br><br>
|
||||
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
|
||||
<br><br>
|
||||
Suivez le lien pour voir la carte : <a href='".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php'>".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php</a>";
|
||||
$strings['enable_api'] = "Enable API";
|
||||
$strings['api_key'] = "Api Key";
|
||||
$strings['extra_field_name'] = "Nom de champ supplémentaire";
|
||||
$strings['UsersCoordinatesMap'] = "Carte des emplacements des utilisateurs";
|
||||
13
plugin/google_maps/lang/spanish.php
Normal file
13
plugin/google_maps/lang/spanish.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
$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 o los campos extra de usuario separados por una coma (,) del cual quiere obtener las localizaciones, puede obtener hasta 5 campos de geolocalización (el resto serán ignorados) los cuales se marcarán con los siguientes iconos respectivamente:
|
||||
<br><br>
|
||||
<img src='//maps.google.com/mapfiles/ms/icons/red-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/blue-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/green-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/yellow-dot.png'> <img src='//maps.google.com/mapfiles/ms/icons/purple-dot.png'>
|
||||
<br><br>
|
||||
siga el siguiente link para ver el mapa : <a href='".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php'>".api_get_path(WEB_PLUGIN_PATH)."google_maps/src/map_coordinates.php</a>";
|
||||
$strings['enable_api'] = "Activar API";
|
||||
$strings['api_key'] = "Api Key";
|
||||
$strings['extra_field_name'] = "Nombre del campo extra";
|
||||
$strings['UsersCoordinatesMap'] = "Mapa de localización de Usuarios";
|
||||
12
plugin/google_maps/plugin.php
Normal file
12
plugin/google_maps/plugin.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Show google maps.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
$plugin_info = GoogleMapsPlugin::create()->get_info();
|
||||
70
plugin/google_maps/src/GoogleMapsPlugin.php
Normal file
70
plugin/google_maps/src/GoogleMapsPlugin.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* The google maps class allows to use.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
class GoogleMapsPlugin extends Plugin
|
||||
{
|
||||
public $javascriptIncluded;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$parameters = [
|
||||
'enable_api' => 'boolean',
|
||||
'api_key' => 'text',
|
||||
'extra_field_name' => 'text',
|
||||
];
|
||||
|
||||
$this->javascriptIncluded = false;
|
||||
|
||||
parent::__construct('1.0', 'José Loguercio Silva', $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return 'google_maps';
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance the plugin.
|
||||
*
|
||||
* @staticvar null $result
|
||||
*
|
||||
* @return GoogleMapsPlugin
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
static $result = null;
|
||||
|
||||
return $result ? $result : $result = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the plugin.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall the plugin.
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
68
plugin/google_maps/src/map_coordinates.php
Normal file
68
plugin/google_maps/src/map_coordinates.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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');
|
||||
|
||||
$extraFieldName = array_map('trim', explode(',', $extraFieldName));
|
||||
|
||||
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');
|
||||
|
||||
$extraFieldNames = [];
|
||||
|
||||
foreach ($extraFieldName as $field) {
|
||||
$extraFieldNames[] = $extraField->findOneBy(['variable' => $field]);
|
||||
}
|
||||
|
||||
$extraFieldValues = [];
|
||||
|
||||
foreach ($extraFieldNames as $index => $fieldName) {
|
||||
if ($fieldName) {
|
||||
$extraFieldRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldValues');
|
||||
$extraFieldValues[] = $extraFieldRepo->findBy(['field' => $fieldName->getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
$templateName = $plugin->get_lang('UsersCoordinatesMap');
|
||||
|
||||
$tpl = new Template($templateName);
|
||||
|
||||
$formattedExtraFieldValues = [];
|
||||
|
||||
foreach ($extraFieldValues as $index => $extra) {
|
||||
foreach ($extra as $yandex => $field) {
|
||||
$thisUserExtraField = api_get_user_info($field->getItemId());
|
||||
$formattedExtraFieldValues[$index][$yandex]['address'] = $field->getValue();
|
||||
$formattedExtraFieldValues[$index][$yandex]['user_complete_name'] = $thisUserExtraField['complete_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('extra_field_values_formatted', $formattedExtraFieldValues);
|
||||
$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();
|
||||
12
plugin/google_maps/uninstall.php
Normal file
12
plugin/google_maps/uninstall.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
/**
|
||||
* Initialization uninstall.
|
||||
*
|
||||
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
|
||||
*
|
||||
* @package chamilo.plugin.google_maps
|
||||
*/
|
||||
require_once __DIR__.'/config.php';
|
||||
|
||||
GoogleMapsPlugin::create()->uninstall();
|
||||
105
plugin/google_maps/view/map_coordinates.tpl
Normal file
105
plugin/google_maps/view/map_coordinates.tpl
Normal file
@@ -0,0 +1,105 @@
|
||||
<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 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
|
||||
});
|
||||
|
||||
var extraFields = {{ extra_field_values_formatted|json_encode }};
|
||||
|
||||
for (var i = 0; i < extraFields.length; i++) {
|
||||
|
||||
var index = i + 1;
|
||||
|
||||
for (var y = 0; y < extraFields[i].length; y++) {
|
||||
|
||||
var address = extraFields[i][y]['address'];
|
||||
var userCompleteName = extraFields[i][y]['user_complete_name'];
|
||||
|
||||
addMaker(address, map, bounds, userCompleteName, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addMaker(address, map, bounds, userCompleteName, index) {
|
||||
|
||||
if (index > 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
var infoWindow = new google.maps.InfoWindow();
|
||||
|
||||
var geocoder = geocoder = new google.maps.Geocoder();
|
||||
|
||||
var formattedAddress = '';
|
||||
|
||||
geocoder.geocode({ 'address': address }, function (results, status) {
|
||||
|
||||
if (status === google.maps.GeocoderStatus.OK) {
|
||||
|
||||
if (results) {
|
||||
formattedAddress = results[0].formatted_address;
|
||||
} else {
|
||||
formattedAddress = '{{ 'Unknown' | get_lang }}';
|
||||
}
|
||||
|
||||
var marker = new google.maps.Marker({
|
||||
map: map,
|
||||
position: results[0].geometry.location,
|
||||
label: userCompleteName
|
||||
});
|
||||
|
||||
switch (index) {
|
||||
case 1:
|
||||
marker.setIcon('//maps.google.com/mapfiles/ms/icons/red-dot.png');
|
||||
break;
|
||||
case 2:
|
||||
marker.setIcon('//maps.google.com/mapfiles/ms/icons/blue-dot.png');
|
||||
break;
|
||||
case 3:
|
||||
marker.setIcon('//maps.google.com/mapfiles/ms/icons/green-dot.png');
|
||||
break;
|
||||
case 4:
|
||||
marker.setIcon('//maps.google.com/mapfiles/ms/icons/yellow-dot.png');
|
||||
break;
|
||||
case 5:
|
||||
marker.setIcon('//maps.google.com/mapfiles/ms/icons/purple-dot.png');
|
||||
break;
|
||||
}
|
||||
|
||||
var infoWinContent = "<b>" + userCompleteName + "</b> - " + formattedAddress;
|
||||
|
||||
marker.addListener('click', function() {
|
||||
infoWindow.setContent(infoWinContent);
|
||||
infoWindow.open(map, marker);
|
||||
});
|
||||
|
||||
bounds.extend(marker.position);
|
||||
map.fitBounds(bounds);
|
||||
|
||||
} else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
|
||||
setTimeout(function() {
|
||||
addMaker(address, map, bounds, userCompleteName, index);
|
||||
}, 350);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user