Skip to content

Commit

Permalink
#83 [Map] add: header on map and improve features
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-micka committed Jul 18, 2023
1 parent b995f8b commit f915816
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 35 deletions.
3 changes: 2 additions & 1 deletion class/address.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public function create(User $user, bool $notrigger = false): int
$address = $data[0];

$this->status = self::STATUS_ACTIVE;
$this->fk_region = $this->fk_region > 0 ? $this->fk_region : $regionAndState['region_code'];
$this->latitude = $address->lat;
$this->longitude = $address->lon;
$this->osm_type = $address->osm_type ?? '';
Expand Down Expand Up @@ -350,7 +351,7 @@ public function injectMapFeatures(array $features, int $chunkSize, int $deep = 0
foreach ($bulkFeatures as $bulk) {
$encodedBulk = json_encode($bulk);
if (!empty($encodedBulk)) {
print "geojsonProspectMarkers.features = $.merge(geojsonProspectMarkers.features, $encodedBulk);\n";
print "geojsonMarkers.features = $.merge(geojsonMarkers.features, $encodedBulk);\n";
} else {
if ($chunkSize > 1) {
$result = $this->injectMapFeatures($bulk, floor($chunkSize / 2), $deep + 1);
Expand Down
33 changes: 19 additions & 14 deletions core/modules/modEasyCRM.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function __construct($db)
if (preg_match('/_/', $objectsMetadataType)) {
$splittedElementType = preg_split('/_/', $objectsMetadataType);
$moduleName = $splittedElementType[0];
$objectName = strtolower($objectsMetadataType['className']);
$objectName = strtolower($objectsMetadataType['class_name']);
$objectType = $objectName . '@' . $moduleName;
} else {
$objectType = $objectsMetadataType;
Expand Down Expand Up @@ -278,16 +278,23 @@ public function __construct($db)
$this->rights[$r][4] = 'read';
$this->rights[$r][5] = 1;
$r++;
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1);
$this->rights[$r][1] = $langs->trans('WriteModule', 'EasyCRM');
$this->rights[$r][4] = 'write';
$this->rights[$r][5] = 'write';
$r++;
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1);
$this->rights[$r][1] = $langs->trans('DeleteModule', 'EasyCRM');
$this->rights[$r][4] = 'delete';
$this->rights[$r][5] = 'delete';
$r++;

/* ADDRESS PERMISSSIONS */
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used)
$this->rights[$r][1] = $langs->transnoentities('ReadObjects',$langs->transnoentities('Address')); // Permission label
$this->rights[$r][4] = 'address'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$r++;
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used)
$this->rights[$r][1] = $langs->transnoentities('CreateObjects', $langs->transnoentities('Address')); // Permission label
$this->rights[$r][4] = 'address'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$this->rights[$r][5] = 'write'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$r++;
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1); // Permission id (must not be already used)
$this->rights[$r][1] = $langs->transnoentities('DeleteObjects', $langs->transnoentities('Address')); // Permission label
$this->rights[$r][4] = 'address'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->easycrm->level1->level2)
$r++;

/* ADMINPAGE PANEL ACCESS PERMISSIONS */
$this->rights[$r][0] = $this->numero . sprintf('%02d', $r + 1);
Expand Down Expand Up @@ -338,9 +345,7 @@ public function __construct($db)
$this->menu[$r++] = [
'fk_menu' => 'fk_mainmenu=' . $objectMetadata['mainmenu'] . ',fk_leftmenu=' . $objectMetadata['leftmenu'],
'type' => 'left',
'titre' => $langs->transnoentities('Map'),
'prefix' => '<i class="fas fa-map pictofixedwidth"></i>',
'mainmenu' => '',
'titre' => '<i class="fas fa-map-marked-alt pictofixedwidth" style="padding-right: 4px; color:#63ACC9"></i>' . $langs->transnoentities('Map'),
'leftmenu' => 'map',
'url' => 'easycrm/view/map.php?object_type=' . $objectsMetadataType,
'langs' => 'easycrm@easycrm',
Expand Down
9 changes: 5 additions & 4 deletions view/address.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be included, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals

// Security check - Protection if external user
$permissiontoread = $user->rights->easycrm->read;
$permissiontoadd = $user->rights->easycrm->write;
$permissiontodelete = $user->rights->easycrm->delete;
$permissiontoread = $user->rights->easycrm->address->read;
$permissiontoadd = $user->rights->easycrm->address->write;
$permissiontodelete = $user->rights->easycrm->address->delete;
saturne_check_access($permissiontoread);

/*
Expand Down Expand Up @@ -246,7 +246,8 @@
} else if ($id > 0 || !empty($ref) && empty($action)) {
saturne_get_fiche_head($object, 'address', $title);

saturne_banner_tab($object, 'ref', '', 1, 'ref', 'ref', '', !empty($object->photo));
$morehtml = '<a href="' . dol_buildpath('/' . $object->element . '/list.php', 1) . '?restore_lastsearch_values=1&object_type=' . $object->element . '">' . $langs->trans('BackToList') . '</a>';
saturne_banner_tab($object, 'ref', $morehtml, 1, 'ref', 'ref', '', !empty($object->photo));

$object->fetch_optionals();

Expand Down
40 changes: 24 additions & 16 deletions view/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
//$filterCat = GETPOST("search_category_" . $objectType ."_list", 'array');

// Security check - Protection if external user
$permissiontoread = $user->rights->saturne->read;
$permissiontoadd = $user->rights->saturne->write;
$permissiontodelete = $user->rights->saturne->delete;
$permissiontoread = $user->rights->easycrm->address->read;
$permissiontoadd = $user->rights->easycrm->address->write;
$permissiontodelete = $user->rights->easycrm->address->delete;
saturne_check_access($permissiontoread);

// Initialize technical object
$address = new Address($db);
$object = new $objectInfos['class_name']($db);
$address = new Address($db);
$object = new $objectInfos['class_name']($db);

// Initialize view objects
$form = new Form($db);
Expand Down Expand Up @@ -125,7 +125,6 @@
$num = 0;
$allObjects = saturne_fetch_all_object_type($objectInfos['class_name']);


if ($conf->global->EASYCRM_DISPLAY_MAIN_ADDRESS) {
if (is_array($allObjects) && !empty($allObjects)) {
foreach ($allObjects as $object) {
Expand All @@ -139,9 +138,9 @@

$address->fetch($addressId);

if (($filterId > 0 && $filterId != $address->id) || (dol_strlen($filterType) > 0 && $filterType != $address->type) || (dol_strlen($filterTown) > 0 && $filterTown != $address->town) ||
if (($filterId > 0 && $filterId != $object->id) || (dol_strlen($filterType) > 0 && $filterType != $address->type) || (dol_strlen($filterTown) > 0 && $filterTown != $address->town) ||
($filterCountry > 0 && $filterCountry != $address->fk_country) || ($filterRegion > 0 && $filterRegion != $address->fk_region) || ($filterState > 0 && $filterState != $address->fk_department)) {
continue;
continue;
}

if ($address->longitude != 0 && $address->latitude != 0) {
Expand Down Expand Up @@ -211,6 +210,15 @@
}
}

if ($filterId > 0) {
$object->fetch($filterId);

saturne_get_fiche_head($object, 'map', $title);

$morehtml = '<a href="' . dol_buildpath('/' . $object->element . '/list.php', 1) . '?restore_lastsearch_values=1&object_type=' . $object->element . '">' . $langs->trans('BackToList') . '</a>';
saturne_banner_tab($object, 'ref', $morehtml, 1, 'ref', 'ref', '', !empty($object->photo));
}

print_barre_liste($title, '', $_SERVER["PHP_SELF"], '', '', '', '', '', $num, 'fa-map-marked-alt');

print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '?object_type=' . $objectType . '" name="formfilter">';
Expand All @@ -222,11 +230,11 @@

$selectArray = [];
foreach ($allObjects as $singleObject) {
$selectArray[$singleObject->id] = $singleObject->ref;
$selectArray[$singleObject->id] = $singleObject->ref;
}
// Object ?>
<div class="divsearchfield"> <?php print img_picto('', $objectInfos['picto']) . ' ' . $langs->trans($objectInfos['langs']). ': ';
print $form->selectarray('object_id', $selectArray, $filterId, 1);
print $form->selectarray('object_id', $selectArray, $filterId, 1, 0, 0, '', 0, 0, $filterId > 0);

// Type ?>
<div class="divsearchfield"> <?php print $langs->trans('Type'). ': ';
Expand Down Expand Up @@ -316,7 +324,7 @@
}
</style>

<div id="map" class="map"></div>
<div id="display_map" class="display_map"></div>
<div id="popup" class="ol-popup">
<a href="#" id="popup-closer" class="ol-popup-closer"></a>
<div id="popup-content"></div>
Expand All @@ -326,15 +334,15 @@
/**
* Set map height.
*/
var _map = $('#map');
var _map = $('#display_map');
var _map_pos = _map.position();
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
_map.height(h - _map_pos.top - 20);

/**
* Prospect markers geoJSON.
*/
var geojsonProspectMarkers = {
var geojsonMarkers = {
"type": "FeatureCollection",
"crs": {
"type": "name",
Expand All @@ -351,7 +359,7 @@
}
?>
console.log("Map metrics: EPSG:3857");
console.log("Map features length: " + geojsonProspectMarkers.features.length + " map features loaded.");
console.log("Map features length: " + geojsonMarkers.features.length + " map features loaded.");

/**
* Prospect markers styles.
Expand All @@ -377,7 +385,7 @@
* Prospect markers source.
*/
var prospectSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonProspectMarkers)
features: (new ol.format.GeoJSON()).readFeatures(geojsonMarkers)
});

/**
Expand Down Expand Up @@ -447,7 +455,7 @@
* Create the map.
*/
var map = new ol.Map({
target: 'map',
target: 'display_map',
layers: [osmLayer, prospectLayer],
overlays: [popupOverlay],
view: mapView
Expand Down

0 comments on commit f915816

Please sign in to comment.