Example #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)
 {
     $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;
 }
Example #2
0
/**
 * Campsite debate_list block plugin
 *
 * Type:     block
 * Name:     debate_list
 * Purpose:  Create a list of available debates
 *
 * @param string
 *     $p_params
 * @param Smarty_Internal_Template
 *     $p_smarty
 * @param string
 *     $p_repeat
 *
 * @return
 *
 */
function smarty_function_debatevotes($p_params, &$p_smarty)
{
    // gets the context variable
    $campContext = $p_smarty->get_template_vars('gimme');
    /* @var $campContext \CampContext */
    $html = '';
    if ($campContext->current_list && $campContext->current_list->current instanceof MetaDebate) {
        $debate = $campContext->current_list->current;
        /* @var $debate MetaDebate */
        $results = DebateVote::getResults($debate->getNr(), $debate->getLanguageId());
        if (!isset($p_params['date_format'])) {
            switch ($debate->getResultsTimeUnit()) {
                case 'daily':
                    $dformat = '%e.%m.%y';
                    break;
                case 'weekly':
                    $dformat = '%W-%y';
                    break;
                case 'monthly':
                    $dformat = '%b-%y';
                    break;
            }
        } else {
            $dformat = $p_params['date_format'];
        }
        $html .= '<div class="debate-results">';
        foreach ($results as $resitem) {
            $html .= '<div class="debate-result-item">';
            $html .= '<div class="debate-result-item-values">';
            foreach ($results as $result) {
                if (!is_array($result)) {
                    continue;
                }
                $html .= '<div class="debate-result-item-answer-value"' . "style='height:'" . ($percentage = number_format($result['value'] * 100 / $results['total_count'], 2)) . "%'>" . $percentage . '%' . '</div>';
            }
            $html .= '<div class="bottom">' . strftime($p_params['date_format'], $results['time']) . '</div>' . '<div style="clear: both"></div>';
        }
        $html .= '</div>';
    }
    return $html;
}
Example #3
0
 /**
  * Reset all counters
  * @return void
  */
 public function reset()
 {
     DebateVote::deleteByDebate($this->getNumber());
     foreach ($this->getAnswers() as $PollAnswer) {
         $PollAnswer->setProperty('nr_of_votes', 0);
         $PollAnswer->setProperty('percentage', 0);
         $PollAnswer->setProperty('percentage_overall', 0);
         $PollAnswer->setProperty('value', 0);
         $PollAnswer->setProperty('average_value', 0);
         $this->setProperty('reset_token', sha1(uniqid()));
     }
     $this->triggerStatistics();
 }
Example #4
0
        break;
    case 'weekly':
        putGS('Week');
        $dformat = '%W-%y';
        break;
    case 'monthly':
        putGS('Month');
        $dformat = '%b-%y';
        break;
}
?>
    	</div>
	</div>

    <?php 
foreach (DebateVote::getResults($f_debate_nr, $f_fk_language_id) as $results) {
    ?>
    	<div class="item">
    		<div class="value">
        	<?php 
    foreach ($results as $result) {
        ?>
        		<?php 
        if (!is_array($result)) {
            continue;
        }
        ?>
        		<div class="division"
        			style="height:<?php 
        echo $percentage = number_format($result['value'] * 100 / $results['total_count'], 2);
        ?>