private function getFormVote(WC_Challenge $chall, $has_solved, $userid) { $fun = $edu = $dif = 0; if ($has_solved) { if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_dif'), $userid))) { $dif = $vsr->getScore(); } if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_edu'), $userid))) { $edu = $vsr->getScore(); } if (false !== ($vsr = GWF_VoteScoreRow::getByUID($chall->getVar('chall_vote_fun'), $userid))) { $fun = $vsr->getScore(); } } $data = array('dif' => array(GWF_Form::INT, $dif, $this->module->lang('th_dif'), '', 2), 'edu' => array(GWF_Form::INT, $edu, $this->module->lang('th_edu'), '', 2), 'fun' => array(GWF_Form::INT, $fun, $this->module->lang('th_fun'), '', 2), 'vote' => array(GWF_Form::SUBMIT, $this->module->lang('btn_vote'))); return new GWF_Form($this, $data); }
function wcChallVotes(WC_Challenge $chall, $section) { $db = gdo_db(); # Init back; $back = array(); for ($i = 0; $i <= 10; $i++) { $back[$i] = array(0, 0); } $back[11] = array(0, 0.0); $total = 0; $count = 0; $vsr = GWF_TABLE_PREFIX . 'vote_score_row'; $vsid = $chall->getVar('chall_vote_' . $section); $query = "SELECT vsr_score, COUNT(vsr_uid) FROM {$vsr} WHERE vsr_vsid={$vsid} GROUP BY(vsr_score) ORDER BY vsr_score ASC"; // var_dump($query); if (false === ($result = $db->queryRead($query))) { return $back; } while (false !== ($row = $db->fetchRow($result))) { $cnt = (int) $row[1]; # 15 people $score = (int) $row[0]; # voted N $back[$score] = array($cnt, $score * $cnt); $total += $score * $cnt; $count += $cnt; } $db->free($result); if ($count === 0) { $count = 1.0E-8; } for ($i = 0; $i <= 10; $i++) { // $back[$i] = array($back[$i][0], $back[$i][1] / $total * 100); $back[$i] = array($back[$i][0], round($back[$i][0] / $count * 100, 2)); } if ($count > 0) { $back[11] = array($count, round($total / $count * 10, 2)); } // var_dump($back); return $back; }
public static function getLimitedHREF(WC_Challenge $chall, $length) { $challid = $chall->getVar('chall_id'); $token = self::calcToken($chall, $length); return GWF_WEB_ROOT . 'index.php?mo=WeChall&me=MathSolutions&cid=' . $challid . '&length=' . $length . '&token=' . $token; }
private function getForm(WC_Challenge $chall) { $buttons = array('edit' => $this->module->lang('btn_edit'), 'reset' => $this->module->lang('btn_reset'), 'delete' => $this->module->lang('btn_delete')); $data = array('score' => array(GWF_Form::INT, $chall->getVar('chall_score'), $this->module->lang('th_chall_score')), 'title' => array(GWF_Form::STRING, $chall->getVar('chall_title'), $this->module->lang('th_chall_title')), 'tags' => array(GWF_Form::STRING, $chall->getVar('chall_tags'), $this->module->lang('th_chall_tags')), 'url' => array(GWF_Form::STRING, $chall->getVar('chall_url'), $this->module->lang('th_chall_url')), 'solution' => array(GWF_Form::STRING, '', $this->module->lang('th_chall_solution')), 'creators' => array(GWF_Form::STRING, $chall->getVar('chall_creator_name'), $this->module->lang('th_chall_creator_name')), 'case_i' => array(GWF_Form::CHECKBOX, $chall->isCaseI(), $this->module->lang('th_chall_case_i')), 'cmd' => array(GWF_Form::SUBMITS, $buttons)); return new GWF_Form($this, $data); }