/** * Create a copy of an poll. * * @param string $p_title * @param string $p_question * @param array $p_answers * @return Poll */ public function createCopy($p_data, $p_answers) { // Construct the duplicate poll object. $poll_copy = new Poll(); $poll_copy->m_data['poll_nr'] = Poll::generatePollNumber(); $poll_copy->m_data['parent_poll_nr'] = $this->m_data['poll_nr']; $poll_copy->m_data['fk_language_id'] = $this->m_data['fk_language_id']; // Create the record $values = array('title' => $p_data['title'], 'question' => $p_data['question'], 'date_begin' => $p_data['date_begin'], 'date_end' => $p_data['date_end'], 'nr_of_answers' => count($p_answers), 'votes_per_user' => $p_data['votes_per_user']); $success = $poll_copy->__create($values); if (!$success) { return false; } // create an set of answers PollAnswer::CreateCopySet($poll_copy->getNumber(), $this->m_data['fk_language_id'], $this->m_data['poll_nr'], $p_answers); $poll_copy->triggerStatistics(); /* if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $logtext = getGS('Article #$1 "$2" ($3) translated to "$5" ($4)', $this->getArticleNumber(), $this->getTitle(), $this->getLanguageName(), $articleCopy->getTitle(), $articleCopy->getLanguageName()); Log::Message($logtext, null, 31); */ return $poll_copy; }
public function vote($p_value = 1) { if (!settype($p_value, 'float')) { return false; } $this->setProperty('nr_of_votes', $this->getProperty('nr_of_votes') + 1); $this->setProperty('value', $this->getProperty('value') + $p_value); $this->setProperty('average_value', $this->getProperty('value') / $this->getProperty('nr_of_votes')); $this->getPoll()->increaseUserVoteCount(); Poll::triggerStatistics($this->m_data['fk_poll_nr']); }