Exemple #1
0
    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'];
    }
Exemple #2
0
 public static function getAnnouncement($id)
 {
     if (!Number::isInteger($id)) {
         return false;
     }
     $sql = 'SELECT id,title,text,UNIX_TIMESTAMP(created_on) as epoch FROM announcements WHERE id = :id';
     $stmt = PdoFactory::getInstance()->prepare($sql);
     $stmt->bindValue(':id', $id, PDO::PARAM_INT);
     $stmt->execute();
     if ($stmt->rowCount() === 0) {
         return null;
     }
     return $stmt->fetch(PDO::FETCH_ASSOC);
 }