<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
networkrailbusinesssystems / laravel-moodle example snippets
Route::get('/', function () {})->middleware('laravel-moodle');
use NetworkRailBusinessSystems\LaravelMoodle\LaravelMoodle as LaravelMoodle;
$data = LaravelMoodle::getCourses();
foreach ($data->courses as $course) {
echo $course->fullname; // My First Course
}
echo $data->courses[0]->fullname; // My First Course
// Get course with id 3
$data = LaravelMoodle::getCourses('2', 'id');
// Get courses with ids 2 & 3
$data = LaravelMoodle::getCourses('2,3', 'ids');
$course = LaravelMoodle::getCourse(2);
echo $course->fullname; // My First Course
$searchResults = LaravelMoodle::searchCourses('search term');
echo $searchResults->total; // 1
echo $searchResults->courses[0]->fullname; // My First Course
$submit = LaravelMoodle::saveCourseAssignment($assignmentId, 'The content');
echo $submit; // true
$submit = LaravelMoodle::saveCourseAssignment($assignmentId, '');
echo $submit[0]->item; // Nothing was submitted
echo $submit[0]->message; // Could not save submission
// Defaults to searching by username
$users = LaravelMoodle::searchUsers('testuser');
// Override to search by email address
$users = LaravelMoodle::searchUsers('[email protected]', 'email');
echo $users->users[0]->fullname; // Test User
// Defaults role to student
LaravelMoodle::enrolUserOnCourse(2, 2);
// Override role to editing teacher
LaravelMoodle::enrolUserOnCourse(2, 2, 3);