Merge pull request #1111 from jloguercio/10992

Added Geolocalization (address field) to user profile - Refs #10992
remotes/angel/1.11.x
Yannick Warnier 9 years ago
commit 7f28b0022b
  1. 31
      app/Migrations/Schema/V111/Version20160418113000.php
  2. 105
      main/auth/inscription.php
  3. 103
      main/auth/profile.php
  4. 1
      main/inc/lib/api.lib.php
  5. 5
      main/inc/lib/usermanager.lib.php
  6. 30
      src/Chamilo/UserBundle/Entity/User.php

@ -0,0 +1,31 @@
<?php
/* For licensing terms, see /license.txt */
namespace Application\Migrations\Schema\V111;
use Application\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* Class Version20160418113000
*/
class Version20160418113000 extends AbstractMigrationChamilo
{
/**
* @param Schema $schema
*
* @throws \Doctrine\DBAL\Schema\SchemaException
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE user ADD address VARCHAR(250) DEFAULT NULL;');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->addSql('ALTER TABLE user DROP COLUMN address');
}
}

@ -20,7 +20,8 @@ $allowedFields = [
'phone', 'phone',
'status', 'status',
'language', 'language',
'extra_fields' 'extra_fields',
'address'
]; ];
$allowedFieldsConfiguration = api_get_configuration_value('allow_fields_inscription'); $allowedFieldsConfiguration = api_get_configuration_value('allow_fields_inscription');
@ -30,6 +31,84 @@ if ($allowedFieldsConfiguration !== false) {
} }
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1'); $htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
initializeGeo(false, false);
$("#geolocalization").on("click", function() {
var address = $("#address").val();
initializeGeo(address, false);
return false;
});
$("#myLocation").on("click", function() {
myLocation();
return false;
});
});
function myLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
});
}
}
function initializeGeo(address, latLng) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-75.503, 22.921);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : { "address": "Google" };
if (geocoder && parameter) {
geocoder.geocode(parameter, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
console.log(results[0]);
$("#address").val(results[0].formatted_address);
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: $("#address").val()
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
} else {
alert("'.get_lang("NotFound").'");
}
} else {
alert("Geocode '.get_lang('Error').': " + status);
}
});
}
}
</script>';
// User is not allowed if Terms and Conditions are disabled and // User is not allowed if Terms and Conditions are disabled and
// registration is disabled too. // registration is disabled too.
@ -167,6 +246,26 @@ if ($user_already_registered_show_terms == false) {
} }
} }
// Geolocation
if (in_array('address', $allowedFields)) {
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addButton('geolocalization', get_lang('geolocalization'), 'globe', 'default', 'default', 'null', ['id' => 'geolocalization']);
$form->addButton('myLocation', get_lang('MyLocation'), 'map-marker', 'default', 'default', 'null', ['id' => 'myLocation']);
$form->addHtml('
<div class="form-group">
<label for="map" class="col-sm-2 control-label">
'.get_lang('Map').'
</label>
<div class="col-sm-8">
<div name="map" id="map" style="width:100%; height:300px;">
</div>
</div>
</div>
');
}
// LANGUAGE // LANGUAGE
if (in_array('language', $allowedFields)) { if (in_array('language', $allowedFields)) {
if (api_get_setting('registration', 'language') == 'true') { if (api_get_setting('registration', 'language') == 'true') {
@ -483,7 +582,9 @@ if ($form->validate()) {
0, 0,
$extras, $extras,
null, null,
true true,
false,
$values['address']
); );
//update the extra fields //update the extra fields

@ -33,6 +33,7 @@ if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user[
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1'); $htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1');
$htmlHeadXtra[] = '<link href="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">'; $htmlHeadXtra[] = '<link href="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">';
$htmlHeadXtra[] = '<script src="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.js"></script>'; $htmlHeadXtra[] = '<script src="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.js"></script>';
$htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(document).ready(function() { $(document).ready(function() {
var $image = $("#previewImage"); var $image = $("#previewImage");
@ -80,7 +81,7 @@ $(document).ready(function() {
return false; return false;
}); });
$(\'#id_generate_api_key\').on(\'click\', function (e) { $("id_generate_api_key").on("click", function (e) {
e.preventDefault(); e.preventDefault();
$.ajax({ $.ajax({
@ -93,6 +94,7 @@ $(document).ready(function() {
} }
}); });
}); });
}); });
function confirmation(name) { function confirmation(name) {
@ -147,6 +149,85 @@ $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
$value_array = $array_list_key[$id_temp_key]; $value_array = $array_list_key[$id_temp_key];
$user_data['api_key_generate'] = $value_array; $user_data['api_key_generate'] = $value_array;
$htmlHeadXtra[] = '<script>
$(document).ready(function() {
var address = "'.$user_data['address'].'";
initializeGeo(address, false);
$("#geolocalization").on("click", function() {
var address = $("#address").val();
initializeGeo(address, false);
return false;
});
$("#myLocation").on("click", function() {
myLocation();
return false;
});
});
function myLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
});
}
}
function initializeGeo(address, latLng) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : false;
if (geocoder && parameter) {
geocoder.geocode(parameter, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
console.log(results[0]);
$("#address").val(results[0].formatted_address);
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: $("#address").val()
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
} else {
alert("'.get_lang("NotFound").'");
}
} else {
alert("Geocode '.get_lang('Error').': " + status);
}
});
}
}
</script>';
if ($user_data !== false) { if ($user_data !== false) {
if (api_get_setting('login_is_email') == 'true') { if (api_get_setting('login_is_email') == 'true') {
$user_data['username'] = $user_data['email']; $user_data['username'] = $user_data['email'];
@ -249,6 +330,24 @@ $form->applyFilter('phone', 'stripslashes');
$form->applyFilter('phone', 'trim'); $form->applyFilter('phone', 'trim');
$form->applyFilter('phone', 'html_filter'); $form->applyFilter('phone', 'html_filter');
// Geolocation
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addButton('geolocalization', get_lang('geolocalization'), 'globe', 'default', 'default', 'null', ['id' => 'geolocalization']);
$form->addButton('myLocation', get_lang('MyLocation'), 'map-marker', 'default', 'default', 'null', ['id' => 'myLocation']);
$form->addHtml('
<div class="form-group">
<label for="map" class="col-sm-2 control-label">
'.get_lang('Map').'
</label>
<div class="col-sm-8">
<div name="map" id="map" style="width:100%; height:300px;">
</div>
</div>
</div>
');
// PICTURE // PICTURE
if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') { if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
$form->addElement( $form->addElement(
@ -676,7 +775,7 @@ if ($form->validate()) {
//Fixing missing variables //Fixing missing variables
$available_values_to_modify = array_merge( $available_values_to_modify = array_merge(
$available_values_to_modify, $available_values_to_modify,
array('competences', 'diplomas', 'openarea', 'teach', 'openid') array('competences', 'diplomas', 'openarea', 'teach', 'openid', 'address')
); );
// build SQL query // build SQL query

@ -1273,6 +1273,7 @@ function _api_format_user($user, $add_password = false)
$attributes = array( $attributes = array(
'phone', 'phone',
'address',
'picture_uri', 'picture_uri',
'official_code', 'official_code',
'status', 'status',

@ -211,6 +211,7 @@ class UserManager
* @param string Encrypt method used if password is given encrypted. Set to an empty string by default * @param string Encrypt method used if password is given encrypted. Set to an empty string by default
* @param bool $send_mail * @param bool $send_mail
* @param bool $isAdmin * @param bool $isAdmin
* @param string $address
* *
* @return mixed new user id - if the new user creation succeeds, false otherwise * @return mixed new user id - if the new user creation succeeds, false otherwise
* @desc The function tries to retrieve user id from the session. * @desc The function tries to retrieve user id from the session.
@ -237,7 +238,8 @@ class UserManager
$extra = null, $extra = null,
$encrypt_method = '', $encrypt_method = '',
$send_mail = false, $send_mail = false,
$isAdmin = false $isAdmin = false,
$address = ''
) { ) {
$currentUserId = api_get_user_id(); $currentUserId = api_get_user_id();
$hook = HookCreateUser::create(); $hook = HookCreateUser::create();
@ -346,6 +348,7 @@ class UserManager
->setCreatorId($creator_id) ->setCreatorId($creator_id)
->setAuthSource($auth_source) ->setAuthSource($auth_source)
->setPhone($phone) ->setPhone($phone)
->setAddress($address)
->setLanguage($language) ->setLanguage($language)
->setRegistrationDate($now) ->setRegistrationDate($now)
->setHrDeptId($hr_dept_id) ->setHrDeptId($hr_dept_id)

@ -180,6 +180,13 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
*/ */
protected $phone; protected $phone;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
*/
private $address;
/** /**
* Vich\UploadableField(mapping="user_image", fileNameProperty="picture_uri") * Vich\UploadableField(mapping="user_image", fileNameProperty="picture_uri")
* *
@ -948,6 +955,29 @@ class User implements UserInterface //implements ParticipantInterface, ThemeUser
return $this->phone; return $this->phone;
} }
/**
* Set address
*
* @param string $address
* @return User
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/** /**
* Set pictureUri * Set pictureUri
* *

Loading…
Cancel
Save