Geo_Map::InsertPoints PHP Method

InsertPoints() public static method

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.
public static InsertPoints ( integer $p_mapId, integer $p_languageId, integer $p_articleNumber, array $p_insertion, array &$p_indices ) : array
$p_mapId integer
$p_languageId integer
$p_articleNumber integer
$p_insertion array
$p_indices array
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
        */
        // removed cause params are not properly processed atm
        // 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)
                $queryStr_loc_in = 'INSERT INTO Locations (poi_location, poi_type, poi_type_style, poi_center, poi_radius, IdUser) VALUES (';
                $queryStr_loc_in .= "GeomFromText('POINT(" . $poi['latitude'] . " " . $poi['longitude'] . ")'), 'point', 0, PointFromText('POINT(" . $poi['latitude'] . " " . $poi['longitude'] . ")'), 0, %%user_id%%";
                $queryStr_loc_in .= ')';
                // 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);
                // 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;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * The main dispatcher for ajax based editing of maps
  *
  * @param int $p_mapId
  * @param int $p_languageId
  * @param int $p_articleNumber
  * @param mixed $p_map
  * @param mixed $p_remove
  * @param mixed $p_insert
  * @param mixed $p_locations
  * @param mixed $p_contents
  * @param mixed $p_order
  *
  * @return array
  */
 public static function StoreMapData($p_mapId, $p_languageId, $p_articleNumber, $p_map = '', $p_remove = '', $p_insert = '', $p_locations = '', $p_contents = '', $p_order = '')
 {
     Geo_MapLocation::CleanFound();
     $security_problem = array('status' => '403', 'description' => 'Invalid security token!');
     $unknown_request = array('status' => '404', 'description' => 'Unknown request!');
     $data_wrong = array('status' => '404', 'description' => 'Wrong data.');
     $status = true;
     if ('' != $p_map) {
         $map_data = array();
         try {
             $p_map = str_replace('%2B', '+', $p_map);
             $p_map = str_replace('%2F', '/', $p_map);
             $map_json = base64_decode($p_map);
             $map_data = json_decode($map_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Map::UpdateMap($p_mapId, $p_articleNumber, $map_data);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     if ('' != $p_remove) {
         $remove_data = array();
         try {
             $p_remove = str_replace('%2B', '+', $p_remove);
             $p_remove = str_replace('%2F', '/', $p_remove);
             $remove_json = base64_decode($p_remove);
             $remove_data = json_decode($remove_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Map::RemovePoints($p_mapId, $remove_data);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     $new_ids = array();
     if ('' != $p_insert) {
         $insert_data = array();
         try {
             $p_insert = str_replace('%2B', '+', $p_insert);
             $p_insert = str_replace('%2F', '/', $p_insert);
             $insert_json = base64_decode($p_insert);
             $insert_data = json_decode($insert_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Map::InsertPoints($p_mapId, $p_languageId, $p_articleNumber, $insert_data, $new_ids);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     if ('' != $p_locations) {
         $locations_data = array();
         try {
             $p_locations = str_replace('%2B', '+', $p_locations);
             $p_locations = str_replace('%2F', '/', $p_locations);
             $locations_json = base64_decode($p_locations);
             $locations_data = json_decode($locations_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Location::UpdateLocations($p_mapId, $locations_data);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     if ('' != $p_contents) {
         $contents_data = array();
         try {
             $p_contents = str_replace('%2B', '+', $p_contents);
             $p_contents = str_replace('%2F', '/', $p_contents);
             $contents_json = base64_decode($p_contents);
             $contents_data = json_decode($contents_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Location::UpdateContents($p_mapId, $contents_data);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     if ('' != $p_order) {
         $order_data = array();
         try {
             $p_order = str_replace('%2B', '+', $p_order);
             $p_order = str_replace('%2F', '/', $p_order);
             $order_json = base64_decode($p_order);
             $order_data = json_decode($order_json);
         } catch (Exception $exc) {
             $status = false;
         }
         if ($status) {
             $status = Geo_Location::UpdateOrder($p_mapId, $order_data, $new_ids);
         }
     }
     if (!$status) {
         return $data_wrong;
     }
     $geo_map_usage = Geo_Map::ReadMapInfo('map', $p_mapId);
     $poi_count = 0;
     $p_constraints = array();
     $leftOperand = 'as_array';
     $rightOperand = true;
     $operator = new Operator('is', 'php');
     $constraint = new ComparisonOperation($leftOperand, $operator, $rightOperand);
     $p_constraints[] = $constraint;
     $leftOperand = 'preview';
     $rightOperand = false;
     $operator = new Operator('is', 'php');
     $constraint = new ComparisonOperation($leftOperand, $operator, $rightOperand);
     $p_constraints[] = $constraint;
     $leftOperand = 'text_only';
     $rightOperand = false;
     $operator = new Operator('is', 'php');
     $constraint = new ComparisonOperation($leftOperand, $operator, $rightOperand);
     $p_constraints[] = $constraint;
     $leftOperand = 'language';
     $rightOperand = $p_languageId;
     $operator = new Operator('is', 'php');
     $constraint = new ComparisonOperation($leftOperand, $operator, $rightOperand);
     $p_constraints[] = $constraint;
     $leftOperand = 'map';
     $rightOperand = $p_mapId;
     $operator = new Operator('is', 'php');
     $constraint = new ComparisonOperation($leftOperand, $operator, $rightOperand);
     $p_constraints[] = $constraint;
     $found_list = array();
     $found_objs = Geo_MapLocation::GetListExt($p_constraints, (array) null, 0, 0, $poi_count, false, $found_list);
     $res_array = array('status' => '200', 'pois' => $found_list, 'map' => $geo_map_usage);
     return $res_array;
 }
All Usage Examples Of Geo_Map::InsertPoints