/** * 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; }
/** * 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; }