MDL-49796 assign: New external function view_grading_table
authorJuan Leyva <juanleyvadelgado@gmail.com>
Fri, 17 Apr 2015 12:57:19 +0000 (14:57 +0200)
committerJuan Leyva <juanleyvadelgado@gmail.com>
Mon, 13 Jul 2015 07:25:23 +0000 (09:25 +0200)
lib/db/services.php
mod/assign/db/services.php
mod/assign/externallib.php
mod/assign/version.php
version.php

index e3c5418..7803aa8 100644 (file)
@@ -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,
index 3061e78..e659519 100644 (file)
@@ -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'
+        ),
 
 );
index f348ac3..412ddc3 100644 (file)
@@ -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()
+            )
+        );
+    }
 }
index ad8e961..8385cde 100644 (file)
@@ -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;
index 35285c9..3bb35ed 100644 (file)
@@ -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.