public function setTestResults($args) { Log::debug("Processing test results for User " . $this->getUserId() . " for " . $args['level'] . "/" . $args['lesson']); $defaults = ["max_score" => 100, "min_score" => 0, "passing_score" => 70]; $bad_arg = false; foreach (['passing_score', 'min_score', 'max_score', 'points', 'max_points'] as $key) { if (!(array_key_exists($key, $args) && Number::isInteger($args[$key]))) { Log::error(__METHOD__ . " given invalid argument; {$key} is either undefined or not a valid integer"); $bad_arg = true; } } if ($bad_arg === true) { $debug = str_replace("\n", '\\n', print_r($args, true)); Log::debug("Arguments: {$debug}"); Log::debug("Cancelling collection of test results due to bad arguments :("); return null; } $args = array_merge($defaults, $args); $sql = <<<SQL \t\t\tINSERT INTO test_result (user_id, level_id, lesson_id, score, passing_score, min_score, max_score, points, max_points) \t\t\tVALUES (:user_id, :level_id, :lesson_id, :score, :passing_score, :min_score, :max_score, :points, :max_points); SQL; $stmt = PdoFactory::getInstance()->prepare($sql); Log::debug("User " . $this->getUserId() . ' passed exam ' . $args['level'] . '/' . $args['lesson'] . ' with a score of ' . $args['score']); $rc = $stmt->execute([':user_id' => $this->getUserId(), ':level_id' => $args['level'], ':lesson_id' => $args['lesson'], ':score' => $args['score'], ':passing_score' => $args['passing_score'], ':min_score' => $args['min_score'], ':max_score' => $args['max_score'], ':points' => $args['points'], ':max_points' => $args['max_points']]); if ($rc === false) { Log::debug("Test result insertion failed for user " . $this->getUserId()); return null; } Log::debug("Test result insertion succeeded for user " . $this->getUserId() . ". Invalidating user cache."); $this->invalidateCache(); return $args['score'] >= $args['passing_score']; }
$alias = 'feedback'; break; case 'teacher': $subject .= 'a request for teacher support'; $alias = 'teacher'; break; default: $subject .= 'a support request'; #$alias = ($user->getClass() === 'student') ? 'support' : 'teacher'; $alias = 'support'; break; } $to = "{$alias}@pathtoarabic.com"; echo json_encode(['status' => mail($to, $subject, $message, $headers) ? '0' : '1']); } else { \PTA\Log::error('nonce verification failed for $ip while submitting support/contact form data'); echo json_encode(['status' => '1']); } }); $app->get('/api/get/note/:level/:lesson', function ($level, $lesson) use($app, $user) { $note = $user->getNote($level, $lesson); $app->contentType('text/plain'); echo $note !== null ? $note : ''; }); $app->post('/api/post/note/:level/:lesson', function ($level, $lesson) use($app, $user) { $result = $user->setNote($level, $lesson, $app->request()->post('text')); $app->contentType('application/json'); echo json_encode(['success' => $result]); }); $app->get('/api/getlevel', function () use($app, $user) { $app->contentType('application/json');