Skip to content
Snippets Groups Projects
Commit 746ead31 authored by Ryan Smith's avatar Ryan Smith
Browse files

Returns the plugin.

parents
No related branches found
No related tags found
No related merge requests found
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.
# top-most EditorConfig file
root = true
# Unix-style newlines, 2 spaced tabs, UTF-8 with a newline ending
# across every file
[*]
end_of_line = lf
indent_style = space
indent_size = 4
charset = utf-8
.DS_STORE
*.sublime-project
*.sublime-workspace
vendor
language: php
php: 5.5
install: composer install --prefer-source --no-interaction
script: ./vendor/bin/phpunit
This diff is collapsed.
*THIS REPO IS UNDER HEAVY DEVELOPMENT AND IS NOT PRODUCTION READY*
# [Moodle Logstore Emitter](https://github.com/jlowe64/moodle-logstore-xapi)
> Emits events from the [Moodle](https://moodle.org/) Logstore as [xAPI](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md) statements.
[![Build Status](https://travis-ci.org/jlowe64/moodle-logstore-xapi.svg?branch=master)](https://travis-ci.org/jlowe64/moodle-logstore-xapi)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/LearningLocker/learninglocker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
- [Read documentation](https://github.com/jlowe64/moodle-logstore-xapi/blob/master/docs/readme.md).
- [Report bugs, enhancements, and questions](https://github.com/jlowe64/moodle-logstore-xapi/blob/master/contributing.md#issue-templates).
0.0.0
build.sh 0 → 100644
#!/usr/bin/env sh
rm -f xapi.zip
composer install --no-interaction --no-dev
cp -r . ../moodle_logstore_build
mv ../moodle_logstore_build xapi
zip -r xapi.zip xapi -x "xapi/.git/**/*"
rm -rf xapi
git add xapi.zip
git commit -m "Builds zip file."
git push
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External xapi log store plugin
*
* @package logstore_xapi
* @copyright 2015 Jerrett Fowler <jfowler@charitylearning.org>
* Ryan Smith <ryan.smith@ht2.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace logstore_xapi\log;
defined('MOODLE_INTERNAL') || die();
require_once __DIR__ . '/../../vendor/autoload.php';
use \tool_log\log\writer as log_writer;
use \tool_log\log\manager as log_manager;
use \tool_log\helper\store as helper_store;
use \tool_log\helper\reader as helper_reader;
use \tool_log\helper\buffered_writer as helper_writer;
use \core\event\base as event_base;
use \XREmitter\Controller as xapi_controller;
use \XREmitter\Repository as xapi_repository;
use \MXTranslator\Controller as translator_controller;
use \LogExpander\Controller as moodle_controller;
use \LogExpander\Repository as moodle_repository;
use \TinCan\RemoteLRS as tincan_remote_lrs;
use \moodle_exception as moodle_exception;
use \stdClass as php_obj;
class store extends php_obj implements log_writer {
use helper_store;
use helper_reader;
use helper_writer;
/**
* Constructs a new store.
* @param log_manager $manager
*/
public function __construct(log_manager $manager) {
$this->helper_setup($manager);
}
/**
* Should the event be ignored (not logged)?
* @param event_base $event
* @return bool
* @override helper_writer
*/
protected function is_event_ignored(event_base $event) {
return !(isset(moodle_controller::$routes[$event->eventname]) && $event->userid > 0);
}
/**
* Insert events in bulk to the database.
* @param array $events raw event data
* @override helper_writer
*/
protected function insert_event_entries(array $events) {
// Initializes required services.
$xapi_controller = new xapi_controller($this->connect_xapi_repository());
$moodle_controller = new moodle_controller($this->connect_moodle_repository());
$translator_controller = new translator_controller();
// Emits events to other APIs.
foreach ($events as $event) {
$moodle_event = $moodle_controller->createEvent($event);
$translator_event = $translator_controller->createEvent($moodle_event);
$xapi_event = $xapi_controller->createEvent($translator_event);
}
}
/**
* Determines if a connection exists to the store.
* @return boolean
*/
public function is_logging() {
try {
$this->connect_xapi_repository();
return true;
} catch (moodle_exception $ex) {
debugging('Cannot connect to LRS: ' . $e->getMessage(), DEBUG_DEVELOPER);
return false;
}
}
/**
* Creates a connection the xAPI store.
* @return xapi_repository
*/
private function connect_xapi_repository() {
return new xapi_repository(new tincan_remote_lrs(
$this->get_config('endpoint', ''),
'1.0.1',
$this->get_config('username', ''),
$this->get_config('password', '')
));
}
/**
* Creates a connection the xAPI store.
* @return moodle_repository
*/
private function connect_moodle_repository() {
global $DB;
global $CFG;
return new moodle_repository($DB, $CFG);
}
}
{
"name": "jlowe64/moodle-logstore-xapi",
"license": "GPL v3",
"autoload": {
"psr-4": {
"logstore_xapi\\": "classes/",
"Tests\\": "Tests/"
}
},
"require-dev": {
"phpunit/phpunit": "~4.6"
},
"require": {
"rusticisoftware/tincan": "0.12.*",
"learninglocker/moodle-log-expander": "~0.0",
"learninglocker/moodle-xapi-translator": "~0.0",
"learninglocker/xapi-recipe-emitter": "~0.0"
},
"scripts": {
"dev": [
"rm -rf vendor",
"composer install --prefer-source"
]
},
"prefer-stable": true,
"minimum-stability": "dev"
}
This diff is collapsed.
### Issue Templates
If you are reporting an issue, please click the links below and your issue will be prefilled with our template. You need to replace the parts of the template where you see `{{some text}}`.
- [Bug](../../issues/new?title={{Brief description of your bug}}&body=**Version**%0A{{branch}} at {{commit}} on {{version - found in your copy of the VERSION file}} %0A%0A**Steps to reproduce the bug**%0A{{steps}}%0A%0A**Expected behaviour**%0A{{feature}} should be {{expectedResult}} because {{reason}}.%0A%0A**Actual behaviour**%0A{{feature}} is {{actualResult}}.%0A%0A**Server information**%0A{{database}} with {{authentication}}.%0A%0A**Client information**%0AOS: {{operatingSystem}}%0ABrowser: {{browser}} version 1.0.1%0A%0A**Additional information**%0A{{additionalInfo}}): reports an feature that is not working as expected.
- [Enhancement](../../issues/new?title={{Brief description of your enhancement}}&body=**Motive**%0A{{why the enhancement is needed}}%0A%0A**Result**%0A{{what the enhancement is}}%0A%0A**Additional information**%0A{{additionalInfo}}): requests a removal, addition, or change of a feature.
- [Question](../../issues/new?title={{Brief description of your question}}&body={{question}}%3F): asks how a feature should be used or what the feature does.
### Code Structure
Repository = Data layer = Reads and writes data from a location (variable/DB/external API/etc).
Service = Business layer = Operates on data and transforms data from a given structure to a required structure.
1. [Get the requirements](#requirements).
2. [Download the plugin](#downloading).
3. [Install the plugin](#installing).
4. [Configure the plugin](#configuring)
## Requirements
You obviously need to have [Moodle](https://moodle.org/) installed first and you need to be logged in as an Admin.
## Downloading
#### Downloading via Zip (for users)
1. [Download the plugin](https://github.com/jlowe64/moodle-logstore-xapi/blob/master/xapi.zip?raw=true).
2. Go to "http://www.example.com/admin/tool/installaddon/index.php".
3. Drag and drop your download.
4. Click "Install the plugin from the ZIP file".
#### Downloading via Git (for developers)
1. Run `cd admin/tool/log/store/` from the root directory of Moodle.
2. Run `git clone git@github.com:jlowe64/moodle-logstore-xapi.git xapi`.
## Installing
1. Go to "http://www.example.com/admin/index.php".
2. Follow through the upgrade and enter your LRS details when required.
3. Go to "http://www.example.com/admin/settings.php?section=managelogging".
4. Enable the "Logstore xAPI" plugin.
## Configuring
1. Go to "http://www.example.com/admin/settings.php?section=logsettingxapi".
2. Modify your LRS details.
3. Click "Save changes".
- [Installation](installation.md)
- [Supported Events](#supported-events)
- [Plugin Design](#plugin-design)
- [Adding Events](#adding-events)
- [Plugin Release Process](#plugin-release-process)
## Supported Events
Moodle Event Name | xAPI Recipe Example
--- | ---
\core\event\course_viewed | [CourseViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/CourseViewed.json)
\mod_page\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_quiz\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_url\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_folder\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_book\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_scorm\event\course_module_viewed | [ModuleViewed](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/ModuleViewed.json)
\mod_quiz\event\attempt_preview_started | [AttemptStarted](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/AttemptStarted.json)
\mod_quiz\event\attempt_reviewed | [AttemptCompleted](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/AttemptCompleted.json)
\core\event\user_loggedin | [UserLoggedin](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/UserLoggedin.json)
\core\event\user_loggedout | [UserLoggedout](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/UserLoggedout.json)
\mod_assign\event\submission_graded | [AssignmentGraded](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/AssignmentGraded.json)
\mod_assign\event\assessable_submitted | [AssignmentSubmitted](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/examples/AssignmentSubmitted.json)
## Plugin Design
The plugin [controls and configures](../classes/log/store.php) the three parts listed below.
- [Moodle Log Expander](https://github.com/LearningLocker/Moodle-Log-Expander)
- [Moodle to xAPI Translator](https://github.com/LearningLocker/Moodle-xAPI-Translator)
- [xAPI Recipe Emitter](https://github.com/LearningLocker/xAPI-Recipe-Emitter)
The plugin uses the three parts listed above in the following way.
1. The plugin passes raw event data from the logstore_standard_log to the Expander.
2. The Expander expands events with data from your Moodle Database.
3. The plugin passes the expanded events from step 2 to the Translator.
4. The Translator translates expanded events to xAPI recipe options.
5. The plugin passes the translated events from step 4 to the Emitter.
6. The Emitter constructs the translated events as xAPI statements and emits them to the [configured LRS](installation.md#configuration).
These parts have been separated into their own repositories to improve their reusability since these parts will be used in other projects.
## Adding Events
Assuming you've already [installed (using Git)](installation.md), you'll need to follow the steps below to begin developing.
1. Run `cd admin/tool/log/store/xapi` from the root directory of Moodle.
2. Run `php -r "readfile('https://getcomposer.org/installer');" | php` to install Composer.
3. Run `php composer.phar dev` to install the dependencies from their Github repositories (rather than Packagist).
You'll now be able to modify and test events by updating the code inside the "vendor/learninglocker/moodle-log-expander", "vendor/learninglocker/moodle-xapi-translator", and "vendor/learninglocker/xapi-recipe-emitter" directories. If you've read the section on [plugin design](#plugin-design) you should understand what each of these directories are responsible for in this plugin. Each of the parts have their own documentation on their respective Github repositories (linked below).
- [Moodle Log Expander](https://github.com/LearningLocker/Moodle-Log-Expander/blob/master/docs/readme.md#adding-events)
- [Moodle to xAPI Translator](https://github.com/LearningLocker/Moodle-xAPI-Translator/blob/master/docs/readme.md#adding-events)
- [xAPI Recipe Emitter](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/readme.md#adding-events)
## Plugin Release Process
This process has been documented for collaborators (users that have write access to the repository) who are releasing new versions of this plugin.
1. Run `composer build` on the branch to be released.
2. Commit changes from step 1.
3. Create release on Github.
1. Document patches.
2. Document minor changes.
3. Document major changes.
4. Document migrations and additional notes.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External xapi log store plugin
*
* @package logstore_xapi
* @copyright 2015 Jerrett Fowler <jfowler@charitylearning.org>
* Ryan Smith <ryan.smith@ht2.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['endpoint'] = 'Endpoint';
$string['modulename'] = 'Logstore xAPI';
$string['modulenameplural'] = 'xAPI';
$string['modulename_help'] = 'Use the logstore xAPI module for... | The logstore xAPI plugin allows...';
$string['settings'] = 'General Settings';
$string['xapifieldset'] = 'Custom example fieldset';
$string['xapiname'] = 'xAPI name';
$string['xapiname_help'] = 'This is the content of the help tooltip associated with the xAPIname field. Markdown syntax is supported.';
$string['xapi'] = 'xAPI';
$string['password'] = 'Password';
$string['pluginadministration'] = 'Logstore xAPI administration';
$string['pluginname'] = 'Logstore xAPI';
$string['submit'] = 'Submit';
$string['username'] = 'Username';
$string['xapisettingstitle'] = 'Logstore xAPI Settings';
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
</phpunit>
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External xapi log store plugin
*
* @package logstore_xapi
* @copyright 2015 Jerrett Fowler <jfowler@charitylearning.org>
* Ryan Smith <ryan.smith@ht2.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
if ($hassiteconfig) {
//endpoint
$settings->add(new admin_setting_configtext('logstore_xapi/endpoint', get_string('endpoint', 'logstore_xapi'), '', 'http://your.domain.com/endpoint/location/', PARAM_TEXT));
//username
$settings->add(new admin_setting_configtext('logstore_xapi/username', get_string('username', 'logstore_xapi'), '', 'username', PARAM_TEXT));
//key or password
$settings->add(new admin_setting_configtext('logstore_xapi/password', get_string('password', 'logstore_xapi'), '', 'password', PARAM_TEXT));
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* External xapi log store plugin
*
* @package logstore_xapi
* @copyright 2015 Jerrett Fowler <jfowler@charitylearning.org>
* Ryan Smith <ryan.smith@ht2.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'logstore_xapi';
$plugin->version = 2015061700;
$plugin->release = '0.5';
$plugin->requires = 2014111002;
$plugin->maturity = MATURITY_BETA;
xapi.zip 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment