Completion issue in new module

Completion issue in new module

by Mark Rademaker -
Number of replies: 0

I am currently creating an own activity module in Moodle, and I'm stuck on this part.

This is the first time I create code in Moodle, so I'm new to everything, I have basic PHP knowlegde.

So I first created my own module via the template at https://github.com/moodlehq/moodle-mod_newmodule , I changed everything to my own name created a database for it etc, and everything works fine. Now I'm trying the following:

In the module I have a button, and when a student clicks that button, I would like to set the course as completed for that student. I followed the documentation on the Moodle website but I'm stuck at this part.

In the file mod_form.php I've added the following code, copied from mod_form.php in the feedbackfolder because it adds the field that I need when adding this activity:

public function add_completion_rules() {
     $mform =& $this->_form;

     $mform->addElement('checkbox',
                        'completionsubmit',
                        '',
                        get_string('completionsubmit', 'feedback'));
     // Enable this completion rule by default.
     $mform->setDefault('completionsubmit', 1);
     return array('completionsubmit');
 }

 public function completion_rule_enabled($data) {
     return !empty($data['completionsubmit']);
 }

This adds the option "View as completed if the feedback is submitted", that's exactly what I need.

But now I'm kind of stuck, I don't know what code to execute when I "submit the feedback" to set the course as completed. It's just a click on a button, but I don't know what part of code sets a course as completed. I tried searching it up everywhere, but I can't seem to find it. I even tried to look up the function in the whole existing feedback folder but it goes so deep, that I don't know where to look..

Keep in mind that I'm just getting started with this, so any help/tips are appreciated!

Thanks in advance, Mark


Average of ratings: -