by Mike Wilson.
For any-one who's stuck at the same point as I was here's the working version. You can map a multidimensional array from the main function to the returns function. The structure in the return is a single structure with a multi structure which contains another single structure.
Hope this saves someone else a headache.
foreach($feedbacks as $feedback){
$feedbackId = $feedback->id;
$academicyear = academicyear($feedback->timecreated);
$rawcomment = strip_tags($feedback->commenttext);
$marker = $feedback->firstname.' '.$feedback->lastname;
$feedbackdate = date('d.m.Y',$feedback->timemodified);
$unitname = $feedback->fullname;
$assignmentname = $feedback->name;
$feeds[$feedbackId] = array(
'feedbackId' => $feedbackId,
'academicyear' => $academicyear,
'unitname' => $unitname,
'assignmentname' => $assignmentname,
'feedbackcomment' => $rawcomment,
'markername' => $marker,
'feedbackdate' => $feedbackdate
);
}
$portal = array(
'source' => 'Moodle',
'username' => $user->username,
'firstname' => $user->firstname,
'lastname' => $user->lastname,
'email' => $user->email,
'feedback' => $feeds
);
return $portal;
}
public static function personal_tutor_portal_returns() {
return new external_single_structure(
array(
'source' => new external_value(PARAM_TEXT, 'where data came from - moodle'),
'username' => new external_value(PARAM_TEXT, 'username of student'),
'firstname' => new external_value(PARAM_TEXT, 'first name of student'),
'lastname' => new external_value(PARAM_TEXT, 'last name of student'),
'email' => new external_value(PARAM_TEXT, 'email of student'),
'feedback' => new external_multiple_structure(
new external_single_structure(
array(
'feedbackId' => new external_value(PARAM_INT,'assign_grade id'),
'academicyear' => new external_value(PARAM_TEXT, 'academic year of feedback comment', VALUE_OPTIONAL),
'unitname' => new external_value(PARAM_TEXT, 'unit of study for feedback comment', VALUE_OPTIONAL),
'assignmentname' => new external_value(PARAM_TEXT, 'assignment name for feedback comment', VALUE_OPTIONAL),
'feedbackcomment' => new external_value(PARAM_TEXT, 'feedback comment with html tags stripped out', VALUE_OPTIONAL),
'markername' => new external_value(PARAM_TEXT, 'name of lecturer who marked assignment', VALUE_OPTIONAL),
'feedbackdate' => new external_value(PARAM_TEXT, 'date assignment was last marked', VALUE_OPTIONAL)
)
)
)
)
);
}