rest - Moodle api list all cohorts -


im looking cohorts, can info if have id want cohorts names , ids. please let me know if theres way this. in advance

$functionname = 'core_cohort_get_cohorts'; $cohortids = array( '1' ); $data_string = http_build_query(array('cohortids' => $cohortids));  $utoken = 'mytoken';  $adduser = 'yoururl/webservice/rest/server.php?               wstoken='.$utoken.'&wsfunction='.$functionname.'&moodlewsrestformat=json'; $ch = curl_init();  curl_setopt($ch, curlopt_url,$adduser); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data_string); curl_setopt($ch, curlopt_returntransfer, true); $server_output = curl_exec ($ch);  curl_close ($ch);  echo '<pre>';  print_r(json_decode($server_output)); echo '</pre>'; 

you add more method core_cohort cohort following: in cohort/externallib.php, add more method:

public static function get_all_cohorts(){     global $db;     $cohortids = $db->get_records('cohort', null, null, 'id');     $arrids = array();     foreach($cohortids $id){         $arrids[] = $id->id;     }     return (new core_cohort_external())->get_cohorts($arrids); } 

in addition, have register webservice called 'core_cohort_get_all_cohorts' call webservice outside. please tell me if have further question.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -