コード例 #1
0
 /**
  * Test course completed event.
  */
 public function test_course_completion_updated_event()
 {
     $this->setup_data();
     $coursecontext = context_course::instance($this->course->id);
     $coursecompletionevent = \core\event\course_completion_updated::create(array('courseid' => $this->course->id, 'context' => $coursecontext));
     // Mark course as complete and get triggered event.
     $sink = $this->redirectEvents();
     $coursecompletionevent->trigger();
     $events = $sink->get_events();
     $event = array_pop($events);
     $sink->close();
     $this->assertInstanceOf('\\core\\event\\course_completion_updated', $event);
     $this->assertEquals($this->course->id, $event->courseid);
     $this->assertEquals($coursecontext, $event->get_context());
     $this->assertInstanceOf('moodle_url', $event->get_url());
     $expectedlegacylog = array($this->course->id, 'course', 'completion updated', 'completion.php?id=' . $this->course->id);
     $this->assertEventLegacyLogData($expectedlegacylog, $event);
 }
コード例 #2
0
ファイル: completion.php プロジェクト: evltuma/moodle
        $aggregation->setMethod($data->activity_aggregation);
        $aggregation->save();
        // Handle course aggregation.
        if (empty($data->course_aggregation)) {
            $data->course_aggregation = 0;
        }
        $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_COURSE;
        $aggregation = new completion_aggregation($aggdata);
        $aggregation->setMethod($data->course_aggregation);
        $aggregation->save();
        // Handle role aggregation.
        if (empty($data->role_aggregation)) {
            $data->role_aggregation = 0;
        }
        $aggdata['criteriatype'] = COMPLETION_CRITERIA_TYPE_ROLE;
        $aggregation = new completion_aggregation($aggdata);
        $aggregation->setMethod($data->role_aggregation);
        $aggregation->save();
        // Trigger an event for course module completion changed.
        $event = \core\event\course_completion_updated::create(array('courseid' => $course->id, 'context' => context_course::instance($course->id)));
        $event->trigger();
        // Redirect to the course main page.
        $url = new moodle_url('/course/view.php', array('id' => $course->id));
        redirect($url);
    }
}
// Print the form.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editcoursecompletionsettings', 'core_completion'));
$form->display();
echo $OUTPUT->footer();