AMD return description

AMD return description

by oa73neve Königstein -
Number of replies: 1

Hello guys,

I am writing a webservice for my plugin. I am able to retrieve the data I want, but unable to define the correct return description it needs. My output looks like this:

Array
(
    [users_courses] => Array
        (
            [0] => Array
                (
                    [id] => 33
                    [category] => 1
                    [sortorder] => 10004
                    [shortname] => asd
                    [fullname] => asd
                    [idnumber] => 
                    [startdate] => 1484309612
                    [visible] => 1
                    [defaultgroupingid] => 0
                    [groupmode] => 0
                    [groupmodeforce] => 0
                    [ctxid] => 687
                    [ctxpath] => /1/3/687
                    [ctxdepth] => 3
                    [ctxlevel] => 50
                    [ctxinstance] => 33
                )
            [1] => Array
                (
                    [id] => 3
                    .....
                )
            [2] => Array
                (
                    [id] => 32
                    ......
                )
        )
    [user_information] => Array
        (
            [id] => 3
            [auth] => manual
            [confirmed] => 1
            [policyagreed] => 0
            [deleted] => 0
            [suspended] => 0
            [mnethostid] => 1
            [username] => username1
            [password] => XXX
            [idnumber] => 
            [firstname] => First Name 1
            [lastname] => Surname 1
            [email] => dummy@gmx.se
            [emailstop] => 0
            .......
        )
)


I am unable to create the appropiate "get_user_information_returns"-function and am confused as to when you have to use "external_multiple_structure", "external_single_structure" and arrays.

I have tried many compositions. Most yield a "invalid response value detected"-exception. Some of them came through, but wierdly had no data attached.

Appreciate every help!

Average of ratings: -
In reply to oa73neve Königstein

Re: AMD return description

by oa73neve Königstein -

I have found the culprit where I didn't expect it: idnumber should not have the PARAM_TYPE: PARAM_INT because it does not have a value and thus is no integer. The correct return-structure (with a slightly different output structure) looks like this:

           public static function get_user_information_returns() {
             return
              new external_multiple_structure (new external_single_structure (array (
                  'user_information' => new external_single_structure ( array (
                      'id' => new external_value (PARAM_INT, 'id of the user'),
                      'username' => new external_value (PARAM_TEXT, 'username of the user'),
                      'firstname' => new external_value (PARAM_TEXT, 'firstname of the user'),
                      'lastname' => new external_value (PARAM_TEXT, 'lastname of the user'),
                      'email' => new external_value (PARAM_TEXT, 'email of the user'),
                      'timecreated' => new external_value (PARAM_INT, 'timecreated of the user'),
                      'timemodified' => new external_value (PARAM_INT, 'timemodified of the user'),
                      'lang' => new external_value (PARAM_TEXT, 'lang of the user'),
                      'auth' => new external_value (PARAM_TEXT, 'auth of the user'),
                    )),
                    'users_courses' => new external_multiple_structure (new external_single_structure (array (
                          'id' => new external_value (PARAM_INT, 'id of course'),
                          'category' => new external_value (PARAM_INT, 'category id of the course'),
                          'shortname' => new external_value (PARAM_TEXT, 'short name of the course'),
                          'fullname' => new external_value (PARAM_TEXT, 'long name of the course'),
                          'startdate' => new external_value (PARAM_INT, 'starting date of the course'),
                          'visible' => new external_value (PARAM_BOOL, 'visible of course'),
                    )))
                  )));
             }

Cheers
Average of ratings: Useful (1)