## General developer forum

### Set activity completion using PHP

Set activity completion using PHP

Hi there,

(it seems that this is the more appropriate forum to post this)

So hoping someone can help me with what shoud be fairly easy (but I'm battling to find an answer in all my searches)!

I've developed a few activities using Flash. All I want to do is set the activity to 'completed' by calling a Moodle PHP function / running a script.  (maybe even giving the student a 100% grade)

I don't want to package it as a SCORM object. (been there, done that, working, but don't want the SCORM 'interface').

Your guidance would be highly appreciated!

(using ver 2.4)

Average of ratings: -
Re: Set activity completion using PHP

Have you looked at the completetion class in /completion?

Average of ratings: -
Re: Set activity completion using PHP

Hi Ankit, I'm new to the moodle.  I'm battling to find where I can look into the Completion class.  Can you point me into the right direction?

Thx

Average of ratings: -
Re: Set activity completion using PHP

Average of ratings: -
Re: Set activity completion using PHP

Something like this would be in order

// $course is full course object$completion_info = new completion_info($course);//$cm is course module object - activity$completion =$completion_info->update_state($cm, COMPLETION_COMPLETE); Average of ratings: Useful (1) Re: Set activity completion using PHP Thank you so much for your reply. In my php script, would I have to "require" config.php to be able to access to these functions? Average of ratings: - Re: Set activity completion using PHP 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) Re: Set activity completion using PHP Thank you Darko! Average of ratings: - Re: Set activity completion using PHP hi, very util script how can i set the objetc cm from an ID? thakz Average of ratings: - 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: -