Moodle
  1. Moodle
  2. MDL-26250

Create a web service function that enrols users to a certain course

    Details

    • Testing Instructions:
      Hide

      This web service function is for developer so it needs to be tested by developer.

      In order to test, create a web service client and call the web service function. A good test is to try to to enrol two users in two differents courses.

      Look at http://docs.moodle.org/en/Web_Services for information how to create a web service client.

      Show
      This web service function is for developer so it needs to be tested by developer. In order to test, create a web service client and call the web service function. A good test is to try to to enrol two users in two differents courses. Look at http://docs.moodle.org/en/Web_Services for information how to create a web service client.
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull from Repository:
      git@github.com:mouneyrac/moodle.git
    • Pull Master Branch:
      MDL-26250-final6

      Description

      Something like that (I'm just writing this on the fly, need to finish):

      moodle_enrol_users:
      ------------------

      public static function enrol_users_parameters() {
              return new external_function_parameters(
                  array(
                      'enrolments' => new external_multiple_structure(
                          new external_single_structure(
                              array(
                                  'roleid'    => new external_value(PARAM_INT, 'Role to assign to the user'),
                                  'userid'    => new external_value(PARAM_INT, 'The user that is going to be enrolled'),
                                  'contextid' => new external_value(PARAM_INT, 'The context to enrol the user role in'),
                              )
                          )
                      )
                  )
              );
          }
       
      /**
           * Manual enrolment of users
           *
           * @param array $enrolments  An array of manual user enrolment
           * @return null
           */
          public static function enrol_users($enrolments) {
              global $DB, $USER;
       
              $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments'=>$enrolments));
       
              $transaction = $DB->start_delegated_transaction();
       
              foreach ($params['enrolments'] as $enrolment) {
                  // Ensure the current user is allowed to run this function in the enrolment context
                  $context = get_context_instance_by_id($enrolment['contextid']);
                  self::validate_context($context);
                  require_capability('moodle/role:assign', $context); //TODO: there is probably a capability related to enrolment, look for it and check on it it.
       
                  $instance = $DB->get_record('enrol', array('courseid' => $context->instanceid, 'enrol' => 'manual'));
                  $enrol = enrol_get_plugin('manual');
                  $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid']);
       
                  //TODO: maybe return a array of success/fail
              }
       
              $transaction->allow_commit();
          }
       
       /**
           * Returns description of method result value
           * @return external_description
           */
          public static function enrol_users_returns() {
              return null;
          }
       

        Gliffy Diagrams

          Issue Links

            Activity

            Jérôme Mouneyrac created issue -
            Jérôme Mouneyrac made changes -
            Field Original Value New Value
            Description Something like that (I'm just writing this on the fly, need to finish):

            moodle_enrol_users:
            ------------------

            {code}
            public static function enrol_users_parameters() {
                    return new external_function_parameters(
                        array(
                            'enrolments' => new external_multiple_structure(
                                new external_single_structure(
                                    array(
                                        'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
                                        'userid' => new external_value(PARAM_INT, 'The user that is going to be assigned'),
                                        'contextid' => new external_value(PARAM_INT, 'The context to assign the user role in'),
                                    )
                                )
                            )
                        )
                    );
                }

            /**
                 * Manual enrolment of users
                 *
                 * @param array $enrolments An array of manual user enrolment
                 * @return null
                 */
                public static function enrol_users($enrolments) {
                    global $DB, $USER;

                    $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments'=>$enrolments));

                    $transaction = $DB->start_delegated_transaction();

                    foreach ($params['enrolments'] as $enrolment) {
                        // Ensure the current user is allowed to run this function in the enrolment context
                        $context = get_context_instance_by_id($enrolment['contextid']);
                        self::validate_context($context);
                        require_capability('moodle/role:assign', $context); //TODO: there is probably a capability related to enrolment, look for it and check on it it.

                        $instance = $DB->get_record('enrol', array('courseid' => $context->instanceid, 'enrol' => 'manual'));
                        $enrol = enrol_get_plugin('manual');
                        $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid']);

                        //TODO: maybe return a array of success/fail
                    }

                    $transaction->allow_commit();
                }

             /**
                 * Returns description of method result value
                 * @return external_description
                 */
                public static function role_assign_returns() {
                    return null;
                }

            {code}
            Something like that (I'm just writing this on the fly, need to finish):

            moodle_enrol_users:
            ------------------

            {code}
            public static function enrol_users_parameters() {
                    return new external_function_parameters(
                        array(
                            'enrolments' => new external_multiple_structure(
                                new external_single_structure(
                                    array(
                                        'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
                                        'userid' => new external_value(PARAM_INT, 'The user that is going to be enrolled'),
                                        'contextid' => new external_value(PARAM_INT, 'The context to enrol the user role in'),
                                    )
                                )
                            )
                        )
                    );
                }

            /**
                 * Manual enrolment of users
                 *
                 * @param array $enrolments An array of manual user enrolment
                 * @return null
                 */
                public static function enrol_users($enrolments) {
                    global $DB, $USER;

                    $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments'=>$enrolments));

                    $transaction = $DB->start_delegated_transaction();

                    foreach ($params['enrolments'] as $enrolment) {
                        // Ensure the current user is allowed to run this function in the enrolment context
                        $context = get_context_instance_by_id($enrolment['contextid']);
                        self::validate_context($context);
                        require_capability('moodle/role:assign', $context); //TODO: there is probably a capability related to enrolment, look for it and check on it it.

                        $instance = $DB->get_record('enrol', array('courseid' => $context->instanceid, 'enrol' => 'manual'));
                        $enrol = enrol_get_plugin('manual');
                        $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid']);

                        //TODO: maybe return a array of success/fail
                    }

                    $transaction->allow_commit();
                }

             /**
                 * Returns description of method result value
                 * @return external_description
                 */
                public static function enrol_users_returns() {
                    return null;
                }

            {code}
            Martin Dougiamas made changes -
            Labels triaged
            Fix Version/s STABLE backlog [ 10463 ]
            Martin Dougiamas made changes -
            Fix Version/s STABLE Sprint 6 [ 10535 ]
            Fix Version/s STABLE backlog [ 10463 ]
            Jérôme Mouneyrac made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-374 [ PULL-374 ]
            Jérôme Mouneyrac made changes -
            Status In Progress [ 3 ] Ready for review [ 10010 ]
            Resolution Fixed [ 1 ]
            Petr Skoda made changes -
            Resolution Fixed [ 1 ]
            Status Ready for review [ 10010 ] Reopened [ 4 ]
            Jérôme Mouneyrac made changes -
            Status Reopened [ 4 ] In Progress [ 3 ]
            Martin Dougiamas made changes -
            Fix Version/s STABLE Sprint 7 [ 10540 ]
            Fix Version/s STABLE Sprint 6 [ 10535 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-449 [ PULL-449 ]
            Jérôme Mouneyrac made changes -
            Status In Progress [ 3 ] Ready for review [ 10010 ]
            Resolution Fixed [ 1 ]
            Petr Skoda made changes -
            Resolution Fixed [ 1 ]
            Status Ready for review [ 10010 ] Reopened [ 4 ]
            Jérôme Mouneyrac made changes -
            Status Reopened [ 4 ] In Progress [ 3 ]
            Jérôme Mouneyrac made changes -
            Link This issue is blocked by MDL-26822 [ MDL-26822 ]
            Jérôme Mouneyrac made changes -
            Status In Progress [ 3 ] Ready for review [ 10010 ]
            Resolution Fixed [ 1 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-457 [ PULL-457 ]
            Petr Skoda made changes -
            Resolution Fixed [ 1 ]
            Status Ready for review [ 10010 ] Reopened [ 4 ]
            Jérôme Mouneyrac made changes -
            Fix Version/s STABLE Sprint 8 [ 10541 ]
            Fix Version/s STABLE Sprint 7 [ 10540 ]
            Jérôme Mouneyrac made changes -
            Status Reopened [ 4 ] In Progress [ 3 ]
            Jérôme Mouneyrac made changes -
            Status In Progress [ 3 ] Ready for review [ 10010 ]
            Resolution Fixed [ 1 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-515 [ PULL-515 ]
            Jérôme Mouneyrac made changes -
            Resolution Fixed [ 1 ]
            Status Ready for review [ 10010 ] Reopened [ 4 ]
            Jérôme Mouneyrac made changes -
            Status Reopened [ 4 ] In Progress [ 3 ]
            Helen Foster made changes -
            Fix Version/s STABLE backlog [ 10463 ]
            Fix Version/s STABLE Sprint 8 [ 10541 ]
            moodle.com made changes -
            Fix Version/s STABLE Sprint 8 [ 10541 ]
            Fix Version/s STABLE backlog [ 10463 ]
            Martin Dougiamas made changes -
            Fix Version/s STABLE Sprint 9 [ 10550 ]
            Fix Version/s STABLE Sprint 8 [ 10541 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-590 [ PULL-590 ]
            Jérôme Mouneyrac made changes -
            Link This issue has been marked as being related by MDL-27229 [ MDL-27229 ]
            Jérôme Mouneyrac made changes -
            Link This issue will be resolved by PULL-691 [ PULL-691 ]
            Jérôme Mouneyrac made changes -
            Status In Progress [ 3 ] Ready for review [ 10010 ]
            Resolution Fixed [ 1 ]
            Jérôme Mouneyrac made changes -
            Fix Version/s STABLE Sprint 10 [ 10551 ]
            Fix Version/s STABLE Sprint 9 [ 10550 ]
            Martin Dougiamas made changes -
            Workflow MDL Workflow [ 67471 ] MDL Full Workflow [ 76458 ]
            Martin Dougiamas made changes -
            Status Waiting for review [ 10010 ] Closed [ 6 ]
            Martin Dougiamas made changes -
            Resolution Fixed [ 1 ]
            Status Closed [ 6 ] Reopened [ 4 ]
            Jérôme Mouneyrac made changes -
            Status Reopened [ 4 ] Development in progress [ 3 ]
            Jérôme Mouneyrac made changes -
            Pull Master Diff URL https://github.com/mouneyrac/moodle/commit/c978f59a93358b94404caa94d552e8829e8f0b22
            Pull Master Branch MDL-26250-final5
            Pull from Repository git@github.com:mouneyrac/moodle.git
            Jérôme Mouneyrac made changes -
            Pull 2.0 Diff URL https://github.com/mouneyrac/moodle/commit/c3b6ff99b101ee49542bd8c530435c12ea921fe5
            Pull 2.0 Branch MDL-26250-20STABLE
            Peer reviewer andyjdavis
            Jérôme Mouneyrac made changes -
            Status Development in progress [ 3 ] Waiting for peer review [ 10012 ]
            Jérôme Mouneyrac made changes -
            Testing Instructions This web service function is for developer so it needs to be tested by developer.

            In order to test, create a web service client and call the web service function. A good test is to try to to enrol two users in two differents courses.

            Look at http://docs.moodle.org/en/Web_Services for information how to create a web service client.
            Jérôme Mouneyrac made changes -
            Peer reviewer andyjdavis rwijaya
            Jérôme Mouneyrac made changes -
            Link This issue has a non-specific relationship to MDL-27320 [ MDL-27320 ]
            Jérôme Mouneyrac made changes -
            Link This issue has been marked as being related by MDL-27321 [ MDL-27321 ]
            moodle.com made changes -
            Original Estimate 0 minutes [ 0 ]
            Remaining Estimate 0 minutes [ 0 ]
            Status Waiting for peer review [ 10012 ] Development in progress [ 3 ]
            Jérôme Mouneyrac made changes -
            Status Development in progress [ 3 ] Waiting for integration review [ 10010 ]
            Sam Hemelryk made changes -
            Labels triaged ci pullweek-2011-18
            Sam Hemelryk made changes -
            Labels ci pullweek-2011-18
            Sam Hemelryk made changes -
            Labels triaged
            Sam Hemelryk made changes -
            Attachment test.php [ 23771 ]
            Sam Hemelryk made changes -
            Status Waiting for integration review [ 10010 ] Integration review in progress [ 10004 ]
            Integrator samhemelryk
            Sam Hemelryk made changes -
            Status Integration review in progress [ 10004 ] Waiting for testing [ 10005 ]
            Sam Hemelryk made changes -
            Labels triaged ci pullweek-2011-18
            Rossiani Wijaya made changes -
            Status Waiting for testing [ 10005 ] Testing in progress [ 10011 ]
            Tester rwijaya
            Rossiani Wijaya made changes -
            Status Testing in progress [ 10011 ] Tested [ 10006 ]
            Rossiani Wijaya made changes -
            Link This issue has a non-specific relationship to MDL-27388 [ MDL-27388 ]
            Eloy Lafuente (stronk7) made changes -
            Labels ci pullweek-2011-18 ci emergencypull pullweek-2011-18
            Eloy Lafuente (stronk7) made changes -
            Status Tested [ 10006 ] Closed [ 6 ]
            Fix Version/s 2.0.3 [ 10537 ]
            Resolution Fixed [ 1 ]
            Eloy Lafuente (stronk7) made changes -
            Labels ci emergencypull pullweek-2011-18 emergencypull pullweek-2011-18
            Eloy Lafuente (stronk7) made changes -
            Integration date 6/May/11
            Eloy Lafuente (stronk7) made changes -
            Fix Version/s STABLE Sprint 10 [ 10551 ]

              People

              • Votes:
                6 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: