Ejemplo n.º 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 bool $p_hasNextElements
	 * @return array
	 */
	protected function CreateList($p_start = 0, $p_limit = 0, array $p_parameters, &$p_count)
	{
	    $operator = new Operator('is');
	    $context = CampTemplate::singleton()->context();
	    $comparisonOperation = new ComparisonOperation('fk_poll_nr', $operator,
	                                                   $context->poll->number);
	    $this->m_constraints[] = $comparisonOperation;
	    
        $comparisonOperation = new ComparisonOperation('fk_language_id', $operator,
                                                        $context->poll->language_id);
	    $this->m_constraints[] = $comparisonOperation;

	    $pollAnswersList = PollAnswer::GetList($this->m_constraints, $this->m_order, $p_start, $p_limit, $p_count);
        $metaPollAnswersList = array();
	    foreach ($pollAnswersList as $pollAnswer) {
	        $metaPollAnswersList[] = new MetaPollAnswer($pollAnswer->getLanguageId(), $pollAnswer->getPollNumber(), $pollAnswer->getNumber());
	    }
	    return $metaPollAnswersList;
	}
Ejemplo n.º 2
0
    $poll->setProperty('date_end', $f_date_end);
    $poll->setProperty('votes_per_user', $f_votes_per_user);
    $poll->setProperty('nr_of_answers', $f_nr_of_answers);
    $poll->setProperty('is_extended', $f_is_extended);
    foreach ($f_answers as $nr_answer => $text) {
        if ($text !== '__undefined__') {
            $answer = new PollAnswer($f_fk_language_id, $f_poll_nr, $nr_answer);
            if ($answer->exists()) {
                $answer->setProperty('answer', $text);
            } else {
                $answer->create($text);
            }
        }
    }
    PollAnswer::SyncNrOfAnswers($f_fk_language_id, $f_poll_nr);
} else {
    // create new poll
    $poll = new Poll($f_fk_language_id);
    $success = $poll->create($f_title, $f_question, $f_date_begin, $f_date_end, $f_nr_of_answers, $f_votes_per_user);
    if ($success) {
        $poll->setProperty('is_extended', $f_is_extended);
        foreach ($f_answers as $nr_answer => $text) {
            if ($text !== '__undefined__') {
                $answer = new PollAnswer($f_fk_language_id, $poll->getNumber(), $nr_answer);
                $success = $answer->create($text);
            }
        }
    }
}
$f_from = Input::Get('f_from', 'string', 'index.php');
camp_html_goto_page($f_from);
Ejemplo n.º 3
0
 /**
  * Get array of answer objects for an poll
  *
  * @return array
  */
 public function getAnswers()
 {
     return PollAnswer::getAnswers($this->m_data['poll_nr'], $this->m_data['fk_language_id']);
 }
Ejemplo n.º 4
0
 /**
  * Create a copy of an answer set.
  *
  * @param int $p_fk_poll_nr
  * @param int $p_parent_nr
  * @param array $p_answers
  * @return Article
  */
 function CreateCopySet($p_poll_nr, $p_language_id, $p_parent_nr)
 {
     $ParentPoll = new Poll($p_language_id, $p_parent_nr);
     $parentAnswers = $ParentPoll->getAnswers();
     foreach ($parentAnswers as $ParentPollAnswer) {
         $TargetPollAnswer = new PollAnswer($p_language_id, $p_poll_nr, $ParentPollAnswer->getNumber());
         if ($TargetPollAnswer->exists()) {
             $parentPollAnswerAttachments = $ParentPollAnswer->getPollAnswerAttachments();
             foreach ($parentPollAnswerAttachments as $ParentPollAnswerAttachment) {
                 $TargetPollAnswerAttachment = new PollAnswerAttachment($p_poll_nr, $ParentPollAnswerAttachment->getProperty('fk_pollanswer_nr'), $ParentPollAnswerAttachment->getProperty('fk_attachment_id'));
                 $TargetPollAnswerAttachment->create();
             }
         }
     }
 }
Ejemplo n.º 5
0
    /**
     * Performs the action; returns true on success, false on error.
     *
     * @param $p_context - the current context object
     * @return bool
     */
    public function takeAction(CampContext &$p_context)
    {
        if (!is_object($this->m_poll)) {
            return false;   
        }
        
        // vote the poll
        $PollAnswer = new PollAnswer($this->m_properties['poll_language_id'], 
                                     $this->m_properties['poll_nr'],
                                     $this->m_properties['pollanswer_nr']);
        $PollAnswer->vote($this->m_properties['value']);
        
        // reset the f_pollanswer(_$nr) context vars             
        $p_context->default_url->reset_parameter('f_pollanswer_nr');
        $p_context->url->reset_parameter('f_pollanswer_nr');

        foreach ($this->m_poll->getAnswers() as $PollAnswer) {
            $nr = $PollAnswer->getNumber();
            $p_context->default_url->reset_parameter('f_pollanswer_'.$nr);
            $p_context->url->reset_parameter('f_pollanswer_'.$nr);
        }

        $this->m_error = ACTION_OK;       
        return true;
    }
Ejemplo n.º 6
0
		case 3: // UPLOAD_ERR_PARTIAL
			camp_html_display_error(getGS("The uploaded file was only partially uploaded. This is common when the maximum time to upload a file is low in contrast with the file size you are trying to input. The maximum input time is specified in 'php.ini'"), null, true);
			break;
		case 4: // UPLOAD_ERR_NO_FILE
			camp_html_display_error(getGS("You must select a file to upload."), null, true);
			break;
		case 6: // UPLOAD_ERR_NO_TMP_DIR
		case 7: // UPLOAD_ERR_CANT_WRITE
			camp_html_display_error(getGS("There was a problem uploading the file."), null, true);
			break;
	}
} else {
	camp_html_display_error(getGS("The file exceeds the allowed max file size."), null, true);
}

$PollAnswer = new PollAnswer($f_fk_language_id, $f_poll_nr, $f_pollanswer_nr);

if (!$PollAnswer->exists()) {
	camp_html_display_error(getGS("Poll Answer $1 does not exist.", $f_pollanswer_nr), null, true);
	exit;
}

$description = new Translation($f_language_id);
$description->create($f_description);

$attributes = array();
$attributes['fk_description_id'] = $description->getPhraseId();
$attributes['fk_user_id'] = $g_user->getUserId();
if ($f_language_specific == "yes") {
	$attributes['fk_language_id'] = $f_language_id;
}
Ejemplo n.º 7
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 $issuesList
     *    An array of Issue objects
     */
    public static function GetList(array $p_parameters, $p_order = null, $p_start = 0, $p_limit = 0, &$p_count)
    {
        global $g_ado_db;
        $hasPollNr = false;
        $hasLanguageId = fase;
        $selectClauseObj = new SQLSelectClause();

        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) {
                $hasPollNr = true;
            }
            if (strpos($comparisonOperation['left'], 'language_id') !== false) {
                $hasLanguageId = true;
            }
            $whereCondition = $comparisonOperation['left'] . ' '
                . $comparisonOperation['symbol'] . " '"
                . $g_ado_db->escape($comparisonOperation['right']) . "' ";
            $selectClauseObj->addWhere($whereCondition);
        }

        // validates whether publication identifier was given
        if ($hasPollNr == false) {
            CampTemplate::singleton()->trigger_error('missed parameter Poll Number in statement list_pollanswers');
            return;
        }
        // validates whether language identifier was given
        if ($hasLanguageId == false) {
            CampTemplate::singleton()->trigger_error('missed parameter Language Identifier in statement list_pollanswers');
            return;
        }

        // sets the columns to be fetched
        $tmpPollAnswer = new PollAnswer();
		$columnNames = $tmpPollAnswer->getColumnNames(true);
        foreach ($columnNames as $columnName) {
            $selectClauseObj->addColumn($columnName);
        }

        // sets the main table for the query
        $mainTblName = $tmpPollAnswer->getDbTableName();
        $selectClauseObj->setTable($mainTblName);
        unset($tmpPollAnswer);

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

        // sets the ORDER BY condition
        $p_order = count($p_order) > 0 ? $p_order : PollAnswer::$s_defaultOrder;
        $order = PollAnswer::ProcessListOrder($p_order);
        foreach ($order as $orderColumn => $orderDirection) {
            $selectClauseObj->addOrderBy($orderColumn . ' ' . $orderDirection);
        }

        $sqlQuery = $selectClauseObj->buildQuery();

        // count all available results
        $countRes = $g_ado_db->Execute($sqlQuery);
        $p_count = $countRes->recordCount();

        //get the wanted rows
        $pollAnswerRes = $g_ado_db->Execute($sqlQuery);

        // builds the array of poll objects
        $pollAnswersList = array();
        while ($pollAnswer = $pollAnswerRes->FetchRow()) {
            $pollAnswerObj = new PollAnswer($pollAnswer['fk_language_id'], $pollAnswer['fk_poll_nr'], $pollAnswer['nr_answer']);
            if ($pollAnswerObj->exists()) {
                $pollAnswersList[] = $pollAnswerObj;
            }
        }

        return $pollAnswersList;
    } // fn GetList
Ejemplo n.º 8
0
$f_poll_nr = Input::Get('f_poll_nr', 'int');
$f_fk_language_id = Input::Get('f_fk_language_id', 'int');
$f_answers = Input::Get('f_answer', 'array');
$f_copy_statistics = Input::Get('f_copy_statistics', 'boolean');

$data = array(
    'title' => Input::Get('f_title', 'string'),
    'question' => Input::Get('f_question', 'string'),
    'date_begin' => Input::Get('f_date_begin', 'string'),
    'date_end' => Input::Get('f_date_end', 'string'),
    'votes_per_user' => Input::Get('f_votes_per_user', 'int'),
);

foreach ($f_answers as $answer) {
    if (isset($answer['number']) && !empty($answer['number']) && strlen($answer['text'])) {
        $PollAnswer = new PollAnswer($f_fk_language_id, $f_poll_nr, $answer['number']);
        $answers[] = array(
            'number' => $answer['number'],
            'text' => $answer['text'],
            'nr_of_votes' => $f_copy_statistics ? $PollAnswer->getProperty('nr_of_votes') : 0,
            'value' => $f_copy_statistics ? $PollAnswer->getProperty('value') : 0,
        );
    }
}

$source = new Poll($f_fk_language_id, $f_poll_nr);
$copy = $source->createCopy($data, $answers);

/*
foreach($translation->getAnswers() as $answer) {
    $answer->setProperty('answer', $f_answers[$answer->getNumber()]);