/** * Returns map locations list based on the given parameters. * * @param array $p_parameters * An array of ComparionOperation objects * @param string $p_order * An array of columns and directions to order by * @param integer $p_start * The record number to start the list * @param integer $p_limit * The offset. How many records from $p_start will be retrieved. * * @return array of IGeoMapLocation */ public static function GetList(array $p_parameters, array $p_order = array(), $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false) { global $g_ado_db; $selectClauseObj = new SQLSelectClause(); $countClauseObj = new SQLSelectClause(); // set columns $tmpMapLoc = new self(NULL); $tmpLoc = new Geo_Location(NULL); $columnNames = array_merge($tmpMapLoc->getColumnNames(true), array_diff($tmpLoc->getColumnNames(true), array('Locations.id'))); foreach ($columnNames as $columnName) { $selectClauseObj->addColumn($columnName); } $selectClauseObj->addColumn('X(poi_location) as latitude'); $selectClauseObj->addColumn('Y(poi_location) as longitude'); $countClauseObj->addColumn('COUNT(*)'); // sets the base table $selectClauseObj->setTable($tmpMapLoc->getDbTableName()); $selectClauseObj->addJoin(sprintf('INNER JOIN `%s` ON fk_location_id = %s.id', $tmpLoc->getDbTableName(), $tmpLoc->getDbTableName())); $countClauseObj->setTable($tmpMapLoc->getDbTableName()); unset($tmpMapLoc); unset($tmpLoc); // process params foreach ($p_parameters as $param) { switch ($param->getLeftOperand()) { case 'article': $searchQuery = sprintf('fk_map_id IN (SELECT id FROM %s WHERE fk_article_number = %d)', Geo_Map::TABLE, $param->getRightOperand()); $selectClauseObj->addWhere($searchQuery); $countClauseObj->addWhere($searchQuery); break; } } // set order by rank and id $selectClauseObj->addOrderBy(self::TABLE . '.rank'); $selectClauseObj->addOrderBy(self::TABLE . '.id'); // sets the limit $selectClauseObj->setLimit($p_start, $p_limit); // builds the query and executes it $selectQuery = $selectClauseObj->buildQuery(); $rows = $g_ado_db->GetAll($selectQuery); $list = array(); $p_count = 0; if (is_array($rows)) { $countQuery = $countClauseObj->buildQuery(); $p_count = $g_ado_db->GetOne($countQuery); // builds the array of image objects foreach ($rows as $row) { $list[] = new self((array) $row); } } return $list; }
/** * 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; }
/** * Returns map locations list based on the given parameters. * * @param array $p_parameters * An array of ComparionOperation objects * @param array $p_order * An array of columns and directions to order by * @param integer $p_start * The record number to start the list * @param integer $p_limit * The offset. How many records from $p_start will be retrieved. * * @return array of IGeoMapLocation */ public static function GetList(array $p_parameters, array $p_order = array(), $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false) { global $g_ado_db; $list_spec = array('params' => $p_parameters, 'order' => $p_order, 'start' => $p_start, 'limit' => $p_limit, 'skip_cache' => $p_skipCache); $list_spec_str = serialize($list_spec); if (!$p_skipCache && !empty(self::$s_found_maplocations_list) && isset(self::$s_found_maplocations_list[$list_spec_str])) { $list_res_data = self::$s_found_maplocations_list[$list_spec_str]; $p_count = $list_res_data['count']; $list = $list_res_data['list']; return $list; } $selectClauseObj = new SQLSelectClause(); $countClauseObj = new SQLSelectClause(); // set columns $tmpMapLoc = new self(NULL); $tmpLoc = new Geo_Location(NULL); $columnNames = array_merge($tmpMapLoc->getColumnNames(true), array_diff($tmpLoc->getColumnNames(true), array('Locations.id'))); foreach ($columnNames as $columnName) { $selectClauseObj->addColumn($columnName); } $selectClauseObj->addColumn('X(poi_location) as latitude'); $selectClauseObj->addColumn('Y(poi_location) as longitude'); $countClauseObj->addColumn('COUNT(*)'); // sets the base table $selectClauseObj->setTable($tmpMapLoc->getDbTableName()); $selectClauseObj->addJoin(sprintf('INNER JOIN `%s` ON fk_location_id = %s.id', $tmpLoc->getDbTableName(), $tmpLoc->getDbTableName())); $countClauseObj->setTable($tmpMapLoc->getDbTableName()); unset($tmpMapLoc); unset($tmpLoc); // process params foreach ($p_parameters as $param) { switch ($param->getLeftOperand()) { case 'article': $searchQuery = sprintf('fk_map_id IN (SELECT id FROM %s WHERE fk_article_number = %d)', Geo_Map::TABLE, $param->getRightOperand()); $selectClauseObj->addWhere($searchQuery); $countClauseObj->addWhere($searchQuery); break; } } // set order by rank and id $selectClauseObj->addOrderBy(self::TABLE . '.rank'); $selectClauseObj->addOrderBy(self::TABLE . '.id'); // sets the limit $selectClauseObj->setLimit($p_start, $p_limit); // builds the query and executes it $selectQuery = $selectClauseObj->buildQuery(); $rows = $g_ado_db->GetAll($selectQuery); $list = array(); $p_count = 0; if (is_array($rows)) { $countQuery = $countClauseObj->buildQuery(); $p_count = $g_ado_db->GetOne($countQuery); foreach ($rows as $row) { $map_loc = new self((array) $row, true); $row['id'] = $row['fk_location_id']; $map_loc->location = new Geo_Location($row, true); $list[] = $map_loc; } } if (empty(self::$s_found_maplocations_list)) { self::$s_found_maplocations_list = array(); } self::$s_found_maplocations_list[$list_spec_str] = array('count' => $p_count, 'list' => $list); return $list; }