Skip to content

Commit

Permalink
New WS for retrieving activity modules information
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Sep 22, 2015
1 parent 03f0df9 commit f569aac
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 3 deletions.
20 changes: 19 additions & 1 deletion db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,23 @@
'classpath' => 'local/aspiredu/externallib.php',
'description' => 'Get all custom course settings',
'type' => 'read'
)
),

'local_aspiredu_core_course_get_course_module' => array(
'classname' => 'local_aspiredu_external',
'methodname' => 'core_course_get_course_module',
'classpath' => 'local/aspiredu/externallib.php',
'description' => 'Return information about a course module',
'type' => 'read'
),

'local_aspiredu_core_course_get_course_module_from_instance' => array(
'classname' => 'local_aspiredu_external',
'methodname' => 'core_course_get_course_module_from_instance',
'classpath' => 'local/aspiredu/externallib.php',
'description' => 'Return information about a course module',
'type' => 'read'
),
);

// We define the services to install as pre-build services. A pre-build service is not editable by administrator.
Expand Down Expand Up @@ -146,6 +162,8 @@
'local_aspiredu_mod_assign_get_assignments',
'local_aspiredu_mod_assign_get_submissions',
'local_aspiredu_get_custom_course_settings',
'local_aspiredu_core_course_get_course_module',
'local_aspiredu_core_course_get_course_module_from_instance',
),
'restrictedusers' => 1,
'enabled' => 1,
Expand Down
205 changes: 205 additions & 0 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2222,4 +2222,209 @@ public static function get_custom_course_settings_returns() {
);
}

/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.0
*/
public static function core_course_get_course_module_parameters() {
return new external_function_parameters(
array(
'cmid' => new external_value(PARAM_INT, 'The course module id')
)
);
}

/**
* Return information about a course module.
*
* @param int $cmid the course module id
* @return array of warnings and the course module
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function core_course_get_course_module($cmid) {

$params = self::validate_parameters(self::core_course_get_course_module_parameters(),
array(
'cmid' => $cmid,
));

$warnings = array();

$cm = get_coursemodule_from_id(null, $params['cmid'], 0, true, MUST_EXIST);
$context = context_module::instance($cm->id);
self::validate_context($context);

// If the user has permissions to manage the activity, return all the information.
if (has_capability('moodle/course:manageactivities', $context)) {
$info = $cm;
} else {
// Return information is safe to show to any user.
$info = new stdClass();
$info->id = $cm->id;
$info->course = $cm->course;
$info->module = $cm->module;
$info->modname = $cm->modname;
$info->instance = $cm->instance;
$info->section = $cm->section;
$info->sectionnum = $cm->sectionnum;
$info->groupmode = $cm->groupmode;
$info->groupingid = $cm->groupingid;
$info->completion = $cm->completion;
}
// Format name.
$info->name = format_string($cm->name, true, array('context' => $context));

$result = array();
$result['cm'] = $info;
$result['warnings'] = $warnings;
return $result;
}

/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 3.0
*/
public static function core_course_get_course_module_returns() {
return new external_single_structure(
array(
'cm' => new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'The course module id'),
'course' => new external_value(PARAM_INT, 'The course id'),
'module' => new external_value(PARAM_INT, 'The module type id'),
'name' => new external_value(PARAM_TEXT, 'The activity name'),

This comment has been minimized.

Copy link
@tim-schilling

tim-schilling Sep 28, 2015

Member

This apparently does not come back always as text, but as possibly html.

'modname' => new external_value(PARAM_COMPONENT, 'The module component name (forum, assign, etc..)'),
'instance' => new external_value(PARAM_INT, 'The activity instance id'),
'section' => new external_value(PARAM_INT, 'The module section id'),
'sectionnum' => new external_value(PARAM_INT, 'The module section number'),
'groupmode' => new external_value(PARAM_INT, 'Group mode'),
'groupingid' => new external_value(PARAM_INT, 'Grouping id'),
'completion' => new external_value(PARAM_INT, 'If completion is enabled'),
'idnumber' => new external_value(PARAM_RAW, 'Module id number', VALUE_OPTIONAL),
'added' => new external_value(PARAM_INT, 'Time added', VALUE_OPTIONAL),
'score' => new external_value(PARAM_INT, 'Score', VALUE_OPTIONAL),
'intent' => new external_value(PARAM_INT, 'Indentation', VALUE_OPTIONAL),
'visible' => new external_value(PARAM_INT, 'If visible', VALUE_OPTIONAL),
'visibleold' => new external_value(PARAM_INT, 'Visible old', VALUE_OPTIONAL),
'completiongradeitemnumber' => new external_value(PARAM_INT, 'Completion grade item', VALUE_OPTIONAL),
'completionview' => new external_value(PARAM_INT, 'Completion view setting', VALUE_OPTIONAL),
'completionexpected' => new external_value(PARAM_INT, 'Completion time expected', VALUE_OPTIONAL),
'showdescription' => new external_value(PARAM_INT, 'If the description is showed', VALUE_OPTIONAL),
'availability' => new external_value(PARAM_RAW, 'Availability settings', VALUE_OPTIONAL),
)
),
'warnings' => new external_warnings()
)
);
}

/**
* Returns description of method parameters
*
* @return external_function_parameters
* @since Moodle 3.0
*/
public static function core_course_get_course_module_from_instance_parameters() {
return new external_function_parameters(
array(
'module' => new external_value(PARAM_COMPONENT, 'The module name'),
'instance' => new external_value(PARAM_INT, 'The module instance id')
)
);
}

/**
* Return information about a course module.
*
* @param int $module the module name
* @param int $instance the module instance
* @return array of warnings and the course module
* @since Moodle 3.0
* @throws moodle_exception
*/
public static function core_course_get_course_module_from_instance($module, $instance) {

$params = self::validate_parameters(self::core_course_get_course_module_from_instance_parameters(),
array(
'module' => $module,
'instance' => $instance,
));

$warnings = array();

$cm = get_coursemodule_from_instance($params['module'], $params['instance'], 0, true, MUST_EXIST);
$context = context_module::instance($cm->id);
self::validate_context($context);

// If the user has permissions to manage the activity, return all the information.
if (has_capability('moodle/course:manageactivities', $context)) {
$info = $cm;
} else {
// Return information is safe to show to any user.
$info = new stdClass();
$info->id = $cm->id;
$info->course = $cm->course;
$info->module = $cm->module;
$info->modname = $cm->modname;
$info->instance = $cm->instance;
$info->section = $cm->section;
$info->sectionnum = $cm->sectionnum;
$info->groupmode = $cm->groupmode;
$info->groupingid = $cm->groupingid;
$info->completion = $cm->completion;
}
// Format name.
$info->name = format_string($cm->name, true, array('context' => $context));

$result = array();
$result['cm'] = $info;
$result['warnings'] = $warnings;
return $result;
}

/**
* Returns description of method result value
*
* @return external_description
* @since Moodle 3.0
*/
public static function core_course_get_course_module_from_instance_returns() {
return new external_single_structure(
array(
'cm' => new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'The course module id'),
'course' => new external_value(PARAM_INT, 'The course id'),
'module' => new external_value(PARAM_INT, 'The module type id'),
'name' => new external_value(PARAM_TEXT, 'The activity name'),

This comment has been minimized.

Copy link
@tim-schilling

tim-schilling Sep 28, 2015

Member

Same concern as above.

'modname' => new external_value(PARAM_COMPONENT, 'The module component name (forum, assign, etc..)'),
'instance' => new external_value(PARAM_INT, 'The activity instance id'),
'section' => new external_value(PARAM_INT, 'The module section id'),
'sectionnum' => new external_value(PARAM_INT, 'The module section number'),
'groupmode' => new external_value(PARAM_INT, 'Group mode'),
'groupingid' => new external_value(PARAM_INT, 'Grouping id'),
'completion' => new external_value(PARAM_INT, 'If completion is enabled'),
'idnumber' => new external_value(PARAM_RAW, 'Module id number', VALUE_OPTIONAL),
'added' => new external_value(PARAM_INT, 'Time added', VALUE_OPTIONAL),
'score' => new external_value(PARAM_INT, 'Score', VALUE_OPTIONAL),
'intent' => new external_value(PARAM_INT, 'Indentation', VALUE_OPTIONAL),
'visible' => new external_value(PARAM_INT, 'If visible', VALUE_OPTIONAL),
'visibleold' => new external_value(PARAM_INT, 'Visible old', VALUE_OPTIONAL),
'completiongradeitemnumber' => new external_value(PARAM_INT, 'Completion grade item', VALUE_OPTIONAL),
'completionview' => new external_value(PARAM_INT, 'Completion view setting', VALUE_OPTIONAL),
'completionexpected' => new external_value(PARAM_INT, 'Completion time expected', VALUE_OPTIONAL),
'showdescription' => new external_value(PARAM_INT, 'If the description is showed', VALUE_OPTIONAL),
'availability' => new external_value(PARAM_RAW, 'Availability settings', VALUE_OPTIONAL),
)
),
'warnings' => new external_warnings()
)
);
}

}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$plugin->version = 2015010120;
$plugin->version = 2015010122;
$plugin->requires = 2012120300;
$plugin->component = 'local_aspiredu';
$plugin->release = '1.5';
$plugin->release = '1.6';
$plugin->maturity = MATURITY_STABLE;

0 comments on commit f569aac

Please sign in to comment.