Skip to content

Unofficial SDK for Moodle REST APIs written in PHP

License

Notifications You must be signed in to change notification settings

fidelo-software/moodle-php-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moodle-PHP-SDK

PHP SDK for Moodle RESTful APIs

Build Status

Getting Started

  1. Install MoodleSDK

    php composer.phar require agurz/moodle-php-sdk
    
  2. Create a RestApiContext instance

    $context = new RestApiContext();
    $context->setUrl('example.com/moodle')
            ->setCredential(new AuthTokenCredential('token'))
  3. Create a model object instance, set it's properties and call get, create, update, or delete operations

    $user = new User();
    $user->setUsername('username')
         ->setPassword('Password..01')
         ->setFirstName('first')
         ->setLastName('last')
         ->setFullName('first last')
         ->setEmail('[email protected]')
         ->create($context)
  4. That's all!

Usage example

Creating a user and enrolling him into 'test-course' course

<?php

require_once 'vendor/autoload.php';

use MoodleSDK\Api\Model\Course;
use MoodleSDK\Api\Model\User;
use MoodleSDK\Auth\AuthTokenCredential;
use MoodleSDK\Rest\RestApiContext;

$context = RestApiContext::instance()
                         ->setUrl('example.com/moodle')
                         ->setCredential(new AuthTokenCredential('token'))

$user = User::instance()
            ->setUsername('agurz')
            ->setPassword('Password..01')
            ->setFirstName('Agustn')
            ->setLastName('Rodríguez')
            ->setFullName('Agustn Rodríguez')
            ->setEmail('[email protected]')
            ->create($context);

$course = Course::instance()
                ->setShortName('test-course')
                ->get($context)
                ->enrolUser($context, $user);

About

Unofficial SDK for Moodle REST APIs written in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%