예제 #1
0
 /**
  * Gets an issue 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_count
  *    The count of answers.
  *
  * @return array $pollAnswerAttachmentsList
  *    An array of Attachment objects
  */
 public static function GetList(array $p_parameters, $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;
     }
     // sets the where conditions
     foreach ($p_parameters as $param) {
         $comparisonOperation = self::ProcessListParameters($param);
         if (empty($comparisonOperation)) {
             continue;
         }
         if (strpos($comparisonOperation['left'], 'poll_nr') !== false) {
             $poll_nr = $comparisonOperation['right'];
         }
         if (strpos($comparisonOperation['left'], 'pollanswer_nr') !== false) {
             $pollanswer_nr = $comparisonOperation['right'];
         }
     }
     $sqlClauseObj = new SQLSelectClause();
     // sets the columns to be fetched
     $tmpPollAnswerAttachment = new PollAnswerAttachment($language_id, $poll_nr);
     $columnNames = $tmpPollAnswerAttachment->getColumnNames(true);
     foreach ($columnNames as $columnName) {
         $sqlClauseObj->addColumn($columnName);
     }
     // sets the main table for the query
     $mainTblName = $tmpPollAnswerAttachment->getDbTableName();
     $sqlClauseObj->setTable($mainTblName);
     unset($tmpPollAnswerAttachment);
     if (empty($pollanswer_nr) || empty($poll_nr)) {
         return;
     }
     $sqlClauseObj->addWhere("fk_poll_nr = " . $g_ado_db->escape($poll_nr));
     $sqlClauseObj->addWhere("fk_pollanswer_nr = " . $g_ado_db->escape($pollanswer_nr));
     if (!is_array($p_order)) {
         $p_order = array();
     }
     // sets the ORDER BY condition
     $p_order = count($p_order) > 0 ? $p_order : self::$s_defaultOrder;
     $order = self::ProcessListOrder($p_order);
     foreach ($order as $orderColumn => $orderDirection) {
         $sqlClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
     }
     $sqlQuery = $sqlClauseObj->buildQuery();
     // count all available results
     $countRes = $g_ado_db->Execute($sqlQuery);
     $p_count = $countRes->recordCount();
     //get the wanted rows
     $pollAnswerAttachments = $g_ado_db->Execute($sqlQuery);
     // builds the array of poll objects
     $pollAnswerAttachmentsList = array();
     while ($pollAnswerAttachment = $pollAnswerAttachments->FetchRow()) {
         $pollAnswerAttachment = new Attachment($pollAnswerAttachment['fk_attachment_id']);
         if ($pollAnswerAttachment->exists()) {
             $pollAnswerAttachmentsList[] = $pollAnswerAttachment;
         }
     }
     return $pollAnswerAttachmentsList;
 }