PHP code example of networkrailbusinesssystems / laravel-moodle

1. Go to this page and download the library: Download networkrailbusinesssystems/laravel-moodle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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

$searchResults = LaravelMoodle::searchCourses('search term', 2, 15);

$searchResults = LaravelMoodle::searchCourses('search term', 2, 15, 1);

$courseContents = LaravelMoodle::getCourseContents(1);

echo $courseContents[0]->name; // Topic name
echo $courseContents[0]->modules[0]->name; // Activity name

$module = LaravelMoodle::getCourseModule(11);

echo $module->cm->name; // Topic name

$pages = LaravelMoodle::getCoursePages(1);

echo $pages->pages[0]->name; // Page name

$page = LaravelMoodle::getCoursePage($courseId, $moduleId);

$scorms = LaravelMoodle::getCourseScorms(1);

echo $scorms->scorms[0]->name; // Example scorm

$scorm = LaravelMoodle::getCourseScorm($courseId, $moduleId);

$resources = LaravelMoodle::getCourseResources(1);
echo $resources->resources[0]->name;

$resource = LaravelMoodle::getCourseResource($courseId, $moduleId);

$completion = LaravelMoodle::getCourseCompletion(2, 2);

$activities = LaravelMoodle::getCourseActivitiesCompletion(2, 2);

echo $activities->statuses[0]->state;

$data = LaravelMoodle::getCourseAssignments(2);

echo $data->courses[0]->assignments[0]->name;
echo $data->courses[0]->assignments[0]->id;

$assignment = LaravelMoodle::getCourseAssignment($courseId, $moduleId);

LaravelMoodle::getAssignmentSubmissionStatus($assignmentId, $userId);

$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

$grades = LaravelMoodle::getUserGrades();

echo $grades->grades[0]->courseid; // 2
echo $grades->grades[0]->grade; // A

$grade = LaravelMoodle::getCourseGrade(2);

echo $grade->courseid; // 2
echo $grade->grade; // A

// 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);

LaravelMoodle::unenrolUserOnCourse($userId, $courseId, $roleId);

$enrolledUsers = LaravelMoodle::getEnrolledUsersForCourse(2);

echo $enrolledUsers[0]->fullname; // Test User
echo $enrolledUsers[0]->roles[0]->shortname; // Student

$categories = LaravelMoodle::getCategories();

echo $categories[0]->name; // Category name

$categories = LaravelMoodle::searchCategories('Business Briefing System');

echo $categories[0]->name; // Business Briefing System

$pageViewed = LaravelMoodle::viewPageEvent(1);

dd($pageViewed); // true

$data = LaravelMoodle::getCourses();

$data->courses[0]->asDate('startdate')->format('d/m/Y');
$data->courses[0]->dates()->startdate->format('d/m/Y');
$data->courses[0]->dates()->enddate->format('d/m/Y');
bash
php artisan migrate
bash
php artisan vendor:publish