示例#1
0
	/**
	 * 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)
	{
	    $operator = new Operator('is', 'integer');
	    $context = CampTemplate::singleton()->context();
	    
	    if (!$context->blog->defined) {
	        return array();
	    }
	    
	    $comparisonOperation = new ComparisonOperation('fk_blog_id', $operator, $context->blog->identifier);
	    $this->m_constraints[] = $comparisonOperation;

	    $blogTopicsList = BlogTopic::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
	    $metaTopicsList = array();
	    
	    foreach ($blogTopicsList as $topic) {
	        $metaTopicsList[] = new MetaTopic($topic->getTopicId());
	    }
	    
	    return $metaTopicsList;
	}
示例#2
0
    /**
     * Returns an blog topics 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 $blogTopicsList
     *    An array of Topic objects
     */
    public static function GetList(array $p_parameters, $p_order = null,
                                   $p_start = 0, $p_limit = 0, &$p_count)
    {
        global $g_ado_db;

        $selectClauseObj = new SQLSelectClause();
        $countClauseObj = new SQLSelectClause();

        // processes the parameters
        foreach ($p_parameters as $parameter) {
            $comparisonOperation = self::ProcessListParameters($parameter);
            if (sizeof($comparisonOperation) < 1) {
                break;
            }

            if (strpos($comparisonOperation['left'], 'fk_blog_id') !== false) {
                $hasBlogId = true;
            }
            $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            $selectClauseObj->addWhere($whereCondition);
            $countClauseObj->addWhere($whereCondition);
        }

        // validates whether blog number was given
        if ($hasBlogId == false) {
            CampTemplate::singleton()->trigger_error("missed parameter Blog Number in statement list_blog_topics");
            return array();
        }

        // sets the main table and columns to be fetched
        $tmpBlogTopic = new BlogTopic();
        $selectClauseObj->setTable($tmpBlogTopic->getDbTableName());
        $selectClauseObj->addColumn('fk_topic_id');
        $countClauseObj->setTable($tmpBlogTopic->getDbTableName());
        $countClauseObj->addColumn('COUNT(*)');
        unset($tmpBlogTopic);

        if (!is_array($p_order)) {
            $p_order = array();
        }

        // sets the order condition if any
        foreach ($p_order as $orderColumn => $orderDirection) {
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }

        // sets the limit
        $selectClauseObj->setLimit($p_start, $p_limit);

        // builds the query and executes it
        $selectQuery = $selectClauseObj->buildQuery();
        $topics = $g_ado_db->GetAll($selectQuery);
        if (!is_array($topics)) {
            return array();
        }
        $countQuery = $countClauseObj->buildQuery();
        $p_count = $g_ado_db->GetOne($countQuery);

        // builds the array of topic objects
        $blogTopicsList = array();
        foreach ($topics as $topic) {
            $topObj = new Topic($topic['fk_topic_id']);
            if ($topObj->exists()) {
                $blogTopicsList[] = $topObj;
            }
        }

        return $blogTopicsList;
    } // fn GetList
示例#3
0
 public function getTopics()
 {
     foreach (BlogTopic::getAssignments($this->m_data['blog_id']) as $BlogTopic) {
         $topics[] = $BlogTopic->getTopic();
     }
     return (array) $topics;
 }