Пример #1
0
 public function startAttempt($quiz, $studentId = null)
 {
     db()->beginTransaction();
     if (empty($studentId)) {
         $studentId = studentId();
     }
     if (!empty($quiz['maxAttemptNum'])) {
         $numAttemptsUsed = field_sql('SELECT COUNT(quizAttemptId) FROM quiz_attempt WHERE quizId=:quizId AND studentId=:studentId', array('quizId' => $quiz['quizId'], 'studentId' => $studentId));
         if ($numAttemptsUsed >= $quiz['maxAttemptNum']) {
             throw new Exception('Attempt limit consumed', 403);
         }
     }
     $numAttemptsInproc = field_sql('SELECT COUNT(quizAttemptId) FROM quiz_attempt WHERE quizId=:quizId AND studentId=:studentId AND status=:status', array('quizId' => $quiz['quizId'], 'studentId' => $studentId, 'status' => STATUS_INPROC));
     if ($numAttemptsInproc > 0) {
         throw new Exception('Already started', 403);
     }
     entry_change('quiz_attempt', array('quizId' => $quiz['quizId'], 'studentId' => $studentId, 'status' => STATUS_INPROC, 'timeStart' => date('Y-m-d H:i:s')));
     $attemptId = db()->lastInsertId();
     $questions = entries_sql('SELECT questionId FROM question WHERE questionBaseId=:questionBaseId', array('questionBaseId' => $quiz['questionBaseId']));
     if (empty($questions)) {
         throw new Exception('Questions not found', 404);
     }
     shuffle($questions);
     $num = 1;
     foreach ($questions as $q) {
         if (!empty($quiz['numQuestion']) && $num > $quiz['numQuestion']) {
             break;
         }
         entry_change('question_session', array('num' => $num++, 'quizAttemptId' => $attemptId, 'questionId' => $q['questionId'], 'status' => STATUS_NEW));
     }
     db()->commit();
     return $attemptId;
 }
Пример #2
0
 public function events()
 {
     if (!env('student')) {
         redirect('m=login');
     }
     $updisciplineId = val($_REQUEST, 'updisciplineId');
     $learningMode = val($_REQUEST, 'learningMode');
     if (empty($updisciplineId) || empty($learningMode)) {
         throw new Exception('Missed required param', 404);
     }
     $updiscipline = entry_sql('SELECT * FROM updiscipline WHERE updisciplineId=:updisciplineId', array(':updisciplineId' => $updisciplineId));
     if (empty($updiscipline)) {
         throw new Exception('Updiscipline not found', 404);
     }
     $groupPeriod = entry_sql('SELECT gp.* FROM group_history gh INNER JOIN group_period gp USING(groupPeriodId) WHERE gh.studentId=:studentId AND gp.sersemester=:sersemester', array('studentId' => studentId(), 'sersemester' => $updiscipline['sersemester']));
     if (empty($groupPeriod)) {
         throw new Exception('Cannot detect groupPeriod', 404);
     }
     $events = entries_sql('SELECT * FROM event WHERE updisciplineId=:updisciplineId AND groupPeriodId=:groupPeriodId AND learningMode=:learningMode', array('groupPeriodId' => $groupPeriod['groupPeriodId'], 'updisciplineId' => $updiscipline['updisciplineId'], 'learningMode' => $learningMode));
     array_walk($events, function (&$event, $k, $studentId) {
         $event['c'] = material::i($event['instanceType'])->c();
         $event['grade'] = material::i($event['instanceType'])->get_grade($event['instanceId'], $studentId);
     }, studentId());
     env('breadcrumbs', array(array(lng('up:disciplines'), '/?c=up'), array($updiscipline['disciplineName'], '/?c=up&m=events&updisciplineId=' . $updisciplineId . '&learningMode=' . $learningMode), lng('up:events')));
     tpl('up/events', array('updiscipline' => $updiscipline, 'events' => $events, 'result' => entry_sql('SELECT * FROM result WHERE studentId=:studentId AND updisciplineId=:updisciplineId AND learningMode=:learningMode', array('studentId' => studentId(), 'updisciplineId' => $updiscipline['updisciplineId'], 'learningMode' => $learningMode))));
 }
 public function __construct(array $extra = null)
 {
     $this->_extra = $extra;
     if (studentId() && !env('student')) {
         try {
             env('student', entry_sql('SELECT * FROM student WHERE studentId=:studentId', array(':studentId' => studentId())));
         } catch (Exception $e) {
             // in some cases DB not initialized
         }
     }
     env('css', array('base'));
 }
Пример #4
0
 public function login()
 {
     if (studentId()) {
         redirect('c=up');
     }
     $login = val($_REQUEST, 'login');
     $passw = val($_REQUEST, 'passw');
     if (!empty($passw)) {
         $studentId = field_sql('SELECT studentId FROM student WHERE login=:login AND passw=:passw', array('login' => $login, 'passw' => md5($passw)));
         if (empty($studentId)) {
             env('warning', lng('main:loginfailed'));
         } else {
             $_SESSION['studentId'] = $studentId;
             redirect('c=up');
         }
     }
     env('breadcrumbs', array(lng('main:loginpage')));
     tpl('login_form', array('login' => $login, 'passw' => ''));
 }
Пример #5
0
 public function attempt()
 {
     if (!env('student')) {
         redirect('m=login');
     }
     $quizId = val($_REQUEST, 'id', -1);
     $attemptId = val($_REQUEST, 'attemptId', -1);
     $page = val($_REQUEST, 'page', 1);
     $complete = val($_REQUEST, 'complete');
     $pro = val($_REQUEST, 'pro');
     if (!empty($pro)) {
         env('modepro', true);
     }
     $now = date('Y-m-d H:i:s');
     if (val(env('event'), 'instanceId') != $quizId) {
         throw new Exception('Cannot fetch event', 404);
     }
     $quiz = entry_sql('SELECT * FROM quiz WHERE quizId=:quizId', array('quizId' => $quizId));
     if (empty($quiz)) {
         throw new Exception('Cannot find quiz "' . $id . '"', 404);
     }
     if ($attemptId == 0) {
         // create new attempt
         $attemptId = material::i('quiz')->startAttempt($quiz);
         redirect('c=quiz&m=attempt&id=' . $quizId . '&attemptId=' . $attemptId);
     }
     $attempt = entry_sql('SELECT * FROM quiz_attempt WHERE quizAttemptId=:quizAttemptId AND quizId=:quizId AND studentId=:studentId', array('quizAttemptId' => $attemptId, 'quizId' => $quizId, 'studentId' => studentId()));
     if (empty($attempt)) {
         throw new Exception('Attempt "' . $attemptId . '" not found', 404);
     }
     if ($attempt['status'] != STATUS_INPROC) {
         throw new Exception('Attempt is not available anymore', 403);
     }
     if (!empty($quiz['timeLimit']) && date('Y-m-d H:i:s', strtotime($attempt['timeStart']) + $quiz['timeLimit']) < $now) {
         // if time expired
         material::i('quiz')->finishAttempt($attemptId);
         redirect('c=quiz&id=' . $quiz['quizId'] . '&eventId=' . val(env('event'), 'eventId'));
     }
     $questions = entries_sql('SELECT * FROM question_session WHERE quizAttemptId=:quizAttemptId ORDER BY num', array('quizAttemptId' => $attemptId));
     $perpage = 1;
     $numl = $page * $perpage;
     $numf = $numl - $perpage;
     $qresponses = val($_REQUEST, 'question', array());
     foreach ($questions as &$qsess) {
         $qobj = question::i($qsess['questionId']);
         $qresponse = val($qresponses, $qsess['questionId']);
         if (!empty($qresponse)) {
             $qgrade = $qobj->get_grade($qresponse);
             $qsess['grade'] = $qobj->get_grade($qresponse);
             $qsess['response'] = json_encode($qresponse);
             $qsess['status'] = STATUS_ANSWER;
             entry_change('question_session', $qsess, array('questionSessionId' => $qsess['questionSessionId']));
             entry_change('quiz_attempt', array('timeChange' => date('Y-m-d H:i:s')), array('quizAttemptId' => $attemptId));
         }
         if ($qsess['num'] > $numf && $qsess['num'] <= $numl) {
             // render only questions of the page
             $qsess['qhtml'] = $qobj->render(json_decode($qsess['response']));
         }
         $qsess['page'] = ceil($qsess['num'] / $perpage);
     }
     env('breadcrumbs', array_merge($this->_up_breadcrumbs(env('event')), array(lng('quiz:attempt'))));
     if (!empty($complete)) {
         material::i('quiz')->finishAttempt($attemptId);
         trigger_exe('material.graded', array('quiz', $quizId, studentId()));
         redirect('c=quiz&id=' . $quiz['quizId'] . '&eventId=' . val(env('event'), 'eventId'));
     }
     tpl('quiz/attempt', array('page' => $page, 'quiz' => $quiz, 'attempt' => $attempt, 'questions' => $questions));
 }