Geo_MapLocation::GetList PHP Method

GetList() public static method

Returns map locations list based on the given parameters.
public static GetList ( array $p_parameters, array $p_order = [], integer $p_start, integer $p_limit, &$p_count, $p_skipCache = false ) : array
$p_parameters array An array of ComparionOperation objects
$p_order array An array of columns and directions to order by
$p_start integer The record number to start the list
$p_limit integer 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;
    }

Usage Example

 /**
  * Creates the list of objects. Sets the parameter $p_hasNextElements to
  * true if this list is limited and elements still exist in the original
  * list (from which this was truncated) after the last element of this
  * list.
  *
  * @param int $p_start
  * @param int $p_limit
  * @param array $p_parameters
  * @param int &$p_count
  * @return array
  */
 protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
 {
     $articleLocationsList = Geo_MapLocation::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
     $metaLocationsList = array();
     foreach ($articleLocationsList as $location) {
         $metaLocationsList[] = new MetaMapLocation($location);
     }
     return $metaLocationsList;
 }