How to update course Progress value in external application automatically?

How to update course Progress value in external application automatically?

by D.Joseph Francis Kumar -
Number of replies: 0

I am trying to update course progress value for angular application. Angular having separate API to store course progress value from moodle. Back end side i can get course progress value through from some curl method from moodle. But front end side course progress is updating when the moodle page should refresh.

Do we have any solution to update course progress apj in external application without refresh or login required?

Am using below code to send automatic course progress value to external application.


use core_completion\progress;

global $COURSE;

$course = $COURSE;

$completion = new \completion_info($course);

$coursecontext = context_course::instance($course->id);

$percentage = progress::get_course_progress_percentage($course);

//print_r($percentage);

$data = array("moodleCourseId" => $course->id, "courseShortName" => $course->shortname, "userMoodleId" => $USER->id, "progress" => $percentage, "externalCourse" => false);

//$data = array("moodleCourseId" => $course->id, "userMoodleId" => $USER->id, "progress" => $percentage, "externalCourse" => false);

//print_r($data);$

data_string = json_encode($data);                                        ch = curl_init('https://abc.com/controller/course-progress');                                           

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      curl_setopt($ch, CURLOPT_HTTPHEADER, array(              'Content-Type: application/json',                                          'Content-Length: ' . strlen($data_string))                               );$result = curl_exec($ch);


Average of ratings: -