Example #1
0
<?php

/*
|--------------------------------------------------------------------------
| xhr.php
|--------------------------------------------------------------------------
|
| This script is a proxy to perform a cross-domain XHR request. It
| expects a form POST with 2 parameters:
|   - endpoint (full URL to POST to)
|   - request (body of form POST)
|
*/
include_once 'config.php';
use LearnositySdk\Request\DataApi;
$security = array('consumer_key' => $consumer_key, 'domain' => $domain);
$endpoint = isset($_POST['endpoint']) ? $_POST['endpoint'] : null;
$data = isset($_POST['request']) ? json_decode($_POST['request'], true) : null;
$action = isset($_POST['action']) ? $_POST['action'] : 'get';
$dataapi = new DataApi();
$response = $dataapi->request($endpoint, $security, $consumer_secret, $data, $action);
if (strlen($response->getBody())) {
    echo $response->getBody();
} else {
    $err = $response->getError();
    echo $err['message'];
}
use LearnositySdk\Request\Init;
use LearnositySdk\Request\DataApi;
use LearnositySdk\Utils\Uuid;
$security = array('consumer_key' => $consumer_key, 'domain' => $domain, 'timestamp' => $timestamp);
/*
 * Array of cardsets (activities) you want to display
 */
$activityRefs = ['gallery_1', 'gallery_2', 'gallery_3', 'gallery_4', 'gallery_5', 'gallery_6'];
/*
 * First make a request to the Data API to retrieve all
 * card sets you want to appear on this gallery page.
 *
 * This assumes that each set has an equivalent `activity`
 * in the Learnosity Authoring site.
 */
$DataApi = new DataApi();
$response = $DataApi->request($url_data . '/latest/itembank/activities', $security, $consumer_secret, ['references' => $activityRefs]);
/*
 * Now that you have all activities, loop over them and
 * retrieve the first item in each. That will be the item
 * used as the preview card students will click on.
 */
if (!$response->getError()['code']) {
    $activities = json_decode($response->getBody(), true)['data'];
    $glossaryCards = [];
    $cardsetRef = [];
    foreach ($activities as $i => $activity) {
        $glossaryCards[] = $activity['data']['items'][0];
        $cardsetRef[] = $activity['reference'];
    }
}