addJoin() публичный Метод

Adds a table join to the query.
public addJoin ( string $p_join ) : void
$p_join string The full join string including the ON condition
Результат void
Пример #1
0
	public static function SearchQuery($p_searchPhrase)
	{
	    global $g_ado_db;

	    $matchAll = false;
        $keywords = preg_split('/[\s,.-]/', $p_searchPhrase);
        if (isset($keywords[0]) && strtolower($keywords[0]) == '__match_all') {
            $matchAll = true;
            array_shift($keywords);
        }

        // set search keywords
        if ($matchAll && count($keywords) > 1) {
            $selectKeywordClauseObj = new SQLSelectClause();
            $selectKeywordClauseObj->addColumn('DISTINCT AI1.NrArticle');
            $selectKeywordClauseObj->addColumn('AI1.IdLanguage');
            $selectKeywordClauseObj->setTable('ArticleIndex AS AI1');
            $selectKeywordClauseObj->addJoin('LEFT JOIN KeywordIndex AS KI1 ON AI1.IdKeyword = KI1.Id');
            for ($tableIndex = 2; $tableIndex <= count($keywords); $tableIndex++) {
                $selectKeywordClauseObj->addJoin("LEFT JOIN ArticleIndex AS AI$tableIndex "
                    . "ON AI1.NrArticle = AI$tableIndex.NrArticle "
                    . "AND AI1.IdLanguage = AI$tableIndex.IdLanguage");
                $selectKeywordClauseObj->addJoin("LEFT JOIN KeywordIndex AS KI$tableIndex "
                    . "ON AI$tableIndex.IdKeyword = KI$tableIndex.Id");
            }

            $tableIndex = 1;
            foreach ($keywords as $keyword) {
                $keywordConstraint = "KI$tableIndex.Keyword = '" . $g_ado_db->escape($keyword) . "'";
                $selectKeywordClauseObj->addWhere($keywordConstraint);
                $tableIndex++;
            }
        } else {
            $selectKeywordClauseObj = new SQLSelectClause();
            $selectKeywordClauseObj->addColumn('DISTINCT AI1.NrArticle');
            $selectKeywordClauseObj->addColumn('AI1.IdLanguage');
            $selectKeywordClauseObj->setTable('ArticleIndex AS AI1');
            $selectKeywordClauseObj->addJoin('LEFT JOIN KeywordIndex AS KI1 ON AI1.IdKeyword = KI1.Id');

            foreach ($keywords as $keyword) {
                $keywordConstraint = "KI1.Keyword = '" . $g_ado_db->escape($keyword) . "'";
                $selectKeywordClauseObj->addConditionalWhere($keywordConstraint);
            }
        }

        return $selectKeywordClauseObj->buildQuery();
	}
Пример #2
0
    /**
     * Performs a search against the given article field using the given
     * keywords. Returns the list of articles matching the given criteria.
     *
     * @param array $p_keywords
     * @param string $p_fieldName - may be 'title' or 'author'
     * @param bool $p_matchAll - true if all keyword have to match
     * @param array $p_constraints
     * @param array $p_order
     * @param int $p_start - return results starting from the given order number
     * @param int $p_limit - return at most $p_limit rows
     * @param int $p_count - sets $p_count to the total number of rows in the search
     * @param bool $p_countOnly - if true returns only the total number of rows
     * @return array
     */
    public static function SearchByField(array $p_keywords,
                                         $p_fieldName,
                                         $p_matchAll = false,
                                         array $p_constraints = array(),
                                         array $p_order = array(),
                                         $p_start = 0,
                                         $p_limit = 0,
                                         &$p_count,
                                         $p_countOnly = false)
    {
        global $g_ado_db;

        static $searchFields = array(
                'title'=>array('table_fields'=>array('Name'),
                               'table'=>'Articles'),
                'author'=>array('table_fields'=>array('first_name', 'last_name'),
                                'table'=>'ArticleAuthors',
                                'join_fields'=>array('Number'=>'fk_article_number')));

        $fieldName = strtolower($p_fieldName);
        if (!array_key_exists($fieldName, $searchFields)) {
            return false;
        }

        $selectClauseObj = new SQLSelectClause();

        // set tables and joins between tables
        $selectClauseObj->setTable('Articles');

        $joinTable = $searchFields[$fieldName]['table'];
        if ($joinTable != 'Articles') {
            $selectClauseObj->addTableFrom($joinTable);
            foreach ($searchFields[$fieldName]['join_fields'] as
                       $leftJoinField=>$rightJoinField) {
                $selectClauseObj->addWhere("`Articles`.`$leftJoinField` = "
                                           . "`$joinTable`.`$rightJoinField`");
            }
            if ($fieldName == 'author') {
                $joinTable = 'Authors';
                $selectClauseObj->addTableFrom($joinTable);
                $selectClauseObj->addWhere("`ArticleAuthors`.`fk_author_id` = "
                                           . "`$joinTable`.`id`");
            }
        }

        foreach ($searchFields[$fieldName]['table_fields'] as $matchField) {
            $matchFields[] = "`$joinTable`.`$matchField`";
        }
        $matchCond = 'MATCH (' . implode(', ', $matchFields) . ") AGAINST ('";
        foreach ($p_keywords as $keyword) {
            $matchCond .= ($p_matchAll ? '+' : '') . $g_ado_db->escape($keyword) . ' ';
        }
        $matchCond .= "' IN BOOLEAN MODE)";
        $selectClauseObj->addWhere($matchCond);

        $joinTables = array();
        // set other constraints
        foreach ($p_constraints as $constraint) {
            $leftOperand = $constraint->getLeftOperand();
            $operandAttributes = explode('.', $leftOperand);
            if (count($operandAttributes) == 2) {
                $table = trim($operandAttributes[0]);
                if (strtolower($table) != 'articles') {
                    $joinTables[] = $table;
                }
            }
            $symbol = $constraint->getOperator()->getSymbol('sql');
            $rightOperand = "'" . $g_ado_db->escape($constraint->getRightOperand()) . "'";
            $selectClauseObj->addWhere("$leftOperand $symbol $rightOperand");
        }
        foreach ($joinTables as $table) {
            $selectClauseObj->addJoin("LEFT JOIN $table ON Articles.Number = $table.NrArticle");
        }

        // create the count clause object
        $countClauseObj = clone $selectClauseObj;

        // set the columns for the select clause
        $selectClauseObj->addColumn('Articles.Number');
        $selectClauseObj->addColumn('Articles.IdLanguage');
        $selectClauseObj->addColumn($matchCond . ' AS score');

        // set the order for the select clause
        $p_order = count($p_order) > 0 ? $p_order : Article::$s_defaultOrder;
        $order = Article::ProcessListOrder($p_order);
        $selectClauseObj->addOrderBy('score DESC');
        foreach ($order as $orderDesc) {
            $orderField = $orderDesc['field'];
            $orderDirection = $orderDesc['dir'];
            $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
        }

        // sets the LIMIT start and offset values
        $selectClauseObj->setLimit($p_start, $p_limit);

        // set the column for the count clause
        $countClauseObj->addColumn('COUNT(*)');

        $articlesList = array();
        if (!$p_countOnly) {
            $selectQuery = $selectClauseObj->buildQuery();
            $articles = $g_ado_db->GetAll($selectQuery);
            foreach ($articles as $article) {
                $articlesList[] = new Article($article['IdLanguage'], $article['Number']);
            }
        }
        $countQuery = $countClauseObj->buildQuery();
        $p_count = $g_ado_db->GetOne($countQuery);
        return $articlesList;
    }
Пример #3
0
 /**
  * Gets an issue list based on the given parameters.
  *
  * @param array $p_parameters
  *    An array of ComparisonOperation objects
  * @param string item
  *    An indentifier which assignment should be used (publication/issue/section/article)
  * @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 $issuesList
  *    An array of Issue objects
  */
 public static function GetList(array $p_parameters, $p_item = null, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count)
 {
     global $g_ado_db;
     if (!is_array($p_parameters)) {
         return null;
     }
     // adodb::selectLimit() interpretes -1 as unlimited
     if ($p_limit == 0) {
         $p_limit = -1;
     }
     $selectClauseObj = new SQLSelectClause();
     // sets the where conditions
     foreach ($p_parameters as $param) {
         $comparisonOperation = self::ProcessListParameters($param);
         if (empty($comparisonOperation)) {
             continue;
         }
         if (strpos($comparisonOperation['left'], '_assign_publication_id') !== false) {
             $assign_publication_id = $comparisonOperation['right'];
         } elseif (strpos($comparisonOperation['left'], '_assign_issue_nr') !== false) {
             $assign_issue_nr = $comparisonOperation['right'];
         } elseif (strpos($comparisonOperation['left'], '_assign_section_nr') !== false) {
             $assign_section_nr = $comparisonOperation['right'];
         } elseif (strpos($comparisonOperation['left'], '_assign_article_nr') !== false) {
             $assign_article_nr = $comparisonOperation['right'];
         } elseif (strpos($comparisonOperation['left'], '_current') !== false) {
             $whereCondition = "date_begin <= NOW()";
             $selectClauseObj->addWhere($whereCondition);
             $whereCondition = "date_end >= NOW()";
             $selectClauseObj->addWhere($whereCondition);
         } elseif (strpos($comparisonOperation['left'], 'language_id') !== false) {
             $language_id = $comparisonOperation['right'];
             $whereCondition = $g_ado_db->escapeOperation($comparisonOperation);
             $selectClauseObj->addWhere($whereCondition);
         } else {
             $whereCondition = $g_ado_db->escapeOperation($comparisonOperation);
             $selectClauseObj->addWhere($whereCondition);
         }
     }
     // sets the columns to be fetched
     $tmpPoll = new Poll();
     $columnNames = $tmpPoll->getColumnNames(true);
     foreach ($columnNames as $columnName) {
         $selectClauseObj->addColumn($columnName);
     }
     // sets the main table for the query
     $mainTblName = $tmpPoll->getDbTableName();
     $selectClauseObj->setTable($mainTblName);
     unset($tmpPoll);
     switch ($p_item) {
         case 'publication':
             if (empty($assign_publication_id)) {
                 return;
             }
             $tmpAssignObj = new PollPublication();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_poll_nr = `{$mainTblName}`.poll_nr\n                            AND j.fk_publication_id = '{$assign_publication_id}'";
             $selectClauseObj->addJoin($join);
             $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_poll.poll_nr');
             break;
         case 'issue':
             if (empty($assign_publication_id) || empty($assign_issue_nr)) {
                 return;
             }
             $tmpAssignObj = new PollIssue();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN {$assignTblName} AS j\n                            ON\n                            j.fk_poll_nr = `{$mainTblName}`.poll_nr\n                            AND j.fk_issue_nr = '{$assign_issue_nr}'\n                            AND j.fk_publication_id = '{$assign_publication_id}'";
             if (isset($language_id)) {
                 $join .= " AND j.fk_issue_language_id = '{$language_id}'";
             }
             $selectClauseObj->addJoin($join);
             $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_poll.poll_nr');
             break;
         case 'section':
             if (empty($assign_publication_id) || empty($assign_issue_nr) || empty($assign_section_nr)) {
                 return;
             }
             $tmpAssignObj = new PollSection();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_poll_nr = `{$mainTblName}`.poll_nr\n                            AND j.fk_section_nr = '{$assign_section_nr}'\n                            AND j.fk_issue_nr = '{$assign_issue_nr}'\n                            AND j.fk_publication_id = '{$assign_publication_id}'";
             if (isset($language_id)) {
                 $join .= " AND j.fk_section_language_id = '{$language_id}'";
             }
             $selectClauseObj->addJoin($join);
             $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_poll.poll_nr');
             break;
         case 'article':
             if (empty($assign_article_nr)) {
                 return;
             }
             $tmpAssignObj = new PollArticle();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_poll_nr = `{$mainTblName}`.poll_nr\n                            AND j.fk_article_nr = '{$assign_article_nr}'";
             if (isset($language_id)) {
                 $join .= " AND j.fk_article_language_id = '{$language_id}'";
             }
             $selectClauseObj->addJoin($join);
             $selectClauseObj->addWhere('j.fk_poll_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_poll.poll_nr');
             break;
     }
     if (is_array($p_order)) {
         $order = Poll::ProcessListOrder($p_order);
         // sets the order condition if any
         foreach ($order as $orderField => $orderDirection) {
             $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
         }
     }
     $sqlQuery = $selectClauseObj->buildQuery();
     // count all available results
     $countRes = $g_ado_db->Execute($sqlQuery);
     $p_count = $countRes->recordCount();
     //get the wanted rows
     $pollRes = $g_ado_db->SelectLimit($sqlQuery, $p_limit, $p_start);
     // builds the array of poll objects
     $pollsList = array();
     while ($poll = $pollRes->FetchRow()) {
         $pollObj = new Poll($poll['fk_language_id'], $poll['poll_nr']);
         if ($pollObj->exists()) {
             $pollsList[] = $pollObj;
         }
     }
     return $pollsList;
 }
Пример #4
0
 /**
  * Returns an article authors list based on the given parameters.
  *
  * @param array $p_parameters
  *    An array of ComparisonOperation 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.
  * @param integer $p_count
  *    The total count of the elements; this count is computed without
  *    applying the start ($p_start) and limit parameters ($p_limit)
  *
  * @return array $articleAuthorsList
  *    An array of Author objects
  */
 public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count, $p_skipCache = false)
 {
     global $g_ado_db;
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $paramsArray['parameters'] = serialize($p_parameters);
         $paramsArray['order'] = is_null($p_order) ? 'order' : $p_order;
         $paramsArray['start'] = $p_start;
         $paramsArray['limit'] = $p_limit;
         $cacheListObj = new CampCacheList($paramsArray, __METHOD__);
         $articleAuthorsList = $cacheListObj->fetchFromCache();
         if ($articleAuthorsList !== false && is_array($articleAuthorsList)) {
             return $articleAuthorsList;
         }
     }
     $hasArticleNr = false;
     $selectClauseObj = new SQLSelectClause();
     $countClauseObj = new SQLSelectClause();
     // sets the where conditions
     foreach ($p_parameters as $param) {
         if ($param->getLeftOperand() == 'type') {
             $whereCondition = 'fk_type_id ' . $param->getOperator()->getSymbol() . ' (SELECT id FROM ' . AuthorType::TABLE . ' WHERE type="' . str_replace("'", "", $param->getRightOperand()) . '")';
             $selectClauseObj->addWhere($whereCondition);
             $countClauseObj->addWhere($whereCondition);
         }
         if ($param->getLeftOperand() == 'id') {
             $whereCondition = 'fk_author_id ' . $param->getOperator()->getSymbol() . ' ' . $param->getRightOperand();
             $selectClauseObj->addWhere($whereCondition);
             $countClauseObj->addWhere($whereCondition);
         }
         $comparisonOperation = self::ProcessListParameters($param);
         if (sizeof($comparisonOperation) < 1) {
             break;
         }
         switch (key($comparisonOperation)) {
             case 'fk_article_number':
                 $whereCondition = 'fk_article_number = ' . $comparisonOperation['fk_article_number'];
                 $hasArticleNr = true;
                 break;
             case 'fk_language_id':
                 $whereCondition = '(fk_language_id IS NULL OR ' . 'fk_language_id = ' . $comparisonOperation['fk_language_id'] . ')';
                 break;
         }
         $selectClauseObj->addWhere($whereCondition);
         $countClauseObj->addWhere($whereCondition);
     }
     // validates whether article number was given
     if ($hasArticleNr === false) {
         CampTemplate::singleton()->trigger_error("missed parameter Article Number in statement list_article_authors");
     }
     // sets the base table ArticleAuthors and the column to be fetched
     $tmpArticleAuthor = new ArticleAuthor();
     $selectClauseObj->setTable($tmpArticleAuthor->getDbTableName());
     $selectClauseObj->addJoin('JOIN ' . Author::TABLE . ' ON fk_author_id = id');
     $selectClauseObj->addColumn('fk_author_id');
     $selectClauseObj->addColumn('fk_type_id');
     $countClauseObj->setTable($tmpArticleAuthor->getDbTableName());
     $countClauseObj->addColumn('COUNT(*)');
     unset($tmpArticleAuthor);
     if (!is_array($p_order)) {
         $p_order = array();
     }
     $order = self::ProcessListOrder($p_order);
     // sets the order condition if any
     foreach ($order as $orderDesc) {
         $orderField = $orderDesc['field'];
         $orderDirection = $orderDesc['dir'];
         $selectClauseObj->addOrderBy($orderField . ' ' . $orderDirection);
     }
     // sets the limit
     $selectClauseObj->setLimit($p_start, $p_limit);
     // builds the query and executes it
     $selectQuery = $selectClauseObj->buildQuery();
     $authors = $g_ado_db->GetAll($selectQuery);
     if (is_array($authors)) {
         $countQuery = $countClauseObj->buildQuery();
         $p_count = $g_ado_db->GetOne($countQuery);
         // builds the array of attachment objects
         $authorsList = array();
         foreach ($authors as $author) {
             $authorObj = new Author($author['fk_author_id'], $author['fk_type_id']);
             if ($authorObj->exists()) {
                 $authorsList[] = $authorObj;
             }
         }
     } else {
         $authorsList = array();
         $p_count = 0;
     }
     if (!$p_skipCache && CampCache::IsEnabled()) {
         $cacheListObj->storeInCache($authorsList);
     }
     return $authorsList;
 }
Пример #5
0
    /**
     * 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;
    }
Пример #6
0
 public static function SearchQuery($p_searchPhrase, $p_symbol = null)
 {
     global $g_ado_db;
     $p_searchPhrase = trim($p_searchPhrase);
     if (empty($p_searchPhrase)) {
         return null;
     }
     $matchAll = false;
     $keywords = preg_split('/[\\s,.-]/', $p_searchPhrase);
     if (isset($keywords[0]) && strtolower($keywords[0]) == '__match_all') {
         $matchAll = true;
         array_shift($keywords);
     }
     $keywords = array_diff($keywords, array("", ""));
     $sKeys = array();
     foreach ($keywords as $keyword) {
         if (strlen($keyword) > 2) {
             $sKeys[] = $keyword;
         }
     }
     $keywords = $sKeys;
     if (count($keywords) < 1) {
         return null;
     }
     // specifically match webcode (first one)
     $webcodeMatches = preg_grep("`^\\s*[\\+@]`", $keywords);
     if (count($webcodeMatches)) {
         $wcode = ltrim(current($webcodeMatches), '@+');
         $za = Zend_Registry::get('container')->getService('webcode')->findArticleByWebcode($wcode);
         $article_no = $za->getId();
         if (is_numeric($article_no)) {
             $selectKeywordClauseObj = new SQLSelectClause();
             $selectKeywordClauseObj->addColumn('DISTINCT AI1.NrArticle');
             $selectKeywordClauseObj->addColumn('AI1.IdLanguage');
             $selectKeywordClauseObj->setTable('ArticleIndex AS AI1');
             $selectKeywordClauseObj->addConditionalWhere("AI1.NrArticle = '{$article_no}'");
         }
     } elseif ($matchAll && count($keywords) > 1) {
         $selectKeywordClauseObj = new SQLSelectClause();
         $selectKeywordClauseObj->addColumn('DISTINCT AI1.NrArticle');
         $selectKeywordClauseObj->addColumn('AI1.IdLanguage');
         $selectKeywordClauseObj->setTable('ArticleIndex AS AI1');
         $selectKeywordClauseObj->addJoin('LEFT JOIN KeywordIndex AS KI1 ON AI1.IdKeyword = KI1.Id');
         for ($tableIndex = 2; $tableIndex <= count($keywords); $tableIndex++) {
             $selectKeywordClauseObj->addJoin("LEFT JOIN ArticleIndex AS AI{$tableIndex} " . "ON AI1.NrArticle = AI{$tableIndex}.NrArticle " . "AND AI1.IdLanguage = AI{$tableIndex}.IdLanguage");
             $selectKeywordClauseObj->addJoin("LEFT JOIN KeywordIndex AS KI{$tableIndex} " . "ON AI{$tableIndex}.IdKeyword = KI{$tableIndex}.Id");
         }
         $tableIndex = 1;
         foreach ($keywords as $keyword) {
             $keywordConstraint = "KI{$tableIndex}.Keyword = '" . $g_ado_db->escape($keyword) . "'";
             $selectKeywordClauseObj->addWhere($keywordConstraint);
             $tableIndex++;
         }
     } else {
         $selectKeywordClauseObj = new SQLSelectClause();
         $selectKeywordClauseObj->addColumn('DISTINCT AI1.NrArticle');
         $selectKeywordClauseObj->addColumn('AI1.IdLanguage');
         $selectKeywordClauseObj->setTable('ArticleIndex AS AI1');
         $selectKeywordClauseObj->addJoin('LEFT JOIN KeywordIndex AS KI1 ON AI1.IdKeyword = KI1.Id');
         foreach ($keywords as $keyword) {
             if (strtolower($p_symbol) == 'like') {
                 $keywordConstraint = "KI1.Keyword LIKE " . $g_ado_db->escape('%' . $keyword . '%');
             } else {
                 $keywordConstraint = "KI1.Keyword = " . $g_ado_db->escape($keyword);
             }
             $selectKeywordClauseObj->addConditionalWhere($keywordConstraint);
         }
     }
     return $selectKeywordClauseObj->buildQuery();
 }
Пример #7
0
 /**
  * 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;
 }