Skip to content

Commit

Permalink
show start time for timed tests in user results
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsguides committed Aug 20, 2023
1 parent 9f34333 commit 72163ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/com_yaquiz/language/en-GB/com_yaquiz.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ COM_YAQUIZ_VIEW_QUIZ_MUST_BE_LOGGED_IN = "You must be logged in to view this."
COM_YAQ_TIME_REMAIN="Time Remaining:"
COM_YAQ_NOANSWER="No answer selected."
COM_YAQ_QUIZ_TIMER_STARTED="Quiz timer started."
COM_YAQ_QUIZ_STARTED_AT="Started At: %s"

36 changes: 35 additions & 1 deletion components/com_yaquiz/src/Model/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function countTotalResults($pk = null){
* load a single result
* @param pk result id
*/
public function getIndividualResult($pk = null){
public function getIndividualResultOld($pk = null){

$app = Factory::getApplication();
$input = $app->input;
Expand Down Expand Up @@ -125,5 +125,39 @@ public function getIndividualResult($pk = null){
}


/**
* load a single result with timer data
* @param pk result id
*/
public function getIndividualResult($pk = null){

$app = Factory::getApplication();
$input = $app->input;

if($pk == null){
$pk = $input->get('resultid', null, 'INT');
}

$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
$query->select('r.*, t.start_time');
$query->from($db->quoteName('#__com_yaquiz_results', 'r'));
$query->join('LEFT', $db->quoteName('#__com_yaquiz_user_quiz_times', 't') . ' ON (' . $db->quoteName('r.id') . ' = ' . $db->quoteName('t.result_id') . ')');
$query->where($db->quoteName('r.id') . ' = ' . $db->quote($pk));
$db->setQuery($query);
$result = $db->loadObject();

//the result->user_id must be the same as the current user
$user = Factory::getApplication()->getIdentity();
if($result->user_id != $user->id){
$app->enqueueMessage(Text::_('COM_YAQUIZ_VIEW_QUIZ_RESULT_DENIED'), 'error');
return false;
}
return $result;


}



}
5 changes: 5 additions & 0 deletions components/com_yaquiz/tmpl/user/singleresult.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$user = $app->getIdentity();

$comp_params = ComponentHelper::getParams('com_yaquiz');
$quizParams = $quizModel->getQuizParams($dbresults->quiz_id);

$qbHelper = new QuestionBuilderHelper();

Expand Down Expand Up @@ -89,9 +90,13 @@
<span class="card-header fs-2"><?php echo (Text::_('COM_YAQ_QUIZ_RESULT_HISTORY').$quizTitle); ?></span>
<div class="card-body">
<p><?php echo Text::sprintf('COM_YAQ_QUIZ_SAVED_RESULT_FOR_USERNAME', $user->name); ?></p>
<?php if (isset($dbresults->start_time)): ?>
<p><?php echo Text::sprintf('COM_YAQ_QUIZ_STARTED_AT', date('F j, Y, g:i a', strtotime($dbresults->start_time))); ?></p>
<?php endif; ?>
<p><?php echo (Text::_('COM_YAQ_ORIGINAL_SUBMIT').$format_submitted_date); ?></p>
<p><?php echo Text::sprintf('COM_YAQ_ATTEMPT_COUNT', $attempt_count); ?></p>
<p><?php echo $remaining_attempts; ?></p>

</div>
<div class="card-footer">
<a href="index.php?option=com_yaquiz&view=user" class="btn btn-primary btn-sm"><i class="fas fa-arrow-circle-left"></i> <?php echo Text::_('COM_YAQ_RETURN');?></a>
Expand Down

0 comments on commit 72163ae

Please sign in to comment.