Geo_Location::UpdateOrder PHP Method

UpdateOrder() public static method

Updates the point ordering at the map NB: p_indices are used for the newly inserted points from the ajax request
public static UpdateOrder ( integer $p_mapId, array $p_reorder, array $p_indices ) : boolean
$p_mapId integer
$p_reorder array
$p_indices array
return boolean
    public static function UpdateOrder($p_mapId, $p_reorder, $p_indices)
    {
        global $g_ado_db;
        /*
            A)
                1) given article_number, language_id, map_id, list of content_ids with new contents
            B)
                cycle:
                    point order is shared between langages
                        1 a) read location_id of the content_id, if an old point
                        1 b) or get location_id from the new indices for new points
                        2) update rank on map_id/location_id
        */
        // ad B 2)
        $queryStr_rnk_up = 'UPDATE ' . Geo_MapLocation::TABLE . ' SET rank = ? WHERE id = ?';
        $rank = 0;
        foreach ($p_reorder as $poi_obj) {
            $rank += 1;
            $db_id = 0;
            $poi = get_object_vars($poi_obj);
            try {
                $state = $poi['state'];
                if ('new' == $state) {
                    // ad B 1 b)
                    $tmp_key = $poi['index'];
                    $db_id = $p_indices[$tmp_key]['maploc'];
                } else {
                    //ad B 1 a)
                    $db_id = 0 + $poi['location'];
                }
                $rnk_up_params = array();
                $rnk_up_params[] = $rank;
                $rnk_up_params[] = $db_id;
                $success = $g_ado_db->Execute($queryStr_rnk_up, $rnk_up_params);
            } catch (Exception $exc) {
                return false;
            }
        }
        return true;
    }

Usage Example

Beispiel #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_Location::UpdateOrder