MDL-50351 scorm: New Web Service mod_scorm_get_scorm_scoes
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
0f7f30021a
commit
dfe927c8d6
@@ -1207,6 +1207,7 @@ $services = array(
|
||||
'core_user_add_user_private_files',
|
||||
'mod_assign_view_grading_table',
|
||||
'mod_scorm_view_scorm',
|
||||
'mod_scorm_get_scorm_scoes',
|
||||
'mod_scorm_get_scorm_attempt_count',
|
||||
'mod_page_view_page',
|
||||
'mod_resource_view_resource',
|
||||
|
||||
@@ -182,4 +182,87 @@ class mod_scorm_external extends external_api {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the parameters for get_scorms_by_courses.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function get_scorm_scoes_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'scormid' => new external_value(PARAM_INT, 'scorm instance id'),
|
||||
'organization' => new external_value(PARAM_RAW, 'organization id', VALUE_DEFAULT, '')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all the scoes data related to the given scorm id
|
||||
*
|
||||
* @param int $scormid the scorm id
|
||||
* @param string $organization the organization id
|
||||
* @return array warnings and the scoes data
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function get_scorm_scoes($scormid, $organization = '') {
|
||||
global $DB;
|
||||
|
||||
$params = self::validate_parameters(self::get_scorm_scoes_parameters(),
|
||||
array('scormid' => $scormid, 'organization' => $organization));
|
||||
|
||||
$scoes = array();
|
||||
$warnings = array();
|
||||
|
||||
$scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST);
|
||||
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
|
||||
|
||||
$context = context_module::instance($cm->id);
|
||||
self::validate_context($context);
|
||||
|
||||
// Check settings / permissions to view the SCORM.
|
||||
scorm_require_available($scorm, true, $context);
|
||||
|
||||
if (!$scoes = scorm_get_scoes($scorm->id, $params['organization'])) {
|
||||
// Function scorm_get_scoes return false, not an empty array.
|
||||
$scoes = array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['scoes'] = $scoes;
|
||||
$result['warnings'] = $warnings;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the get_scorm_scoes return value.
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function get_scorm_scoes_returns() {
|
||||
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'scoes' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'sco id'),
|
||||
'scorm' => new external_value(PARAM_INT, 'scorm id'),
|
||||
'manifest' => new external_value(PARAM_NOTAGS, 'manifest id'),
|
||||
'organization' => new external_value(PARAM_NOTAGS, 'organization id'),
|
||||
'parent' => new external_value(PARAM_NOTAGS, 'parent'),
|
||||
'identifier' => new external_value(PARAM_NOTAGS, 'identifier'),
|
||||
'launch' => new external_value(PARAM_NOTAGS, 'launch file'),
|
||||
'scormtype' => new external_value(PARAM_ALPHA, 'scorm type (asset, sco)'),
|
||||
'title' => new external_value(PARAM_NOTAGS, 'sco title'),
|
||||
'sortorder' => new external_value(PARAM_INT, 'sort order'),
|
||||
), 'SCORM SCO data'
|
||||
)
|
||||
),
|
||||
'warnings' => new external_warnings(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,4 +41,12 @@ $functions = array(
|
||||
'type' => 'read',
|
||||
'capabilities' => ''
|
||||
),
|
||||
|
||||
'mod_scorm_get_scorm_scoes' => array(
|
||||
'classname' => 'mod_scorm_external',
|
||||
'methodname' => 'get_scorm_scoes',
|
||||
'description' => 'Returns a list containing all the scoes data related to the given scorm id',
|
||||
'type' => 'read',
|
||||
'capabilities' => ''
|
||||
),
|
||||
);
|
||||
|
||||
@@ -201,4 +201,88 @@ class mod_scorm_external_testcase extends externallib_advanced_testcase {
|
||||
$this->setExpectedException('moodle_exception');
|
||||
mod_scorm_external::get_scorm_attempt_count($this->scorm->id, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get scorm scoes
|
||||
*/
|
||||
public function test_mod_scorm_get_scorm_scoes() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Create users.
|
||||
$student = self::getDataGenerator()->create_user();
|
||||
$teacher = self::getDataGenerator()->create_user();
|
||||
|
||||
// Set to the student user.
|
||||
self::setUser($student);
|
||||
|
||||
// Create courses to add the modules.
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
|
||||
// First scorm, dates restriction.
|
||||
$record = new stdClass();
|
||||
$record->course = $course->id;
|
||||
$record->timeopen = time() + DAYSECS;
|
||||
$record->timeclose = $record->timeopen + DAYSECS;
|
||||
$scorm = self::getDataGenerator()->create_module('scorm', $record);
|
||||
|
||||
// Users enrolments.
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
$teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
|
||||
$this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id, 'manual');
|
||||
$this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id, 'manual');
|
||||
|
||||
// Retrieve my scoes, warning!.
|
||||
try {
|
||||
mod_scorm_external::get_scorm_scoes($scorm->id);
|
||||
$this->fail('Exception expected due to invalid dates.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('notopenyet', $e->errorcode);
|
||||
}
|
||||
|
||||
$scorm->timeopen = time() - DAYSECS;
|
||||
$scorm->timeclose = time() - HOURSECS;
|
||||
$DB->update_record('scorm', $scorm);
|
||||
|
||||
try {
|
||||
mod_scorm_external::get_scorm_scoes($scorm->id);
|
||||
$this->fail('Exception expected due to invalid dates.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('expired', $e->errorcode);
|
||||
}
|
||||
|
||||
// Retrieve my scoes, user with permission.
|
||||
self::setUser($teacher);
|
||||
$result = mod_scorm_external::get_scorm_scoes($scorm->id);
|
||||
$result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
|
||||
$this->assertCount(2, $result['scoes']);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
|
||||
$scoes = scorm_get_scoes($scorm->id);
|
||||
$sco = array_shift($scoes);
|
||||
$this->assertEquals((array) $sco, $result['scoes'][0]);
|
||||
|
||||
$sco = array_shift($scoes);
|
||||
// Remove specific sco data.
|
||||
unset($sco->isvisible);
|
||||
unset($sco->parameters);
|
||||
$this->assertEquals((array) $sco, $result['scoes'][1]);
|
||||
|
||||
// Use organization.
|
||||
$organization = 'golf_sample_default_org';
|
||||
$result = mod_scorm_external::get_scorm_scoes($scorm->id, $organization);
|
||||
$result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
|
||||
$this->assertCount(1, $result['scoes']);
|
||||
$this->assertEquals($organization, $result['scoes'][0]['organization']);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
|
||||
// Test invalid instance id.
|
||||
try {
|
||||
mod_scorm_external::get_scorm_scoes(0);
|
||||
$this->fail('Exception expected due to invalid instance id.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('invalidrecord', $e->errorcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015091400; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2015091402; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2015050500; // Requires this Moodle version.
|
||||
$plugin->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->cron = 300;
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2015091000.03; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2015091000.05; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user