/** * 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(); if ($context->language->number) { $comparisonOperation = new ComparisonOperation('language_id', $operator, $context->language->number); $this->m_constraints[] = $comparisonOperation; } $comparisonOperation = new ComparisonOperation('_assign_publication_id', $operator, $context->publication->identifier); $this->m_constraints[] = $comparisonOperation; $comparisonOperation = new ComparisonOperation('_assign_issue_nr', $operator, $context->issue->number); $this->m_constraints[] = $comparisonOperation; $comparisonOperation = new ComparisonOperation('_assign_section_nr', $operator, $context->section->number); $this->m_constraints[] = $comparisonOperation; $comparisonOperation = new ComparisonOperation('_assign_article_nr', $operator, $context->article->number); $this->m_constraints[] = $comparisonOperation; if (isset($p_parameters['number'])) { $comparisonOperation = new ComparisonOperation('number', $operator, $p_parameters['number']); $this->m_constraints[] = $comparisonOperation; } $user = $context->user; /* @var $user MetaUser */ $debatesList = Debate::GetList($this->m_constraints, $this->m_item, $this->m_order, $p_start, $p_limit, $p_count); $metaDebatesList = array(); foreach ($debatesList as $debate) { $metaDebatesList[] = new MetaDebate($debate->getLanguageId(), $debate->getNumber(), $user->identifier); } return $metaDebatesList; }
/** * 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) { $context = CampTemplate::singleton()->context(); $debate = new Debate($context->debate->language_id, $context->debate->number); // the template current debate switch ($debate->getProperty('results_time_unit')) { case 'daily': $rangeUnit = 86400; break; case 'weekly': $rangeUnit = 604800; break; case 'monthly': $rangeUnit = 2629744; break; } $dateStart = $context->debate->date_begin; $dateEnd = $p_limit != 0 ? strtotime(strftime('%D', $dateStart) . ' + ' . ($p_limit - 1) . ' days') : $context->debate->date_end; $dateRange = array($dateStart); $dateStartString = strftime('%F %T', $dateStart); while (current($dateRange) < $dateEnd) { $dateRange[] = strtotime($dateStartString . ' + 1 day'); $dateStartString = strftime('%F %T', next($dateRange)); } // @todo check the end range here for daylight savings time thing also.. $dateVotes = DebateVote::getResults($context->debate->number, $context->debate->language_id, $dateStart, $dateEnd + 86399); $dateResults = array(); foreach ($dateRange as $timestamp) { $found = 0; foreach ($dateVotes as $vote) { if (strftime('%D', $vote['time']) == strftime('%D', $timestamp)) { $found = $vote; break; } } if ($found) { $dateResults[] = $found; } else { $dateResults[] = array('time' => $timestamp, 'total_count' => 0); } } $dateArray = array(); foreach ($dateResults as $date) { $dateArray[] = new MetaDebateDays($date); } return $dateArray; }
<?php camp_load_translation_strings("plugin_debate"); // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $allLanguages = Language::GetLanguages(); $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $debate = new Debate($f_fk_language_id, $f_debate_nr); if (!$debate->exists()) { camp_html_display_error(getGS('Debate does not exists.')); exit; } $title = $debate->getProperty('title'); $question = $debate->getProperty('question'); $date_begin = $debate->getProperty('date_begin'); $date_end = $debate->getProperty('date_end'); $fk_language_id = $debate->getProperty('fk_language_id'); $votes_per_user = $debate->getProperty('votes_per_user'); /* $topArray = array('Pub' => $publicationObj, 'Issue' => $issueObj, 'Section' => $sectionObj); camp_html_content_top(getGS('Add new article'), $topArray, true, false, array(getGS("Articles") => "/$ADMIN/articles/?f_publication_id=$f_publication_id&f_issue_number=$f_issue_number&f_section_number=$f_section_number&f_language_id=$f_language_id")); */ ?> <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" class="action_buttons" style="padding-top: 5px;"> <TR> <TD><A HREF="index.php"><IMG SRC="<?php
/** * Create a copy of an answer set. * * @param int $p_fk_debate_nr * @param int $p_parent_nr * @param array $p_answers * @return Article */ function CreateCopySet($p_debate_nr, $p_language_id, $p_parent_nr) { $ParentDebate = new Debate($p_language_id, $p_parent_nr); $parentAnswers = $ParentDebate->getAnswers(); foreach ($parentAnswers as $ParentDebateAnswer) { $TargetDebateAnswer = new DebateAnswer($p_language_id, $p_debate_nr, $ParentDebateAnswer->getNumber()); if ($TargetDebateAnswer->exists()) { $parentDebateAnswerAttachments = $ParentDebateAnswer->getDebateAnswerAttachments(); foreach ($parentDebateAnswerAttachments as $ParentDebateAnswerAttachment) { $TargetDebateAnswerAttachment = new DebateAnswerAttachment($p_debate_nr, $ParentDebateAnswerAttachment->getProperty('fk_debateanswer_nr'), $ParentDebateAnswerAttachment->getProperty('fk_attachment_id')); $TargetDebateAnswerAttachment->create(); } } } }
} $f_language_selected = Input::Get('f_language_selected', 'int'); $f_debate_limit = Input::Get('f_debate_limit', 'int', 20); $f_debate_offset = Input::Get('f_debate_offset', 'int', 0); $f_debate_order = Input::Get('f_debate_order', 'string', 'bynumber'); $parents = Debate::getDebates(array('language_id' => $f_language_selected, 'parent_debate_nr' => 0), null, $f_debate_offset, $f_debate_limit, $f_debate_order); $debates = array(); // add the copys foreach ($parents as $debate) { $debates[] = $debate; $copys = Debate::getDebates(array('language_id' => $debate->getLanguageId(), 'parent_debate_nr' => $debate->getNumber())); foreach ($copys as $debate) { $debates[] = $debate; } } $pager = new SimplePager(Debate::countDebates(), $f_debate_limit, "f_debate_offset", "index.php?f_debate_order={$f_debate_order}&", false); $allLanguages = Language::GetLanguages(); include_once $GLOBALS['g_campsiteDir'] . "/{$ADMIN_DIR}/javascript_common.php"; echo camp_html_breadcrumbs(array(array(getGS('Plugins'), $Campsite['WEBSITE_URL'] . '/admin/plugins/manage.php'), array(getGS('Debates'), ''))); // DO NOT DELETE!!! Needed for localizer // getGS("Debates"); ?> <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?> /js/campsite-checkbox.js"></script> <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" class="action_buttons" style="padding-top: 5px;"> <TR> <TD><A HREF="edit.php" ><IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"];
<?php camp_load_translation_strings("plugin_debate"); if (!SecurityToken::isValid()) { camp_html_display_error(getGS('Invalid security token!')); exit; } // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $f_debate_code = Input::Get('f_debate_code', 'array'); foreach ($f_debate_code as $code) { list($debate_nr, $fk_language_id) = explode('_', $code); $debate = new Debate($fk_language_id, $debate_nr); switch (Input::Get('f_debate_list_action', 'string')) { case 'delete': $debate->delete(); break; case 'reset': $debate->reset(); break; } } header('Location: index.php');
<?php camp_load_translation_strings("plugin_debate"); if (!SecurityToken::isValid()) { camp_html_display_error(getGS('Invalid security token!')); exit; } // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $debate = new Debate($f_fk_language_id, $f_debate_nr); $debate->delete(); header('Location: index.php'); exit;
public function vote($p_value = 1) { if (!settype($p_value, 'float')) { return false; } $debate = $this->getDebate(); $voted = $debate->getAlreadyVoted($this->getProperty('nr_answer')); $debate->userVote($this->getProperty('nr_answer')); if (!is_null($voted) && $voted != $this->getProperty('nr_answer')) { $otherAnswer = new DebateAnswer($this->getProperty('fk_language_id'), $this->getProperty('fk_debate_nr'), $voted); $otherAnswer->setProperty('nr_of_votes', $otherAnswer->getProperty('nr_of_votes') - 1); $otherValueVotes = $otherAnswer->getProperty('value') - $p_value; $otherAnswer->setProperty('value', $otherValueVotes < 0 ? 0 : $otherValueVotes); $otherNrVotes = $otherAnswer->getProperty('nr_of_votes'); $otherAnswer->setProperty('average_value', $otherNrVotes != 0 ? $otherAnswer->getProperty('value') / $otherNrVotes : 0); $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')); } elseif (is_null($voted)) { $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')); } $debate->increaseUserVoteCount(); Debate::triggerStatistics($this->m_data['fk_debate_nr']); }
/** * Called when debate is deleted * * @param int $p_fk_debate_nr */ public static function OnDebateDelete($p_fk_debate_nr) { if (count(Debate::getTranslations($p_debate_nr)) > 1) { return; } foreach (DebateSection::getAssignments($p_fk_debate_nr) as $record) { $record->delete(); } }
?> </b></a> </TD> </TR> <?php $f_debate_limit = Input::Get('f_debate_limit', 'int', 15); $f_debate_offset = Input::Get('f_debate_offset', 'int', 0); $f_debate_order = Input::Get('f_debate_order', 'string'); $f_debate_assigned = Input::Get('f_debate_assigned', 'string'); $constraints = array('language_id' => $f_language_id, 'publication_id' => $f_publication_id, 'issue_nr' => $f_issue_nr, 'section_nr' => $f_section_nr, 'article_nr' => $f_article_nr); $debates = Debate::getDebates($constraints, $f_debate_assigned, $f_debate_offset, $f_debate_limit, $f_debate_order); $param_string = "f_debate_item={$f_debate_item}&f_issue_nr={$f_issue_nr}&f_language_id={$f_language_id}&f_publication_id={$f_publication_id}"; $pager_params = "?{$param_string}&f_debate_order={$f_debate_order}&"; $pager = new SimplePager(Debate::countDebates($f_language_id), $f_debate_limit, "f_debate_offset", $pager_params, false); Debate::countDebates($f_language_id); ?> <tr> <td colspan="2" style="padding: 3px; background-color: #EEE; border-left: 1px solid #8baed1; border-right: 1px solid #8baed1;"> <?php echo $pager->render(); ?> </td> </tr> <tr> <td colspan="2" style="padding: 3px; background-color: #EEE; border-left: 1px solid #8baed1; border-right: 1px solid #8baed1;"> <TABLE BORDER="0" CELLSPACING="1" CELLPADDING="3" class="table_list" style="padding-top: 5px;" width="95%"> <?php $counter = 0;
<?php camp_load_translation_strings("plugin_debate"); // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $allLanguages = Language::GetLanguages(); $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_from = Input::Get('f_from', 'string', false); $debate = new Debate($f_fk_language_id, $f_debate_nr); if ($debate->exists()) { // edit existing debate $parent_debate_nr = $debate->getProperty('parent_debate_nr'); $is_extended = $debate->isExtended(); $title = $debate->getProperty('title'); $question = $debate->getProperty('question'); $date_begin = $debate->getProperty('date_begin'); $date_end = $debate->getProperty('date_end'); $time_begin = strftime('%H:%M', strtotime($date_begin)); $time_end = strftime('%H:%M', strtotime($date_end)); $date_begin = strftime('%Y-%m-%d', strtotime($date_begin)); $date_end = strftime('%Y-%m-%d', strtotime($date_end)); $nr_of_answers = $debate->getProperty('nr_of_answers'); $fk_language_id = $debate->getProperty('fk_language_id'); $votes_per_user = $debate->getProperty('votes_per_user'); $allow_not_logged_in = $debate->getProperty('allow_not_logged_in'); $results_time_unit = $debate->getProperty('results_time_unit'); $debate_answers = $debate->getAnswers();
/** * Reads the input parameters and vote the debate * * @param array $p_input */ public function __construct(array $p_input) { $this->m_defined = true; $this->m_name = 'debate'; if (!isset($p_input['f_debate_nr']) || empty($p_input['f_debate_nr'])) { $this->m_error = new PEAR_Error('The debate number is missing.', ACTION_DEBATE_ERR_NO_DEBATE_NUMBER); return false; } $this->m_properties['debate_nr'] = $p_input['f_debate_nr']; if (!isset($p_input['f_debate_language_id']) || empty($p_input['f_debate_language_id'])) { $this->m_error = new PEAR_Error('The debate language is missing.', ACTION_DEBATE_ERR_NO_LANGUAGE_ID); return false; } $this->m_properties['debate_language_id'] = $p_input['f_debate_language_id']; if ($p_input['f_debate_mode'] !== 'standard' && $p_input['f_debate_mode'] !== 'ajax') { $this->m_error = new PEAR_Error('The debate mode parameter is invalid.', ACTION_DEBATE_ERR_INVLID_MODE); return false; } $this->m_properties['debate_mode'] = $p_input['f_debate_mode']; $Debate = new Debate($this->m_properties['debate_language_id'], $this->m_properties['debate_nr']); if (!$Debate->exists()) { $this->m_error = new PEAR_Error('Debate does not exists.', ACTION_DEBATE_ERR_NOT_EXISTS); return false; } // need to check this by user also and here if I try to get the user from CampContext it breaks // if (!$Debate->isVotable()) { // $this->m_error = new PEAR_Error('Debate is not votable.', ACTION_DEBATE_ERR_NOT_VOTABLE); // syslog(LOG_WARNING, 221); // return false; // // } else { switch ($p_input['f_debate_mode']) { case 'ajax': $allowed_values = $_SESSION['camp_debate_maxvote'][$this->m_properties['debate_nr']][$this->m_properties['debate_language_id']]; if (!is_array($allowed_values)) { $this->m_error = new PEAR_Error('Invalid debate voting value.', ACTION_DEBATE_ERR_INVALID_VALUE); return false; } foreach ($Debate->getAnswers() as $DebateAnswer) { $nr = $DebateAnswer->getNumber(); if (isset($p_input['f_debateanswer_' . $nr]) && !empty($p_input['f_debateanswer_' . $nr])) { // check if value is valid if (!array_key_exists($p_input['f_debateanswer_' . $nr], $allowed_values[$nr])) { $this->m_error = new PEAR_Error('Invalid debate voting value.', ACTION_DEBATE_ERR_INVALID_VALUE); return false; } $this->m_properties['debateanswer_nr'] = $nr; $this->m_properties['value'] = $p_input['f_debateanswer_' . $nr]; break; } } if (!$this->m_properties['value']) { $this->m_error = new PEAR_Error('No answer value was given.', ACTION_DEBATE_ERR_NOANSWER_VALUE); return false; } break; case 'standard': if (!isset($p_input['f_debateanswer_nr']) || empty($p_input['f_debateanswer_nr'])) { $this->m_error = new PEAR_Error('Invalid debate voting value.', ACTION_DEBATE_ERR_INVALID_VALUE); return false; } $this->m_properties['debateanswer_nr'] = $p_input['f_debateanswer_nr']; $this->m_properties['value'] = 1; break; } // } $this->m_debate = $Debate; }
<?php camp_load_translation_strings("plugin_debate"); // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_nr_answer = Input::Get('f_nr_answer', 'int'); $debate = new Debate($f_fk_language_id, $f_debate_nr); $format = '%.2f'; $display[] = $debate; foreach ($debate->getTranslations() as $translation) { if ($translation->getLanguageId() != $debate->getLanguageId()) { $display[] = $translation; } } echo camp_html_breadcrumbs(array(array(getGS('Plugins'), $Campsite['WEBSITE_URL'] . '/admin/plugins/manage.php'), array(getGS('Debates'), $Campsite['WEBSITE_URL'] . '/admin/debate/index.php'), array(getGS('Result'), ''))); ?> <?php $answers = $debate->getAnswers($f_debate_nr, $f_fk_language_id); ?> <style type="text/css"> .results { border: 1px solid #ccc; margin: 0 30px 30px 30px;
<?php camp_load_translation_strings("plugin_debate"); // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $allLanguages = Language::GetLanguages(); $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); if ($f_debate_nr && $f_fk_language_id) { $debate = new Debate($f_fk_language_id, $f_debate_nr); if (Input::Get('submit', 'boolean')) { // create the hitlist } elseif ($debate->exists()) { $debate_nr = $debate->getNumber(); $title = $debate->getProperty('title'); $question = $debate->getProperty('question'); $date_begin = $debate->getProperty('date_begin'); $date_end = $debate->getProperty('date_end'); $nr_of_answers = $debate->getProperty('nr_of_answers'); $fk_language_id = $debate->getProperty('fk_language_id'); $is_display_expired = $debate->getProperty('is_display_expired'); $is_used_as_default = $debate->getProperty('is_used_as_default'); $debate_answers = $debate->getAnswers(); foreach ($debate_answers as $debate_answer) { $answers[$debate_answer->getProperty('nr_answer')] = $debate_answer->getProperty('answer'); } } }
/** * Get vote results * @param int $p_fk_debate_nr * @param int $p_fk_debate_lang * @param int $limit from end time backwards */ public function getResults($p_fk_debate_nr, $p_fk_debate_lang, $limit = null, $start = null) { $debate = new Debate($p_fk_debate_lang, $p_fk_debate_nr); $tunit = strtolower($debate->getProperty('results_time_unit')); $query = "\n \tSELECT\n\t\t\t\t`fk_debate_nr`,\n COUNT(`id_vote`) as `vote_cnt`,\n `fk_answer_nr`,\n %s `dg`,\n UNIX_TIMESTAMP(DATE(`added`)) `time`\n\t\t\tFROM `plugin_debate_vote`\n WHERE `fk_debate_nr` = '{$p_fk_debate_nr}' %s %s\n GROUP BY `dg`, `fk_answer_nr`\n ORDER BY `dg` ASC, `fk_answer_nr` ASC"; $sqlLimit = ''; if (!is_null($limit)) { $sqlLimit = "AND UNIX_TIMESTAMP(`added`) > {$limit}"; } $sqlStart = ''; if (!is_null($start)) { $sqlStart = "AND UNIX_TIMESTAMP(`added`) < {$start}"; } switch ($tunit) { case 'daily': $query = sprintf($query, "YEAR(added)*1000 + DAYOFYEAR(added)", $sqlLimit, $sqlStart); break; case 'weekly': $query = sprintf($query, "YEAR(added)*100 + WEEKOFYEAR(added)", $sqlLimit, $sqlStart); break; case 'monthly': $query = sprintf($query, "YEAR(added)*100 + MONTH(added)", $sqlLimit, $sqlStart); break; default: return array(); } global $g_ado_db; $sqlr = $g_ado_db->execute($query); $vote_total = 0; $tunit = null; $results = $current_result = array(); while ($row = $sqlr->fetchRow()) { if ($tunit != $row['dg']) { $tunit = $row['dg']; $current_result['total_count'] = $vote_total; $vote_total = 0; $current_result =& $results[]; $current_result['time'] = $row['time']; } $vote_total += $row['vote_cnt']; $current_result[] = array('answer_nr' => $row['fk_answer_nr'], 'value' => $row['vote_cnt']); } $current_result['total_count'] = $vote_total; return $results; }
<?php camp_load_translation_strings("plugin_debate"); // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $allLanguages = Language::GetLanguages(); $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $debate = new Debate($f_fk_language_id, $f_debate_nr); if ($debate->exists()) { foreach ($debate->getTranslations() as $translation) { $existing[$translation->getLanguageId()] = true; } $title = $debate->getProperty('title'); $question = $debate->getProperty('question'); $is_used_as_default = false; } echo camp_html_breadcrumbs(array(array(getGS('Plugins'), $Campsite['WEBSITE_URL'] . '/admin/plugins/manage.php'), array(getGS('Debates'), $Campsite['WEBSITE_URL'] . '/admin/debate/index.php'), array(getGS('Translate Debate'), ''))); ?> <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" class="action_buttons" style="padding-top: 5px;"> <TR> <TD><A HREF="index.php"><IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?> /left_arrow.png" BORDER="0"></A></TD> <TD><A HREF="index.php"><B><?php putGS("Debate List"); ?>
/** * 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; }
<?php camp_load_translation_strings("plugin_debate"); if (!SecurityToken::isValid()) { camp_html_display_error(getGS('Invalid security token!')); exit; } // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $f_debate_nr = Input::Get('f_debate_nr', 'int'); $f_fk_language_id = Input::Get('f_fk_language_id', 'int'); $f_target_language_id = Input::Get('f_target_language_id', 'int'); $f_title = Input::Get('f_title', 'string'); $f_question = Input::Get('f_question', 'string'); $f_answers = Input::Get('f_answer', 'array'); $Source = new Debate($f_fk_language_id, $f_debate_nr); $Translation = $Source->createTranslation($f_target_language_id, $f_title, $f_question); foreach ($Translation->getAnswers() as $answer) { $answer->setProperty('answer', $f_answers[$answer->getNumber()]); } header("Location: index.php"); exit;
camp_load_translation_strings("plugin_debate"); if (!SecurityToken::isValid()) { camp_html_display_error(getGS('Invalid security token!')); exit; } // Check permissions if (!$g_user->hasPermission('plugin_debate_admin')) { camp_html_display_error(getGS('You do not have the right to manage debates.')); exit; } $f_debate_nr = Input::Get('f_debate_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'])) { $DebateAnswer = new DebateAnswer($f_fk_language_id, $f_debate_nr, $answer['number']); $answers[] = array('number' => $answer['number'], 'text' => $answer['text'], 'nr_of_votes' => $f_copy_statistics ? $DebateAnswer->getProperty('nr_of_votes') : 0, 'value' => $f_copy_statistics ? $DebateAnswer->getProperty('value') : 0); } } $source = new Debate($f_fk_language_id, $f_debate_nr); $copy = $source->createCopy($data, $answers); /* foreach($translation->getAnswers() as $answer) { $answer->setProperty('answer', $f_answers[$answer->getNumber()]); } */ header("Location: index.php"); exit;
$debate->setProperty('is_extended', $f_is_extended); $debate->setProperty('allow_not_logged_in', $f_allow_not_logged_in); foreach ($f_answers as $nr_answer => $text) { if (trim($text) != '') { $answer = new DebateAnswer($f_fk_language_id, $f_debate_nr, $nr_answer); if ($answer->exists()) { $answer->setProperty('answer', $text); } else { $answer->create($text); } } } DebateAnswer::SyncNrOfAnswers($f_fk_language_id, $f_debate_nr); } else { // create new debate $debate = new Debate($f_fk_language_id); $f_date_begin = strftime("%F %H:%M:%S", strtotime($f_date_begin . " " . $f_time_begin)); $f_date_end = strftime("%F %H:%M:%S", strtotime($f_date_end . " " . $f_time_end)); $success = $debate->create($f_title, $f_question, $f_date_begin, $f_date_end, $f_nr_of_answers, $f_votes_per_user); if ($success) { $debate->setProperty('is_extended', $f_is_extended); foreach ($f_answers as $nr_answer => $text) { if (trim($text) != '') { $answer = new DebateAnswer($f_fk_language_id, $debate->getNumber(), $nr_answer); $success = $answer->create($text); } } } } $f_from = Input::Get('f_from', 'string', 'index.php'); header('Location: ' . $f_from);