-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathactivate.php
More file actions
51 lines (44 loc) · 1.89 KB
/
activate.php
File metadata and controls
51 lines (44 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Elgg AgoraMap Maps Api plugin
* @package amap_maps_api
*
* Credits to https://github.com/hypeJunction/hypeGeo
*/
// Create a new table that will hold geometry data for entities
$prefix = elgg_get_config('dbprefix');
$tables = get_db_tables();
if (!in_array("{$prefix}entity_geometry", $tables)) {
set_time_limit(0);
run_sql_script(__DIR__ . '/sql/create_table.sql');
elgg_add_admin_notice("geo:create_table", "MySQL table for storing entity geometry with the name '{$prefix}entity_geometry' has been created");
// Populate geometry table with know information about entities
$batch = new ElggBatch('elgg_get_entities_from_metadata', array(
'metadata_name_value_pairs' => array(
array('name' => 'geo:lat', 'value' => null, 'operand' => 'NOT NULL'),
array('name' => 'geo:lat', 'value' => '0', 'operand' => '!='),
array('name' => 'geo:long', 'value' => null, 'operand' => 'NOT NULL'),
array('name' => 'geo:long', 'value' => '0', 'operand' => '!='),
),
'order_by' => 'e.guid ASC',
'limit' => 0
));
$i = $k = 0;
foreach ($batch as $b) {
if (elgg_instanceof($b)) {
$lat = $b->getLatitude();
$long = $b->getLongitude();
if ($lat && $long) {
$query = "INSERT INTO {$prefix}entity_geometry (entity_guid, geometry)
VALUES ({$b->guid}, GeomFromText('POINT({$lat} {$long})'))
ON DUPLICATE KEY UPDATE geometry=GeomFromText('POINT({$lat} {$long})')";
if (insert_data($query)) {
$i++;
}
} else {
$k++;
}
}
}
elgg_add_admin_notice("geo:import", "'{$prefix}entity_geometry' has been populated with information about the location of $i entities; geographic coordinates for $k entities were incorrect");
}