Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2362

Enroll users in a course. Help!

$
0
0
by anne anne.  

Hi!! I want to enroll users in a moodle course with de API. I use this function, but not working sad I use other function to create users, it has the same format and it is working perfectly. Please, I need help. Thank!!!

Error: string(636) " enrol_manual_enrol_usersroleid5userid36courseid3" string(43) "Moodle error: Unknown error Fault code: 404"


  function enrollUser($user_id, $course_id) {
       
 $params = array(array(array('roleid'=>'5', 'userid'=>$user_id, 'courseid'=>$course_id)));
       $request = xmlrpc_encode_request('enrol_manual_enrol_users', $params, array('encoding'=>'UTF-8'));
       $context = stream_context_create(array('http' => array(
      'method' => "POST",
      'header' => "Content-Type: text/xml",
      'content' => $request
    )));

    $path = $this->server.$this->dir."/webservice/xmlrpc/server.php?wstoken=".$this->token;
    $file = file_get_contents($path, false, $context);
    $response = xmlrpc_decode($file);
     
    if ($response && xmlrpc_is_fault($response)) {
      $this->error = "Moodle error: " . $response[faultString]." Fault code: " . $response[faultCode];
      return false;
    }

    return true;
  }


Viewing all articles
Browse latest Browse all 2362

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>