示例#1
0
function xmldb_lesson_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2006091802) {
        /// Changing nullability of field response on table lesson_answers to null
        $table = new XMLDBTable('lesson_answers');
        $field = new XMLDBField('response');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'answer');
        /// Launch change of nullability for field response
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2006091803) {
        /// Changing nullability of field useranswer on table lesson_attempts to null
        $table = new XMLDBTable('lesson_attempts');
        $field = new XMLDBField('useranswer');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'correct');
        /// Launch change of nullability for field useranswer
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2007020201) {
        /// Changing nullability of field answer on table lesson_answers to null
        $table = new XMLDBTable('lesson_answers');
        $field = new XMLDBField('answer');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'timemodified');
        /// Launch change of nullability for field answer
        $result = $result && change_field_notnull($table, $field);
    }
    //===== 1.9.0 upgrade line ======//
    if ($result && $oldversion < 2007072201) {
        $table = new XMLDBTable('lesson');
        $field = new XMLDBField('usegrademax');
        $field2 = new XMLDBField('usemaxgrade');
        /// Rename lesson->usegrademax to lesson->usemaxgrade. Some old sites can have it incorrect. MDL-13177
        if (field_exists($table, $field) && !field_exists($table, $field2)) {
            /// Set field specs
            $field->setAttributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0', 'ongoing');
            /// Launch rename field usegrademax to usemaxgrade
            $result = $result && rename_field($table, $field, 'usemaxgrade');
        }
    }
    if ($result && $oldversion < 2008112601) {
        require_once $CFG->dirroot . '/mod/lesson/lib.php';
        // too much debug output
        $db->debug = false;
        lesson_update_grades();
        $db->debug = true;
    }
    return $result;
}
示例#2
0
/**
 * Given an object containing all the necessary data,
 * (defined by the form in mod_form.php) this function
 * will update an existing instance with new data.
 *
 * @global object
 * @param object $lesson Lesson post data from the form
 * @return boolean
 **/
function lesson_update_instance($data, $mform)
{
    global $DB;
    $data->id = $data->instance;
    $cmid = $data->coursemodule;
    $draftitemid = $data->mediafile;
    $context = context_module::instance($cmid);
    lesson_process_pre_save($data);
    unset($data->mediafile);
    $DB->update_record("lesson", $data);
    lesson_update_media_file($data->id, $context, $draftitemid);
    lesson_process_post_save($data);
    // update grade item definition
    lesson_grade_item_update($data);
    // update grades - TODO: do it only when grading style changes
    lesson_update_grades($data, 0, false);
    return true;
}
示例#3
0
function xmldb_lesson_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2006091802) {
        /// Changing nullability of field response on table lesson_answers to null
        $table = new XMLDBTable('lesson_answers');
        $field = new XMLDBField('response');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'answer');
        /// Launch change of nullability for field response
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2006091803) {
        /// Changing nullability of field useranswer on table lesson_attempts to null
        $table = new XMLDBTable('lesson_attempts');
        $field = new XMLDBField('useranswer');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'correct');
        /// Launch change of nullability for field useranswer
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2007020201) {
        /// Changing nullability of field answer on table lesson_answers to null
        $table = new XMLDBTable('lesson_answers');
        $field = new XMLDBField('answer');
        $field->setAttributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'timemodified');
        /// Launch change of nullability for field answer
        $result = $result && change_field_notnull($table, $field);
    }
    if ($result && $oldversion < 2007072200) {
        require_once $CFG->dirroot . '/mod/lesson/lib.php';
        // too much debug output
        $db->debug = false;
        lesson_update_grades();
        $db->debug = true;
    }
    return $result;
}
示例#4
0
         $DB->update_record('lesson_attempts', $attempt);
         // Get grade information
         $grade = current($grades);
         $gradeinfo = lesson_grade($lesson, $attempt->retry, $attempt->userid);
         // Set and update
         $updategrade = new stdClass();
         $updategrade->id = $grade->id;
         $updategrade->grade = $gradeinfo->grade;
         $DB->update_record('lesson_grades', $updategrade);
         $params = array('context' => $context, 'objectid' => $grade->id, 'courseid' => $course->id, 'relateduserid' => $attempt->userid, 'other' => array('lessonid' => $lesson->id, 'attemptid' => $attemptid));
         $event = \mod_lesson\event\essay_assessed::create($params);
         $event->add_record_snapshot('lesson', $dblesson);
         $event->trigger();
         $lesson->add_message(get_string('changessaved'), 'notifysuccess');
         // update central gradebook
         lesson_update_grades($lesson, $grade->userid);
         redirect(new moodle_url('/mod/lesson/essay.php', array('id' => $cm->id)));
     } else {
         print_error('invalidformdata');
     }
     break;
 case 'email':
     // Sending an email(s) to a single user or all
     require_sesskey();
     // Get our users (could be singular)
     if ($userid = optional_param('userid', 0, PARAM_INT)) {
         $queryadd = " AND userid = ?";
         if (!($users = $DB->get_records('user', array('id' => $userid)))) {
             print_error('cannotfinduser', 'lesson');
         }
     } else {
示例#5
0
             if ($lesson->timelimit) {
                 if ($outoftime == 'normal') {
                     $grade = new stdClass();
                     $grade->lessonid = $lesson->id;
                     $grade->userid = $USER->id;
                     $grade->grade = 0;
                     $grade->completed = time();
                     $newgradeid = $DB->insert_record("lesson_grades", $grade);
                     $lessoncontent .= $lessonoutput->paragraph(get_string("eolstudentoutoftimenoanswers", "lesson"));
                 }
             } else {
                 $lessoncontent .= $lessonoutput->paragraph(get_string("welldone", "lesson"));
             }
         }
         // update central gradebook
         lesson_update_grades($lesson, $USER->id);
         $lessoncontent .= $progressbar;
     }
 } else {
     // display for teacher
     if ($lesson->grade != GRADE_TYPE_NONE) {
         $lessoncontent .= $lessonoutput->paragraph(get_string("displayofgrade", "lesson"), 'center');
     }
 }
 $lessoncontent .= $OUTPUT->box_end();
 //End of Lesson button to Continue.
 if ($lesson->modattempts && !$canmanage) {
     // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
     // look at the attempt records to find the first QUESTION page that the user answered, then use that page id
     // to pass to view again.  This is slick cause it wont call the empty($pageid) code
     // $ntries is decremented above
示例#6
0
/**
 * Update grades in central gradebook
 *
 * @param object $lesson null means all lessons
 * @param int $userid specific user only, 0 mean all
 */
function lesson_update_grades($lesson = null, $userid = 0, $nullifnone = true)
{
    global $CFG;
    if (!function_exists('grade_update')) {
        //workaround for buggy PHP versions
        require_once $CFG->libdir . '/gradelib.php';
    }
    if ($lesson != null) {
        if ($grades = lesson_get_user_grades($lesson, $userid)) {
            lesson_grade_item_update($lesson, $grades);
        } else {
            if ($userid and $nullifnone) {
                $grade = new object();
                $grade->userid = $userid;
                $grade->rawgrade = NULL;
                lesson_grade_item_update($lesson, $grade);
            } else {
                lesson_grade_item_update($lesson);
            }
        }
    } else {
        $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid\n                  FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n                 WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
        if ($rs = get_recordset_sql($sql)) {
            while ($lesson = rs_fetch_next_record($rs)) {
                if ($lesson->grade != 0) {
                    lesson_update_grades($lesson, 0, false);
                } else {
                    lesson_grade_item_update($lesson);
                }
            }
            rs_close($rs);
        }
    }
}
示例#7
0
                    }
                    /// Remove the grade from the grades and high_scores tables - this is silly, it should be linked to specific attempt (skodak)
                    $grades = $DB->get_records_sql("SELECT id FROM {lesson_grades}\n                                                     WHERE userid = :userid AND lessonid = :lessonid\n                                                  ORDER BY completed", $params, $try, 1);
                    if ($grades) {
                        $grade = reset($grades);
                        $DB->delete_records('lesson_grades', array('id' => $grade->id));
                        $DB->delete_records('lesson_high_scores', array('gradeid' => $grade->id, 'lessonid' => $lesson->id, 'userid' => $userid));
                    }
                    /// Remove attempts and update the retry number
                    $DB->delete_records('lesson_attempts', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try));
                    $DB->execute("UPDATE {lesson_attempts} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
                    /// Remove seen branches and update the retry number
                    $DB->delete_records('lesson_branch', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try));
                    $DB->execute("UPDATE {lesson_branch} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
                    /// update central gradebook
                    lesson_update_grades($lesson, $userid);
                    $modifier++;
                }
            }
        }
    }
    redirect(new moodle_url($PAGE->url, array('action' => 'reportoverview')));
} else {
    if ($action === 'reportoverview') {
        /**************************************************************************
           this action is for default view and overview view
           **************************************************************************/
        echo $lessonoutput->header($lesson, $cm, $action);
        $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            $seeallgradeslink = new moodle_url('/grade/report/grader/index.php', array('id' => $course->id));
示例#8
0
文件: lib.php 项目: nmicha/moodle
/**
 * Update all grades in gradebook.
 *
 * @global object
 */
function lesson_upgrade_grades()
{
    global $DB;
    $sql = "SELECT COUNT('x')\n              FROM {lesson} l, {course_modules} cm, {modules} m\n             WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
    $count = $DB->count_records_sql($sql);
    $sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid\n              FROM {lesson} l, {course_modules} cm, {modules} m\n             WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
    $rs = $DB->get_recordset_sql($sql);
    if ($rs->valid()) {
        $pbar = new progress_bar('lessonupgradegrades', 500, true);
        $i = 0;
        foreach ($rs as $lesson) {
            $i++;
            upgrade_set_timeout(60 * 5);
            // set up timeout, may also abort execution
            lesson_update_grades($lesson, 0, false);
            $pbar->update($i, $count, "Updating Lesson grades ({$i}/{$count}).");
        }
    }
    $rs->close();
}