Code Monkey home page Code Monkey logo

moodle-php-sdk's Introduction

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

moodle-php-sdk's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.