This commit is contained in:
Xes
2025-08-14 22:39:38 +02:00
parent 3641e93527
commit 5403f346e3
3370 changed files with 327179 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
Google Maps Plugin
===================
Activa la funcionalidad de mostrar mapas usando el api de google maps

View 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');

View 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();

View 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();

View 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";

View 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";

View 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";

View 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();

View 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;
}
}

View 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();

View 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();

View 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>