コード例 #1
0
ファイル: admin.php プロジェクト: e-rasvet/reader
 $data['averagepassed'] = 0;
 $data['averagepoints'] = 0;
 $data['averagefailed'] = 0;
 $data['withquizzes'] = 0;
 $data['withoutquizzes'] = 0;
 $data['averagewordsthisterm'] = 0;
 $data['averagewordsallterms'] = 0;
 $coursestudents = get_enrolled_users($context, NULL, $group->id);
 foreach ($coursestudents as $coursestudent) {
     if ($attempts = $DB->get_records_sql("SELECT * FROM {reader_attempts} WHERE userid= ?  and reader= ?  and timestart > ?", array($coursestudent->id, $reader->id, $reader->ignordate))) {
         $data['averagetaken'] += count($attempts);
         foreach ($attempts as $attempt) {
             if (strtolower($attempt->passed) == "true") {
                 $data['averagepassed']++;
                 $bookdata = $DB->get_record("reader_publisher", array("id" => $attempt->quizid));
                 $data['averagepoints'] += reader_get_reader_length($reader, $bookdata->id);
                 $data['averagewordsthisterm'] += $bookdata->words;
             } else {
                 $data['averagefailed']++;
             }
         }
         $data['withquizzes']++;
     } else {
         $data['withoutquizzes']++;
     }
     if ($attempts = $DB->get_records_sql("SELECT * FROM {reader_attempts} WHERE userid= ? ", array($coursestudent->id))) {
         foreach ($attempts as $attempt) {
             if (strtolower($attempt->passed) == "true") {
                 $bookdata = $DB->get_record("reader_publisher", array("id" => $attempt->quizid));
                 $data['averagewordsallterms'] += $bookdata->words;
             }
コード例 #2
0
ファイル: lib.php プロジェクト: e-rasvet/reader
function reader_get_student_attempts($userid, $reader, $allreaders = false, $booklist = false)
{
    global $CFG, $COURSE, $bookpersentmaxgrade, $DB, $USER;
    $returndata = array();
    $totable = array();
    $readersql = "";
    if ($booklist) {
        $reader->ignordate = 0;
    }
    if (!$allreaders) {
        $readersql = " and ra.reader= :readerid ";
    }
    $studentattempts_p = $DB->get_records_sql("SELECT ra.timefinish,ra.userid,ra.attempt,ra.persent,ra.id,ra.quizid,ra.sumgrades,ra.passed,ra.checkbox,ra.preview,rp.name,rp.publisher,rp.level,rp.length,rp.image,rp.difficulty,rp.words,rp.sametitle,rp.id as rpid FROM {reader_attempts} ra LEFT JOIN {reader_publisher} rp ON rp.id = ra.quizid WHERE ra.preview != 1 and ra.userid= :userid and ra.timefinish > :readerignordate {$readersql} ORDER BY ra.timefinish", array("readerid" => $reader->id, "userid" => $userid, "readerignordate" => $reader->ignordate));
    $studentattempts_n = $DB->get_records_sql("SELECT ra.timefinish,ra.userid,ra.attempt,ra.persent,ra.id,ra.quizid,ra.sumgrades,ra.passed,ra.checkbox,ra.preview,rp.name,rp.publisher,rp.level,rp.length,rp.image,rp.difficulty,rp.words,rp.sametitle,rp.id as rpid FROM {reader_attempts} ra LEFT JOIN {reader_noquiz}    rp ON rp.id = ra.quizid WHERE ra.preview = 1 and ra.userid= :userid and ra.timefinish > :readerignordate {$readersql} ORDER BY ra.timefinish", array("readerid" => $reader->id, "userid" => $userid, "readerignordate" => $reader->ignordate));
    if (is_array($studentattempts_n) && is_array($studentattempts_p)) {
        $studentattempts = array_merge($studentattempts_p, $studentattempts_n);
    } elseif ($studentattempts_n) {
        $studentattempts = $studentattempts_n;
    } else {
        $studentattempts = $studentattempts_p;
    }
    if (!($studentlevel = $DB->get_record("reader_levels", array("userid" => $USER->id, "readerid" => $reader->id)))) {
        $createlevel = new stdClass();
        $createlevel->userid = $USER->id;
        $createlevel->startlevel = 0;
        $createlevel->currentlevel = 0;
        $createlevel->readerid = $reader->id;
        $createlevel->promotionstop = $reader->promotionstop;
        $createlevel->time = time();
        $DB->insert_record('reader_levels', $createlevel);
        $studentlevel = $DB->get_record("reader_levels", array("userid" => $USER->id, "readerid" => $reader->id));
    }
    if (is_array($studentattempts)) {
        $totable['correct'] = 0;
        $totable['incorrect'] = 0;
        $totable['totalpoints'] = 0;
        $totable['countattempts'] = 0;
        foreach ($studentattempts as $studentattempt) {
            $totable['countattempts']++;
            if ($studentattempt->passed == "true" || $studentattempt->passed == "TRUE") {
                $statustext = "Passed";
                $status = "correct";
                $totable['points'] = reader_get_reader_length($reader, $studentattempt->rpid);
                $totable['correct']++;
            } else {
                if ($studentattempt->passed == "cheated") {
                    $statustext = "<font color='red'>" . get_string('cheated', 'reader') . "</font>";
                } else {
                    $statustext = "Not Passed";
                }
                $status = "incorrect";
                $totable['points'] = 0;
                $totable['incorrect']++;
            }
            $totable['totalpoints'] += round($totable['points'], 2);
            if (!isset($bookpersentmaxgrade[$studentattempt->quizid])) {
                $totalgrade = 0;
                $answersgrade = $DB->get_records("reader_question_instances", array("quiz" => $studentattempt->quizid));
                foreach ($answersgrade as $answersgrade_) {
                    $totalgrade += $answersgrade_->grade;
                }
                $totable['bookpersent'] = $studentattempt->persent . "%";
                $totable['bookmaxgrade'] = $totalgrade * reader_get_reader_length($reader, $studentattempt->rpid);
                $bookpersentmaxgrade[$studentattempt->quizid] = array($totable['bookpersent'], $totable['bookmaxgrade']);
            } else {
                list($totable['bookpersent'], $totable['bookmaxgrade']) = $bookpersentmaxgrade[$studentattempt->quizid];
            }
            if ($studentattempt->preview == 1) {
                $statustext = "Credit";
            }
            $returndata[$studentattempt->id] = array("id" => $studentattempt->id, "quizid" => $studentattempt->quizid, "timefinish" => $studentattempt->timefinish, "booktitle" => $studentattempt->name, "image" => $studentattempt->image, "words" => $studentattempt->words, "booklength" => reader_get_reader_length($reader, $studentattempt->rpid), "booklevel" => $studentattempt->level, "bookdiff" => reader_get_reader_difficulty($reader, $studentattempt->rpid), "persent" => $studentattempt->persent, "passed" => $studentattempt->passed, "checkbox" => $studentattempt->checkbox, "sametitle" => $studentattempt->sametitle, "userlevel" => $studentlevel->currentlevel, "status" => $status, "statustext" => $statustext, "bookpoints" => $totable['points'], "bookpersent" => $totable['bookpersent'], "bookmaxgrade" => $totable['bookmaxgrade'], "totalpoints" => $totable['totalpoints'], "startlevel" => $studentlevel->startlevel, "currentlevel" => $studentlevel->currentlevel);
        }
        $totable['startlevel'] = $studentlevel->startlevel;
        $totable['currentlevel'] = $studentlevel->currentlevel;
        return array($returndata, $totable);
    } else {
        return false;
    }
}