Esempio n. 1
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);
         } elseif (strpos($comparisonOperation['left'], 'number') !== false) {
             $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 Debate();
     $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 DebatePublication();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_debate_nr = `{$mainTblName}`.debate_nr\n                            AND j.fk_publication_id = '{$assign_publication_id}'";
             $selectClauseObj->addJoin($join);
             $selectClauseObj->addWhere('j.fk_debate_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_debate.debate_nr');
             break;
         case 'issue':
             if (empty($assign_publication_id) || empty($assign_issue_nr)) {
                 return;
             }
             $tmpAssignObj = new DebateIssue();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN {$assignTblName} AS j\n                            ON\n                            j.fk_debate_nr = `{$mainTblName}`.debate_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_debate_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_debate.debate_nr');
             break;
         case 'section':
             if (empty($assign_publication_id) || empty($assign_issue_nr) || empty($assign_section_nr)) {
                 return;
             }
             $tmpAssignObj = new DebateSection();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_debate_nr = `{$mainTblName}`.debate_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_debate_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_debate.debate_nr');
             break;
         case 'article':
             if (empty($assign_article_nr)) {
                 return;
             }
             $tmpAssignObj = new DebateArticle();
             $assignTblName = $tmpAssignObj->getDbTableName();
             $join = "LEFT JOIN `{$assignTblName}` AS j\n                            ON\n                            j.fk_debate_nr = `{$mainTblName}`.debate_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_debate_nr IS NOT NULL');
             $selectClauseObj->setDistinct('plugin_debate.debate_nr');
             break;
     }
     if (is_array($p_order)) {
         $order = Debate::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);
     if (!is_null($countRes)) {
         $p_count = $countRes->recordCount();
     }
     //get the wanted rows
     $debateRes = $g_ado_db->SelectLimit($sqlQuery, $p_limit, $p_start);
     // builds the array of debate objects
     $debatesList = array();
     while ($debate = $debateRes->FetchRow()) {
         $debateObj = new Debate($debate['fk_language_id'], $debate['debate_nr']);
         if ($debateObj->exists()) {
             $debatesList[] = $debateObj;
         }
     }
     return $debatesList;
 }