我试图通过带有自定义字段的webservice在moodle中添加一个新用户

时间:2016-03-17 06:13:24

标签: web-services drupal-7 moodle

我正在尝试通过webservice在moodle中创建用户。用户是成功创建的,但自定义字段未填充。是否有人将我重定向到解决方案?在自定义字段中,我试图将性别的值作为男性发送。

       $functionName = 'core_user_create_users';
            $user1 = new stdClass();
            $user1->username = $form_state['values']['UserName']; 
            $user1->password=$form_state['values']['PassWord']; 
            $user1->firstname = $form_state['values']['FirstName']; 
            $user1->lastname = $form_state['values']['LastName']; 
            $user1->email = $form_state['values']['Emailid']; 
            $user1->mailformat = '0';
            $preferencename1 = 'auth_forcepasswordchange';
            $user1->preferences = array(
                array('type' => $preferencename1, 'value' => 'true')
               );
              $user1->customfields = array(
                array('type' => 'Gender', 'value' => 'Male')
               );
            $users = array($user1);
            $params = array('users' => $users);

            /// REST CALL
    $rest_format = 'json';

        //$server_url = $domain_name . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $function_name;
        $server_url = 'localhost/moodle' . '/webservice/rest/server.php'. '?wstoken=' . '7525ce057d455657a4e83d7aa63f3684' .'&wsfunction='. $functionName;
        require_once('curl.inc');
        $curl = new curl;
        $rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';

        $resp =$curl->post($server_url.$rest_format , $params);
        dpm($resp);
        $res=json_decode($resp);

        dpm($res);

2 个答案:

答案 0 :(得分:1)

$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
     array('type' => $preferencename1, 'value' => 'true')
);

有效吗? 我正在尝试但显示无效的参数错误。

答案 1 :(得分:0)

我明白了。我所做的一切都是因为性别的第一封信应该是小写的。它应该是gender而不是Gender