mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
Merge branch 'MDL-51371-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
f95452b84f
4 changed files with 173 additions and 1 deletions
|
@ -2316,6 +2316,108 @@ class core_course_external extends external_api {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 3.0
|
||||
*/
|
||||
public static function 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 get_course_module($cmid) {
|
||||
|
||||
$params = self::validate_parameters(self::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 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'),
|
||||
'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),
|
||||
'indent' => 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()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1522,4 +1522,66 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
|||
$this->assertEmpty($event->other);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_course_module
|
||||
*/
|
||||
public function test_get_course_module() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$this->setAdminUser();
|
||||
$course = self::getDataGenerator()->create_course();
|
||||
$record = array(
|
||||
'course' => $course->id,
|
||||
'name' => 'First Chat'
|
||||
);
|
||||
$options = array(
|
||||
'idnumber' => 'ABC',
|
||||
'visible' => 0
|
||||
);
|
||||
// Hidden activity.
|
||||
$chat = self::getDataGenerator()->create_module('chat', $record, $options);
|
||||
|
||||
// Test admin user can see the complete hidden activity.
|
||||
$result = core_course_external::get_course_module($chat->cmid);
|
||||
$result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
|
||||
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
// Test we retrieve all the fields.
|
||||
$this->assertCount(21, $result['cm']);
|
||||
$this->assertEquals($record['name'], $result['cm']['name']);
|
||||
$this->assertEquals($options['idnumber'], $result['cm']['idnumber']);
|
||||
|
||||
$student = $this->getDataGenerator()->create_user();
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
|
||||
self::getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id);
|
||||
$this->setUser($student);
|
||||
|
||||
// The user shouldn't be able to see the activity.
|
||||
try {
|
||||
core_course_external::get_course_module($chat->cmid);
|
||||
$this->fail('Exception expected due to invalid permissions.');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('requireloginerror', $e->errorcode);
|
||||
}
|
||||
|
||||
// Make module visible.
|
||||
set_coursemodule_visible($chat->cmid, 1);
|
||||
|
||||
// Test student user.
|
||||
$result = core_course_external::get_course_module($chat->cmid);
|
||||
$result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result);
|
||||
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
// Test we retrieve only the few files we can see.
|
||||
$this->assertCount(11, $result['cm']);
|
||||
$this->assertEquals($chat->cmid, $result['cm']['id']);
|
||||
$this->assertEquals($course->id, $result['cm']['course']);
|
||||
$this->assertEquals('chat', $result['cm']['modname']);
|
||||
$this->assertEquals($chat->id, $result['cm']['instance']);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -742,6 +742,13 @@ $functions = array(
|
|||
'type' => 'write'
|
||||
),
|
||||
|
||||
'core_course_get_course_module' => array(
|
||||
'classname' => 'core_course_external',
|
||||
'methodname' => 'get_course_module',
|
||||
'classpath' => 'course/externallib.php',
|
||||
'description' => 'Return information about a course module',
|
||||
'type' => 'read'
|
||||
),
|
||||
|
||||
// === course category related functions ===
|
||||
|
||||
|
@ -1192,6 +1199,7 @@ $services = array(
|
|||
'mod_forum_view_forum',
|
||||
'core_course_view_course',
|
||||
'core_course_search_courses',
|
||||
'core_course_get_course_module',
|
||||
'core_completion_get_activities_completion_status',
|
||||
'core_notes_get_course_notes',
|
||||
'core_completion_get_course_completion_status',
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2015092204.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2015092300.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue