Beispiel #1
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;
    lesson_process_pre_save($data);
    unset($data->mediafile);
    $DB->update_record("lesson", $data);
    $context = get_context_instance(CONTEXT_MODULE, $cmid);
    if ($filename = $mform->get_new_filename('mediafilepicker')) {
        if ($file = $mform->save_stored_file('mediafilepicker', $context->id, 'mod_lesson', 'mediafile', 0, '/', $filename, true)) {
            $DB->set_field('lesson', 'mediafile', '/' . $file->get_filename(), array('id' => $data->id));
        } else {
            $DB->set_field('lesson', 'mediafile', '', array('id' => $data->id));
        }
    } else {
        $DB->set_field('lesson', 'mediafile', '', array('id' => $data->id));
    }
    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;
}
Beispiel #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.
 *
 * @param object $lesson Lesson post data from the form
 * @return boolean
 **/
function lesson_update_instance($lesson)
{
    $lesson->id = $lesson->instance;
    lesson_process_pre_save($lesson);
    if (!($result = update_record("lesson", $lesson))) {
        return false;
        // Awe man!
    }
    lesson_process_post_save($lesson);
    // update grade item definition
    lesson_grade_item_update(stripslashes_recursive($lesson));
    // update grades - TODO: do it only when grading style changes
    lesson_update_grades(stripslashes_recursive($lesson), 0, false);
    return $result;
}
 public function save_dates(cm_info $cm, array $dates)
 {
     global $DB, $COURSE;
     // Fetch module instance from $mods array.
     $lesson = $this->mods[$cm->instance];
     // Updating date values.
     foreach ($dates as $datetype => $datevalue) {
         $lesson->{$datetype} = $datevalue;
     }
     $lesson->timemodified = time();
     // Update DB record.
     $DB->update_record('lesson', $lesson);
     // Update associated calender events.
     lesson_process_post_save($lesson);
 }
Beispiel #4
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;
}