Geo_Map::RemovePoints PHP Method

RemovePoints() public static method

Removes points (with locations and other contents) from the map.
public static RemovePoints ( integer $p_mapId, array $p_removal ) : boolean
$p_mapId integer
$p_removal array
return boolean
    public static function RemovePoints($p_mapId, $p_removal)
    {
        global $g_ado_db;
        Geo_MapLocation::CleanFound();
        /*
            A)
                1) provided: map_id, list of maploc_ids
            B)
                1) read all location_id from MapLocations where id=maploc_id;
                2) read all content_id from MapLocationLanguages where maploc_id;
                3) read all multimedia_id from MapLocationMultimedia where maploc_id;
            C)
                    1) delete from MapLocations where there are: id=maploc_id
                    2) delete from MapLocationLanguages where there are: maploc_id
                    3) delete from MapLocationMultimedia where fk_maplocation_id=maploc_id
            D)
                cycle:
                    1) delete from Locations where there are: id=location_id, and there is no location_id at MapLocations
                    2) delete from LocationContents where there are: id=content_id and there is no content_id at MapLocationLanguages
                    2) delete from Multimedia where there are: id=multimedia_id and there is no multimedia_id at MapLocationMultimedia
        */
        $map_loc_ids = array();
        foreach ($p_removal as $one_rem) {
            if (is_object($one_rem)) {
                $one_rem = get_object_vars($one_rem);
            }
            $val_rem = $one_rem['location_id'];
            if (is_numeric($val_rem)) {
                $id_rem = 0 + $val_rem;
                if (is_int($id_rem)) {
                    $map_loc_ids[] = $id_rem;
                }
            }
        }
        if (0 == count($map_loc_ids)) {
            return 0;
        }
        $map_loc_list = implode(', ', $map_loc_ids);
        $list_fill = '%%id_list%%';
        // ad B 1)
        $queryStr_maploc_sel = 'SELECT fk_location_id AS loc FROM MapLocations WHERE id IN (%%id_list%%)';
        // ad B 2)
        $queryStr_maploclan_sel = 'SELECT fk_content_id AS con FROM MapLocationLanguages WHERE fk_maplocation_id IN (%%id_list%%)';
        // ad B 3)
        $queryStr_maplocmed_sel = 'SELECT fk_multimedia_id AS med FROM MapLocationMultimedia WHERE fk_maplocation_id IN (%%id_list%%)';
        // ad C 1)
        $queryStr_maploc_del = 'DELETE FROM MapLocations WHERE id IN (%%id_list%%)';
        // ad C 2)
        $queryStr_maploclan_del = 'DELETE FROM MapLocationLanguages WHERE fk_maplocation_id IN (%%id_list%%)';
        // ad C 3)
        $queryStr_maplocmed_del = 'DELETE FROM MapLocationMultimedia WHERE fk_maplocation_id IN (%%id_list%%)';
        // ad D 1)
        $queryStr_locpos_del = 'DELETE FROM Locations WHERE id = ? AND NOT EXISTS (SELECT id FROM MapLocations WHERE fk_location_id = ?)';
        // ad D 2)
        $queryStr_loccon_del = 'DELETE FROM LocationContents WHERE id = ? AND NOT EXISTS (SELECT id FROM MapLocationLanguages WHERE fk_content_id = ?)';
        // ad D 3)
        $queryStr_locmed_del = 'DELETE FROM Multimedia WHERE id = ? AND NOT EXISTS (SELECT id FROM MapLocationMultimedia WHERE fk_multimedia_id = ?)';
        // ad B1)
        $location_ids = array();
        try {
            $maploc_sel_params = array();
            $queryStr_maploc_sel = str_replace($list_fill, $map_loc_list, $queryStr_maploc_sel);
            $rows = $g_ado_db->GetAll($queryStr_maploc_sel, $maploc_sel_params);
            if (is_array($rows)) {
                foreach ($rows as $row) {
                    $location_ids[] = $row['loc'];
                }
            }
        } catch (Exception $exc) {
            return false;
        }
        // ad B2)
        $content_ids = array();
        try {
            $maploclan_sel_params = array();
            $queryStr_maploclan_sel = str_replace($list_fill, $map_loc_list, $queryStr_maploclan_sel);
            $rows = $g_ado_db->GetAll($queryStr_maploclan_sel, $maploclan_sel_params);
            if (is_array($rows)) {
                foreach ($rows as $row) {
                    $content_ids[] = $row['con'];
                }
            }
        } catch (Exception $exc) {
            return false;
        }
        // ad B3)
        $media_ids = array();
        try {
            $maplocmed_sel_params = array();
            $queryStr_maplocmed_sel = str_replace($list_fill, $map_loc_list, $queryStr_maplocmed_sel);
            $rows = $g_ado_db->GetAll($queryStr_maplocmed_sel, $maplocmed_sel_params);
            if (is_array($rows)) {
                foreach ($rows as $row) {
                    $media_ids[] = $row['med'];
                }
            }
        } catch (Exception $exc) {
            return false;
        }
        // ad C 1)
        try {
            $maploc_del_params = array();
            $queryStr_maploc_del = str_replace($list_fill, $map_loc_list, $queryStr_maploc_del);
            $success = $g_ado_db->Execute($queryStr_maploc_del, $maploc_del_params);
        } catch (Exception $exc) {
            return false;
        }
        // ad C 2)
        try {
            $maploclan_del_params = array();
            $queryStr_maploclan_del = str_replace($list_fill, $map_loc_list, $queryStr_maploclan_del);
            $success = $g_ado_db->Execute($queryStr_maploclan_del, $maploclan_del_params);
        } catch (Exception $exc) {
            return false;
        }
        // ad C 3)
        try {
            $maplocmed_del_params = array();
            $queryStr_maplocmed_del = str_replace($list_fill, $map_loc_list, $queryStr_maplocmed_del);
            $success = $g_ado_db->Execute($queryStr_maplocmed_del, $maplocmed_del_params);
        } catch (Exception $exc) {
            return false;
        }
        // ad D 1)
        try {
            foreach ($location_ids as $one_loc) {
                $locpos_del_params = array();
                $locpos_del_params[] = $one_loc;
                $locpos_del_params[] = $one_loc;
                $success = $g_ado_db->Execute($queryStr_locpos_del, $locpos_del_params);
            }
        } catch (Exception $exc) {
            return false;
        }
        // ad D 2)
        try {
            foreach ($content_ids as $one_con) {
                $loccon_del_params = array();
                $loccon_del_params[] = $one_con;
                $loccon_del_params[] = $one_con;
                $success = $g_ado_db->Execute($queryStr_loccon_del, $loccon_del_params);
            }
        } catch (Exception $exc) {
            return false;
        }
        // ad D 3)
        try {
            foreach ($media_ids as $one_med) {
                $locmed_del_params = array();
                $locmed_del_params[] = $one_med;
                $locmed_del_params[] = $one_med;
                $success = $g_ado_db->Execute($queryStr_locmed_del, $locmed_del_params);
            }
        } catch (Exception $exc) {
            return false;
        }
        return true;
    }

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::RemovePoints