Module refers to the part of the CMS "Interactive" and can be installed optionally.
Module "Geomap" is connected to the other modules. The standard diafan.CMS "GeoMap" connected to the module "Ads". The module card is connected to a specific module settings.
The module allows you to mark a point on the map to the other elements of the module. One element corresponds to one point. If you connect the module to the page of the site, you can bring all the points on a map. GET-variable module displays the points only for the selected module.
Example:
Module "Geomap" is connected to the module "Articles" and "Ads". Create a page "Geomap» http://site.com/geomap/. This page will display a map with points of all modules and the articles and ads. Page http://site.com/geomap/?module=ab show ads only point.
Подключаемая часть – файл modules/geomap/geomap.inc.php. В нем описан класс
Geomap_inc. В модуле к объекту класса можно обратиться через переменную $this->diafan->_geomap
. Экземпляр класса создается при первом вызове
переменной.
string get ([integer $element_id = 0], [string $module_name = ''], [string $element_type = 'element'], [integer $site_id = 0]) – Показывает точку на карте для элемента.
To bring the point on the map in the card item on the site is necessary in the module template modules/module_name/views/module_name.view.id.php add:
Example:
echo $this->diafan->_geomap->get($result["id"], 'модуль');
void prepare ([integer $element_id = 0], [strint $module_name = ''], [string $element_type = 'element']) – Запоминает данные элемента, которому нужно будет вывести точки на карте.
string add ([integer $element_id = 0], [string $module_name = ''], [string $element_type = 'element'], [integer $site_id = 0]) – Редактирование/добавление точки на карте.
To display the map in the form of adding an item, you need to add a form template (usually a file modules/module_name/views/module_name.view.form.php) to include the code:
Example:
echo $this->diafan->_geomap->add(0, 'модуль');
Editing a point on the map for the element is connected in the edit template element (usually a file modules/module_name/views/module_name.view.edit.php) with the following code:
Example:
echo $this->diafan->_geomap->add($result["id"], 'модуль');
string save ([integer $element_id = 0], [string $module_name = ''], [string $element_type = 'element'], [integer $site_id = 0]) – Сохранение точки на карте.
To save card data save function to include the code:
$this->diafan->_geomap->save($id, "модуль");
Example:
In the module "Ads" on the processing and preservation of the addition of ad requests occur in the file modules/ab/ab.action.php. In the function of ad additing add()
after the SQL-query, which save ad, included the code:
$this->diafan->_geomap->save($save, "ab");
In the function of saving the edited ad save()
is added code:
$this->diafan->_geomap->save($_POST["id"], "ab");
void delete (integer|array $element_ids, strint $module_name, [string $element_type = 'element']) – Удаляет точки для одного или нескольких элементов.
Example:
In the module "Ads" in the function of removing the ad delete()
in the file *modules/ab/ab.action.php * included the following code:
$this->diafan->_geomap->delete($row["id"], "ab");
void delete_module (string $module_name) – Удаляет все точки элементов модуля.
Example:
// remove from the map all point on the ads
$this->diafan->_geomap->delete_module('ab');
array config () – Настройки бэкенда.
The module can be connected to an unlimited number of backend – modules for specific maps.
To do this, you need to develop several files stanadartnoy structure, taking into account the features of Maps API and put the folder with these files in a folder geomap/backend. The backend application is to appear in the administrative part of the module "Geomap" and will be available for selection.
The backend must have a unique name in latin letters (for example, yandex, google, 2gis). For example, we will use the name newmap.
In the folder geomap/backend/newmap should contain the following files:
Consider the structure of standard files.
This file contains the name and configuration backend, loadable in selecting it from the list.
File Structure:
Example:
// 404 for direct call files
if ( ! defined('DIAFAN'))
{
$path = __FILE__; $i = 0;
while(! file_exists($path.'/includes/404.php'))
{
if($i == 10) exit; $i++;
$path = dirname($path);
}
include $path.'/includes/404.php';
}
class Geomap_newmap_admin
{
public $config;
private $diafan;
public function __construct(&$diafan)
{
$this->diafan = &$diafan;
$this->config = array(
"name" => 'Method name for administrator',
"params" => array(
// setting name must begin with the name of the method
'newmap_string' => 'Name',
// if the setting is not a string, instead of the name indicates the array with the name and type
// the following types are available: text, checkbox
'newmap_checkbox' => array(
'name' => 'Test mode',
'type' => 'checkbox'
),
// you can determine your function to display the fields and save it
'newmap_var' => 'Name',
)
);
}
/**
* Your function is to edit the settings newmap_var
*
* @return void
*/
public function edit_variable_newmap_var()
{
echo '<div class="unit tr_geomap" backend="paymenthod" style="display:none">
<div class="infofield">Field name</div>
Field value
</div>';
}
/**
* Your function is to save the settings newmap_var
*
* @return void
*/
public function save_variable_newmap_var()
{
// save datas
}
}
Template editing point on the map.
The template provides the following information:
$result["point"]
– coordinates of the point.$result["config"]
– an array of back-end settings.Template output point on the map without editing capabilities.
The template provides the following information:
$result["point"]
– coordinates of the point.$result["config"]
– an array of back-end settings.Template output multiple points on the map.
The template provides the following information:
$result["rows"]
– an array of points.$result["config"]
– an array of back-end settings.In the file of module settings (modules/модуль/admin/модуль.admin.config.php) and in the file of editing elements of the module (modules/модуль/admin/модуль.admin.php) you must add the parameter
'geomap'
:
public $variables = array(
'main' => array(
'geomap' => 'module',
…
),
…
);
The administrative part of the module, you can choose the backend - a service that is used to display the map. Backend "Google Map" is included in the standard build DIAFAN.CMS.
Each backend can have its own settings. For example, backend "Google Map" customizable scale and center map.
{geomap} – Точки на карте
modules/geomap/admin/geomap.admin.php – Module settings;
modules/geomap/admin/geomap.admin.inc.php – Connecting the module to the administrative part of other modules;
modules/geomap/admin/js/geomap.admin.js – Редактирование бэкенда для геокарты, JS-сценарий;
modules/geomap/backend/google/geomap.google.admin.php – Настройки карты "Google Maps" для административного интерфейса;
modules/geomap/backend/google/geomap.google.view.add.php – Шаблон редактирования точки на карте "Google Maps";
modules/geomap/backend/google/geomap.google.view.get.php – Шаблон точки на карте "Google Maps";
modules/geomap/backend/google/geomap.google.view.get_all.php – Шаблон вывода нескольких точек на карте "Google Maps";
modules/geomap/geomap.php – Controller;
modules/geomap/geomap.inc.php – Подключение модуля;
modules/geomap/geomap.install.php – Module installation;
modules/geomap/geomap.model.php – Model;
modules/geomap/views/geomap.view.show.php – Шаблон вывода нескольких точек на карте.