From e0d6d10a83177f47c738983876af32d70e879698 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 17 Apr 2015 14:57:19 +0200 Subject: [PATCH] MDL-49796 assign: New external function view_grading_table --- lib/db/services.php | 1 + mod/assign/db/services.php | 11 ++++++- mod/assign/externallib.php | 66 ++++++++++++++++++++++++++++++++++++++ mod/assign/version.php | 2 +- version.php | 2 +- 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/lib/db/services.php b/lib/db/services.php index e3c54183a69..7803aa83a59 100644 --- a/lib/db/services.php +++ b/lib/db/services.php @@ -1139,6 +1139,7 @@ $services = array( 'mod_url_view_url', 'core_user_get_users_by_field', 'core_user_add_user_private_files', + 'mod_assign_view_grading_table', ), 'enabled' => 0, 'restrictedusers' => 0, diff --git a/mod/assign/db/services.php b/mod/assign/db/services.php index 3061e78812b..e6595190cff 100644 --- a/mod/assign/db/services.php +++ b/mod/assign/db/services.php @@ -144,6 +144,15 @@ $functions = array( 'classpath' => 'mod/assign/externallib.php', 'description' => 'Reveal the identities for a blind marking assignment', 'type' => 'write' - ) + ), + + 'mod_assign_view_grading_table' => array( + 'classname' => 'mod_assign_external', + 'methodname' => 'view_grading_table', + 'classpath' => 'mod/assign/externallib.php', + 'description' => 'Simulate the web interface grading table view', + 'type' => 'write', + 'capabilities' => 'mod/assign:view, mod/assign:viewgrades' + ), ); diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index f348ac3cb5a..412ddc3d4f9 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -2050,4 +2050,70 @@ class mod_assign_external extends external_api { public static function copy_previous_attempt_returns() { return new external_warnings(); } + + /** + * Returns description of method parameters + * + * @return external_function_parameters + * @since Moodle 3.0 + */ + public static function view_grading_table_parameters() { + return new external_function_parameters( + array( + 'assignid' => new external_value(PARAM_INT, 'assign instance id') + ) + ); + } + + /** + * Simulate the web interface grading table view. + * + * @param int $assignid the assign instance id + * @return array of warnings and status result + * @since Moodle 3.0 + * @throws moodle_exception + */ + public static function view_grading_table($assignid) { + global $DB, $CFG; + require_once($CFG->dirroot . "/mod/assign/locallib.php"); + + $params = self::validate_parameters(self::view_grading_table_parameters(), + array( + 'assignid' => $assignid + )); + $warnings = array(); + + // Request and permission validation. + $assign = $DB->get_record('assign', array('id' => $params['assignid']), 'id', MUST_EXIST); + list($course, $cm) = get_course_and_cm_from_instance($assign, 'assign'); + + $context = context_module::instance($cm->id); + self::validate_context($context); + + require_capability('mod/assign:view', $context); + + $assign = new assign($context, null, null); + $assign->require_view_grades(); + \mod_assign\event\grading_table_viewed::create_from_assign($assign)->trigger(); + + $result = array(); + $result['status'] = true; + $result['warnings'] = $warnings; + return $result; + } + + /** + * Returns description of method result value + * + * @return external_description + * @since Moodle 3.0 + */ + public static function view_grading_table_returns() { + return new external_single_structure( + array( + 'status' => new external_value(PARAM_BOOL, 'status: true if success'), + 'warnings' => new external_warnings() + ) + ); + } } diff --git a/mod/assign/version.php b/mod/assign/version.php index ad8e9619db5..8385cde4dec 100644 --- a/mod/assign/version.php +++ b/mod/assign/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2015051100; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015051101; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2015050500; // Requires this Moodle version. $plugin->cron = 60; diff --git a/version.php b/version.php index 35285c9ab70..3bb35ed062f 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2015071100.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2015071100.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. -- 2.43.0