Пример #1
0
    $course = $DB->get_record('course', array('id' => $sassessment->course), '*', MUST_EXIST);
    $cm = get_coursemodule_from_instance('sassessment', $sassessment->id, $course->id, false, MUST_EXIST);
} else {
    error('You must specify a course_module ID or an instance ID');
}
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
//add_to_log($course->id, 'sassessment', 'view', "view.php?id={$cm->id}", $sassessment->name, $cm->id);
$frm = data_submitted();
/*
* Adding mew item
*/
if ($a == "add" && is_array($frm->useranswer)) {
    if ($sassessment->grademethod == "default") {
        if (!($catdata = $DB->get_record("grade_items", array("courseid" => $sassessment->course, "iteminstance" => $sassessment->id, "itemmodule" => 'sassessment')))) {
            sassessment_grade_item_update($sassessment);
        }
    }
    $add = new stdClass();
    $add->aid = $sassessment->id;
    $add->uid = $USER->id;
    $add->summary = $frm->summary;
    $text = "";
    foreach ($frm->useranswer as $k => $v) {
        $add->{'var' . $k} = $v;
        $text .= $v . ". ";
    }
    $add->timecreated = time();
    $add->analize = json_encode(sassessment_printanalizeform($text));
    if (empty($frm->sid)) {
        $DB->insert_record("sassessment_studdent_answers", $add);
Пример #2
0
 /**
  * Updates a new sassessment activity
  *
  * Given an object containing all the necessary data,
  * (defined by the form in mod_form.php) this function
  * will update the sassessment instance and return the id number
  * The due date is updated in the calendar
  * This is common to all sassessment types.
  *
  * @global object
  * @global object
  * @param object $sassessment The data from the form on mod_form.php
  * @return bool success
  */
 function update_instance($sassessment)
 {
     global $COURSE, $DB;
     $sassessment->timemodified = time();
     $sassessment->id = $sassessment->instance;
     $sassessment->courseid = $sassessment->course;
     $DB->update_record('sassessment', $sassessment);
     if ($sassessment->timedue) {
         $event = new stdClass();
         if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'sassessment', 'instance' => $sassessment->id))) {
             $event->name = $sassessment->name;
             $event->description = format_module_intro('sassessment', $sassessment, $sassessment->coursemodule);
             $event->timestart = $sassessment->timedue;
             $calendarevent = calendar_event::load($event->id);
             $calendarevent->update($event);
         } else {
             $event = new stdClass();
             $event->name = $sassessment->name;
             $event->description = format_module_intro('sassessment', $sassessment, $sassessment->coursemodule);
             $event->courseid = $sassessment->course;
             $event->groupid = 0;
             $event->userid = 0;
             $event->modulename = 'sassessment';
             $event->instance = $sassessment->id;
             $event->eventtype = 'due';
             $event->timestart = $sassessment->timedue;
             $event->timeduration = 0;
             calendar_event::create($event);
         }
     } else {
         $DB->delete_records('event', array('modulename' => 'sassessment', 'instance' => $sassessment->id));
     }
     // get existing grade item
     sassessment_grade_item_update($sassessment);
     return true;
 }