/**
* Inserts points (with locations and other contents) into the map.
* NB: The result indices are used at the point order updating, since that order-updating
* would not know id's of the new points otherwise.
*
* @param int $p_mapId
* @param int $p_languageId
* @param int $p_articleNumber
* @param array $p_insertion
* @param array $p_indices
*
* @return array
*/
public static function InsertPoints($p_mapId, $p_languageId, $p_articleNumber, $p_insertion, &$p_indices)
{
global $g_ado_db;
global $g_user;
Geo_MapLocation::CleanFound();
// this should not happen
if (0 == $p_mapId) {
return array();
}
/*
A)
1) given article_number, language_id, map_id, list of new data
2) read languages of the article
B)
cycle:
1) insert into Locations the new position
2) get inserted id as location_id
3) insert into LocationContents the most of the new data,
4) get inserted id as content_id
5) insert into MapLocations (map_id, location_id, data:style, rank=0)
6) get inserted id as maplocation_id
7) insert into MapLocationLanguages (maplocation_id, language_id, content_id, data:display)
ad 7) this for all languages, with display=false for the other ones
*/
// ad B 1)
$queryStr_loc_in = 'INSERT INTO Locations (poi_location, poi_type, poi_type_style, poi_center, poi_radius, IdUser) VALUES (';
$queryStr_loc_in .= "GeomFromText('POINT(? ?)'), 'point', 0, PointFromText('POINT(? ?)'), 0, %%user_id%%";
$queryStr_loc_in .= ')';
// ad B 3)
// ad B 5)
$queryStr_maploc = 'INSERT INTO MapLocations (fk_map_id, fk_location_id, poi_style, rank) ';
$queryStr_maploc .= 'VALUES (?, ?, ?, 0)';
// ad B 7)
$queryStr_maploclan = 'INSERT INTO MapLocationLanguages (fk_maplocation_id, fk_language_id, fk_content_id, poi_display) ';
$queryStr_maploclan .= 'VALUES (?, ?, ?, ?)';
if ($p_articleNumber) {
$languages = Geo_Map::ReadLanguagesByArticle($p_articleNumber);
} else {
$languages = Geo_Map::ReadLanguagesByMap($p_mapId);
}
foreach ($p_insertion as $poi) {
if (is_object($poi)) {
$poi = get_object_vars($poi);
}
$loc_id = null;
$new_loc = array();
$new_loc[] = array('latitude' => $poi['latitude'], 'longitude' => $poi['longitude']);
$new_cen = array('latitude' => $poi['latitude'], 'longitude' => $poi['longitude']);
$new_style = 0;
$new_radius = 0;
$reuse_id = Geo_Location::FindLocation($new_loc, 'point', $new_style, $new_cen, $new_radius);
if ($reuse_id && 0 < $reuse_id) {
$loc_id = $reuse_id;
} else {
// ad B 1)
$loc_in_params = array();
$loc_in_params[] = $poi['latitude'];
$loc_in_params[] = $poi['longitude'];
$loc_in_params[] = $poi['latitude'];
$loc_in_params[] = $poi['longitude'];
// the POI itself insertion
$queryStr_loc_in = str_replace('%%user_id%%', $g_user->getUserId(), $queryStr_loc_in);
$success = $g_ado_db->Execute($queryStr_loc_in, $loc_in_params);
// ad B 2)
// taking its ID for the next processing
$loc_id = $g_ado_db->Insert_ID();
}
// ad B 3/4)
$con_id = Geo_MapLocationContent::InsertContent($poi);
// ad B 5)
$maploc_params = array();
$maploc_params[] = $p_mapId;
$maploc_params[] = $loc_id;
$maploc_params[] = '' . $poi['style'];
// the map-point link insertion
$success = $g_ado_db->Execute($queryStr_maploc, $maploc_params);
// ad B 6)
$maploc_id = $g_ado_db->Insert_ID();
Geo_Multimedia::InsertMultimedia($maploc_id, $poi);
// ad B 7)
$maploclan_params = array();
$maploclan_params[] = $maploc_id;
$maploclan_params[] = 0 + $p_languageId;
$maploclan_params[] = $con_id;
$maploclan_params[] = 0 + $poi['display'];
// the map-point link insertion
$success = $g_ado_db->Execute($queryStr_maploclan, $maploclan_params);
$poi_index = $poi['index'];
$p_indices[$poi_index] = array('maploc' => $maploc_id);
// insert the POI content for the other article's languages
foreach ($languages as $one_lang) {
if ($one_lang == $p_languageId) {
continue;
}
$maploclan_params[1] = $one_lang;
$maploclan_params[3] = 0;
// false; // display;
$success = $g_ado_db->Execute($queryStr_maploclan, $maploclan_params);
}
// if a new POI, then that's all for it here
continue;
}
return $p_indices;
}