by Doug Stevens.
Hi all, I've written a PHP cron script to synchronize students and parents against our SIS. I've managed to get all of it working except assigning parents to students (done on the site via "Assign roles relative to this user". If I do this manually via our moodle site, it works perfectly, however when I run the code below there are no role assignments created nor are there any errors flagged to the console, the apache error logs, nor the PHP cli logs.
For the code below:
roleid = 9 is assigned to a system level role with a user context called "Parent". This shows up in the "Assign roles relative to this user" in the student's preferences.
Via a var_dump I can confirm that both $moodlelookup and $parentlookup below both provide the correct moodle userids which are stored in $role correctly.
In the userlogs for the API token's user the method call shows as "unknown method".
Can anyone spot my mistake?
Thanks!
Doug
----Code below----
$roles=array();
foreach($parentstudent as $thiskid)
{
$role['roleid']=9;
$role['userid']=(int)$parentidlookup[$thiskid['parent']]; //Recover Parent's moodle userid
//Both of these Confirmed by using in Moodle profile
$role['instanceid']=(int)$moodlelookup[$thiskid['student']]; //Recover Student's moodle userid
$role['contextid']=(int)30;
$role['contextlevel']="user";
array_push($roles,$role);
}
unset($resp);
try{
$params=array();
$params['assignments']=$roles;
$resp=$clientm->core_role_assign_roles($params);
}catch(Exception $e){
echo $e."\n";
}
var_dump($resp);