Re: UQM 2.0 - Predictions Extensions
Posted: Fri Jan 22, 2010 1:42 pm
Not as yet, didnt want to try and confuse different issues, and at the moment my hosts phpMyAdmin interface seems to be down
Tech discussion, website creation and the world's best OT Forum!
https://forums.cricketmx.com/
Code: Select all
<?php
// subvertbeats_quiz.php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
if( !$auth->acl_get('a_') )
{
die('No access');
}
else
{
if( $_GET['mode'] == 'deactivate' )
{
$deactivate_id = (int) $_GET['id'];
$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
WHERE quiz_id = $deactivate_id";
$db->sql_query($sql);
die('Quiz id ' . $deactivate_id . ' has been deactivated');
}
if( $_GET['mode'] == 'activate' )
{
$activate_id = (int) $_GET['id'];
$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
WHERE quiz_id = $activate_id";
$db->sql_query($sql);
die('Quiz id ' . $activate_id . ' has been activated');
}
if( $_GET['mode'] == 'enter_answers' )
{
if( $_GET['a'] == 'submit' )
{
$question_id_hidden = $_POST['questions'];
$question_id_set = explode(',', $question_id_hidden);
$question_id_set_count = sizeof($question_id_set) - 1;
$users = array();
$users_information = array();
$users_names = array();
for($i = 0; $i < $question_id_set_count; $i++ )
{
$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
WHERE quiz_question_id = ' . $question_id_set[$i];
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) )
{
$users[$i] = $row['quiz_player'];
$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
WHERE user_id = ' . $row['quiz_player'];
$user_result = $db->sql_query($user_sql);
$user_name_fetch = $db->sql_fetchfield('username');
$db->sql_freeresult($user_result);
$users_names[$row['quiz_player']] = $user_name_fetch;
$is_correct = 0;
$is_incorrect = 0;
if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
{
echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
$users_information[$row['quiz_player']]['quiz_correct']++;
$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
}
else
{
echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';
$users_information[$row['quiz_player']]['quiz_incorrect']++;
$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
}
}
}
/* for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
{
echo 'Username: ' . $users_names[$users[$j]] . '<br />';
echo '-- Correct: ' . $users_information[$users[$j]]['quiz_correct'] . '<br />';
echo '-- Incorrect: ' . $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
echo '-- Quiz ID: ' . $users_information[$users[$j]]['quiz_id'] . '<br />';
} */
foreach($users_names as $key => $val)
{
// $key is the user_id, $val is the username
$correct_answers = ($users_information[$key]['quiz_correct']) ? $users_information[$key]['quiz_correct'] : 0;
$incorrect_answers = ($users_information[$key]['quiz_incorrect']) ? $users_information[$key]['quiz_incorrect'] : 0;
$quiz_id_key = $users_information[$key]['quiz_id'];
echo 'Info for ' . $val . ';<br />';
echo '-- Correct: ' . $correct_answers . '<br />';
echo '-- Incorrect: ' . $incorrect_answers . '<br />';
echo '-- Quiz ID: ' . $quiz_id_key . '<br />';
$statistical_overview_setup[] = array(
'quiz_id' => (int) $quiz_id_key,
'quiz_correct' => (int) $correct_answers,
'quiz_incorrect' => (int) $incorrect_answers,
'user_id' => (int) $key,
'quiz_time' => (int) 0,
);
}
$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $sql_ary);
echo 'SQL Query entered';
die();
}
$quiz_id = (int) $_GET['id'];
$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
WHERE quiz_related_id = ' . $quiz_id;
$result = $db->sql_query($sql);
echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
$question_id_hidden = '';
while( $row = $db->sql_fetchrow($result) )
{
$question_id_hidden .= $row['quiz_question_id'] . ',';
echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
echo 'Correct answer:';
$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
WHERE quiz_question_id = ' . $row['quiz_question_id'];
$ans_res = $db->sql_query($ans);
while( $ans_row = $db->sql_fetchrow($ans_res) )
{
echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . ' ';
}
echo '<br /><br />';
}
echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
echo '<input type="submit" value="Submit" name="submit" />';
echo '</form>';
die(); // new
}
else
{
echo 'Mode types:<br />
<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
die();
}
}
?>I think you are looking for this: http://www.phpbb.com/community/viewtopi ... #p11802285subvertbeats wrote:Looks good.
I was having a hard time working out the stats properly, so I just deleted all the existing quizzes and created a new one.
When I enter it I see no questions. I think I remember seeing this issue in the main UQM thread so going to have a look there now
Yeah, this is explained at http://www.phpbb.com/community/viewtopi ... #p11813005subvertbeats wrote:Hmmm yes, thanks....though Ive made thouse changes and still have the same issue....
edit - might well be the value of config_value - just checking now...
Code: Select all
$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $sql_ary);Code: Select all
$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $statistical_overview_setup);Best results
Competition name Competition player Correct Incorrect Percentage
Heres my test comp subvertbeats 2 1 67%
Heres my test comp Dent 2 1 67%
Most played
Competition name Author Submission date Views
Heres my test comp subvertbeats Fri Jan 22, 2010 2:57 pm 2
Most correct answers
Competition player Correct Incorrect Percentage
subvertbeats 4 2 67%
Code: Select all
$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
WHERE quiz_question_id = ' . $question_id_set[$i];Code: Select all
$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
WHERE quiz_question_id = ' . $question_id_set[$i] . '
ORDER BY quiz_question_id ASC';As you can see that Most Correct answers table is still incorrect, but different to how it was before (user Dent vs subvertbeats)Competition name Competition player Correct Incorrect Percentage
Heres my test comp Dent 2 1 67%
Heres my test comp subvertbeats 2 1 67%
Most played
Competition name Author Submission date Views
Heres my test comp subvertbeats Fri Jan 22, 2010 2:57 pm 2
Most correct answers
Competition player Correct Incorrect Percentage
Dent 4 2 67%