Skip to content

Utility classes for easily and consistently scaffolding API endpoints for Modo Labs XModule

Notifications You must be signed in to change notification settings

uoitwebteam/xmodule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XModule

Latest Stable Version Total Downloads Latest Unstable Version License

PHP library for easily and consistently scaffolding REST API endpoints for Modo Labs' XModule feature.

This library provides a suite of PHP classes that directly mirror Modo's collection of XModule elements. It aids in the creation of complex XModule layouts by removing the need for boilerplate JSON and ensuring all XModule pieces fit together seamlessly using object-oriented workflows and strongly-typed parameters.

After being built, scaffolded XModules can have their contents output in fully compliant JSON using only the json_encode result of a call to $xmodule->render().

Requirements

  • PHP >= 7.0.0

Installation

$ composer require ontariotechu/xmodule:dev-master

Don't forget to include Composer's autoloader once at the beginning of your application:

require __DIR__ . '/vendor/autoload.php';

Usage

Import the needed components into your server application:

use \XModule\Base\XModule;
use \XModule\Shared\Link;
use \XModule\Constants\LinkType;
use \XModule\ButtonContainer;
use \XModule\LinkButton;

Use the components to build XModule structures:

/**
 * Create a new XModule
 */
$xmodule = new XModule();

/**
 * Create XModule elements
 */
$buttonContainer = new ButtonContainer(['id' => 'link_buttons']);
$link = new Link('./', LinkType::RELATIVE_PATH);
$button = new LinkButton('Click here', ['link' => $link]);

/**
 * Attach your elements to each other and the XModule
 */
$buttonContainer->addButton($button)
$xmodule->addContent($buttonContainer);

/**
 * Render the output
 */
echo json_encode($xmodule->render());

Result:

{
  "metadata": {
    "version": "1"
  },
  "content": [
    {
      "elementType": "buttonContainer",
      "id": "link_buttons",
      "buttons": [
        {
          "elementType": "linkButton",
          "title": "Click here",
          "link": {
            "relativePath": "./"
          }
        }
      ]
    }
  ]
}

Documentation

General usage how-tos can be found in the wiki of this repository. The pages of the wiki are also presented in a single document inside usage.md for quick access.

Full class documentation is still pending, but in the meantime there are some very basic auto-generated docs that can be found in the /docs folder of this repository. Documentation can be regenerated or viewed using the included Composer scripts:

# regenerate
$ composer run-script build-docs

# view docs (http://0.0.0.0:8080)
$ composer run-script docs

Credits

  • Modo Labs created XModule and the mobile application software it is used in. All trademarks belong to them.

About

Utility classes for easily and consistently scaffolding API endpoints for Modo Labs XModule

Resources

Stars

Watchers

Forks

Packages

No packages published