示例#1
0
             $attempt->correct = 1;
         } else {
             $attempt->correct = 0;
         }
         $attempt->useranswer = serialize($essayinfo);
         $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)) {
示例#2
0
 /**
  * Test the essay assessed event.
  *
  * There is no external API for assessing an essay, so the unit test will simply
  * create and trigger the event and ensure the legacy log data is returned as expected.
  */
 public function test_essay_assessed()
 {
     // Create an essay assessed event
     $gradeid = 5;
     $attemptid = 7;
     $event = \mod_lesson\event\essay_assessed::create(array('objectid' => $gradeid, 'relateduserid' => 3, 'context' => context_module::instance($this->lesson->properties()->cmid), 'courseid' => $this->course->id, 'other' => array('lessonid' => $this->lesson->id, 'attemptid' => $attemptid)));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\mod_lesson\\event\\essay_assessed', $event);
     $this->assertEquals(context_module::instance($this->lesson->properties()->cmid), $event->get_context());
     $expected = array($this->course->id, 'lesson', 'update grade', 'essay.php?id=' . $this->lesson->properties()->cmid, $this->lesson->name, $this->lesson->properties()->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
 }