General developer forum

 
 
Picture of Darko Miletić
Re: Set activity completion using PHP
Group DevelopersGroup Particularly helpful Moodlers

Yes for using any Moodle API config.php is a must. Than add any additional libraries you intend to use.

In this case you would need these:

require_once(<relative path to config.php>);
require_once($CFG->libdir.'/completionlib.php');
// $course is full couurse object
$completion_info = new completion_info($course);
// $cm is course module object
$completion = $completion_info->update_state($cm, COMPLETION_COMPLETE));
 
Average of ratings:Useful (2)
Picture of Anton van der Merwe
Re: Set activity completion using PHP
 

Thank you Darko!

 
Average of ratings: -
Picture of Gonzalo Santos
Re: Set activity completion using PHP
 

hi, very util script

how can i set the objetc cm from an ID?

thakz

 
Average of ratings: -
Picture of Gonzalo Santos
Re: Set activity completion using PHP
 

this code not work for me, any i forget to include?

 

// Registrar actividad como completada en Moodle
// obtengo coursemodule por ID
$cm = get_coursemodule_from_id('quiz', 13);

// completo curso por ID

$courseid = $cm->course;
$course_object = $DB->get_record('course', array('id'=>$courseid));
//
$completion_info = new completion_info($course_object);
//print_r($completion_info);
$completion = $completion_info->update_state($cm, COMPLETION_COMPLETE);
echo $completion;

 
Average of ratings: -