PHPackages                             otago/moodle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. otago/moodle

ActiveSilverstripe-vendormodule[API Development](/categories/api)

otago/moodle
============

Moodle webservice

v6.0(3mo ago)16.5k3BSD-3-ClausePHP

Since Nov 20Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/otago/moodle)[ Packagist](https://packagist.org/packages/otago/moodle)[ RSS](/packages/otago-moodle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

*Moodle SilverStripe module*
============================

[](#moodle-silverstripe-module)

*Easily connect Moodle to SilverStripe via the web services REST API.*

Project Setup
-------------

[](#project-setup)

- Plop the *moodle/* folder into your SilverStripe directory or **composer require otago/moodle**
- create *\_config/moodle.yml*
- run /dev/build?flush=all

And you've installed the module! The **examples/MoodleExamplePage.php.example** file contains three example web service requests that to help you get started.

You'll need to configure **moodle.yml** with a password/username or a token supplied by Moodle. *(Under Site administration &gt; Advanced features &gt; Plugins &gt; Web services &gt; Manage tokens)*

Example **moodle.yml** file:

```
---
Name: MoodleWebservice
---
OP\MoodleWebservice:
    authentication:
        username: my_moodle_username
        password: my_password
        service: webservice_name
        statictoken:
        locationTest: http://moodle.yourtertiaryaddress.com/
        locationDev: http://moodle.yourtertiaryaddress.com/
        locationLive: http://moodle.yourtertiaryaddress.com/

```

*Your Moodle instance will need to be configured to accept web service requests.*

Example calls
-------------

[](#example-calls)

```
/**
 * returns a user's profile
 * @return \Dataobject|null
 */
public function getUserProfile() {
	// connect to moodle
	$moodle = MoodleWebservice::connect();
	if(!$moodle) {
		return Debug::message('Failed to connect to Moodle Webservice');
	}

	// create a user list containing one generic user
	$params = array('userlist' => array(
		(object) array(
			'userid'=>'2',
			'courseid' => '1'
		)
	));

	// call the function core_user_get_course_user_profiles
	$userprofile = $moodle->call ('core_user_get_course_user_profiles', $params);

	// return it
	return $userprofile->Data();
}

```

### Example 2: get a list of programmes from a user

[](#example-2-get-a-list-of-programmes-from-a-user)

```
$moodle = MoodleWebservice::connect();
if(!$moodle) {
	return Debug::message('Failed to connect to Moodle Webservice');
}

// find programmes belonging to this user
$params = array('userid' => '2');
$courselist = $moodle->call ('core_enrol_get_users_courses', $params);
return $courselist->Data();

```

### Example 3: find a user by their email address

[](#example-3-find-a-user-by-their-email-address)

```
$moodle = MoodleWebservice::connect();
if(!$moodle) {
	return Debug::message('Failed to connect to Moodle Webservice');
}

$params = array('values' => array('email@op.ac.nz'), 'field' => 'email');
$userdata = $moodle->call ('core_user_get_users_by_field', $params);

return $userdata->Data();

```

Configure Moodle
----------------

[](#configure-moodle)

The most difficult integration task for this module will be configuring your Moodle instance to allow web service requests. There are many resources on the web explaining how to do this, but by far the most helpful is the Moodle check list under *Site administration &gt; Advanced features &gt; Plugins &gt; Web services &gt; Overview.*

[![location of overview in moodle](images/m1.png)](images/m1.png)

### Moodle configuration summary:

[](#moodle-configuration-summary)

1. Create a user that will be used for the service
2. Create the roll for this user, with access to the web services
3. Assign your new roll to the user
4. Create an external service [![creating an external service](images/m2.png)](images/m2.png)*Note: Moodle 2.5 users will have to manually set the shortname in the db [![setting the shortname using phpmyadmin](images/m3.png)](images/m3.png)*
5. Add the functions you want to call to the external service [![adding functions under the External services page](images/m4.png)](images/m4.png)

Requirements
------------

[](#requirements)

1. *cURL PHP module*
2. *Moodle 2.2+ for JSON/REST*
3. *SilverStripe 3.x*

Integration Tests
-----------------

[](#integration-tests)

1. Create MoodleExamplePage on a test instance
2. Save and load the page
3. Update MoodleExamplePage.php to relevent user IDs
4. View the raw output by using `Debug::show();` on the output from `$moodle->call()`

Troubleshooting &amp; Useful Tools
----------------------------------

[](#troubleshooting--useful-tools)

*I recommend using [Advanced REST Client](https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo) for Google Chrome for debugging purposes.*

> debuging your moodleWebService:
>
> - Make sure your $params match the API docs (Under Site administration &gt; Advanced features &gt; Plugins &gt; Web services &gt; API Documentation)
> - Moodle's API Documentation can be notirious to read, make sure you tripple check the varibles you're using
> - `Debug::show()` your call()
> - `die(print_r($url, true));` inside MoodleWebservice-&gt;call()
> - Make sure it's working using *Advanced REST Client*

### common errors

[](#common-errors)

- **Invalid parameter value detected** - match your params with the Moodle web service client documentation
- **Access to the function XXXXXX() is not allowed.** - add this function to the external service (see Project Setup)
- **functions return nothing** - enable debugging mode, you'll see debug messages.

Contributing changes
--------------------

[](#contributing-changes)

- *Fork on git*
- *Raise an issue*

License
-------

[](#license)

BSD

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~419 days

Recently: every ~628 days

Total

9

Last Release

113d ago

Major Versions

v3.0 → v4.02018-09-26

v4.0.5 → v5.02024-08-06

v5.0 → v6.02026-01-26

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/67215?v=4)[torleif](/maintainers/torleif)[@torleif](https://github.com/torleif)

---

Top Contributors

[![torleif](https://avatars.githubusercontent.com/u/67215?v=4)](https://github.com/torleif "torleif (7 commits)")[![Alastairkn](https://avatars.githubusercontent.com/u/15573766?v=4)](https://github.com/Alastairkn "Alastairkn (2 commits)")

---

Tags

web servicesilverstripemoodle

### Embed Badge

![Health badge](/badges/otago-moodle/health.svg)

```
[![Health](https://phpackages.com/badges/otago-moodle/health.svg)](https://phpackages.com/packages/otago-moodle)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
