Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-10642

When remotely enrolling, should be passed to the remote server all user settings affecting student's privacy and mails

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 2.0
    • Component/s: MNet
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      When remotely enrolling a student, RPC should pass to the remote server all flags affecting the student's privacy (maildisplay) and how Moodle send mails (emailstop, mailformat, maildigest).
      These settings affect the user in the course even before his first log-in, when all user data are passed.

      I attach the two modified functions in enrol/mnet/enrol.php
      (modifications commented with [nicus] tag)

      ---8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<---
      function enrol_user($user, $courseid) {
      global $MNET, $MNET_REMOTE_CLIENT;

      $userrecord = get_record('user','username',addslashes($user['username']), 'mnethostid',$MNET_REMOTE_CLIENT->id);

      if ($userrecord == false) {
      $userrecord = new stdClass();
      $userrecord->username = addslashes($user['username']);
      $userrecord->email = addslashes($user['email']);
      $userrecord->firstname = addslashes($user['firstname']);
      $userrecord->lastname = addslashes($user['lastname']);

      // [nicus] added emailstop, mailformat, maildigest, maildisplay, lang, trackforums fields
      $userrecord->emailstop = addslashes($user['emailstop']);
      $userrecord->mailformat = addslashes($user['mailformat']);
      $userrecord->maildigest = addslashes($user['maildigest']);
      $userrecord->maildisplay = addslashes($user['maildisplay']);
      $userrecord->lang = addslashes($user['lang']);
      $userrecord->trackforums = addslashes($user['trackforums']);

      $userrecord->mnethostid = $MNET_REMOTE_CLIENT->id;

      if ($userrecord->id = insert_record('user', $userrecord))

      { $userrecord = get_record('user','id', $userrecord->id); }

      else

      { // TODO: Error out return false; }

      }

      if (! $course = get_record('course', 'id', $courseid) )

      { // TODO: Error out return false; }

      $courses = $this->available_courses();

      if (!empty($courses[$courseid])) {
      if (enrol_into_course($course, $userrecord, 'mnet'))

      { return true; }

      }
      return false;
      }

      ---8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<---
      function req_enrol_user($userid, $courseid) {
      global $CFG;
      global $USER;
      global $MNET;
      require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';

      // Prepare a basic user record
      // in case the remote host doesn't have it
      // [nicus] added emailstop, mailformat, maildigest, maildisplay, lang, trackforums fieldS
      $user = get_record('user', 'id', $userid, '','','','', 'username, email, firstname, lastname, emailstop, mailformat, maildigest, maildisplay, lang, trackforums');
      $user = (array)$user;

      $course = get_record('mnet_enrol_course', 'id', $courseid);

      // get the Service Provider info
      $mnet_sp = new mnet_peer();
      $mnet_sp->set_id($course->hostid);

      // set up the RPC request
      $mnetrequest = new mnet_xmlrpc_client();
      $mnetrequest->set_method('enrol/mnet/enrol.php/enrol_user');
      $mnetrequest->add_param($user);
      $mnetrequest->add_param($course->remoteid);

      // Thunderbirds are go! Do RPC call and store response
      if ($mnetrequest->send($mnet_sp) === true) {
      if ($mnetrequest->response == true) {
      // now store it in the mnet_enrol_assignments table
      $assignment = new StdClass;
      $assignment->userid = $userid;
      $assignment->hostid = $course->hostid;
      $assignment->courseid = $course->id;
      $assignment->enroltype = 'mnet';
      // TODO: other fields
      if (insert_record('mnet_enrol_assignments', $assignment))

      { return true; }

      }
      }

      return false;
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mjollnir Penny Leach
                Reporter:
                nicus Lorenzo Nicora
                Tester:
                Nobody
                Participants:
                Component watchers:
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  24/Nov/10