Closed catasoft closed 9 years ago
Sorry, I see I posted in wp2moodle--wordpress, should have been inside wp2moodle--moodle
what moodle version are you using this on, and what are the important config settings you have? This hasn't been a problem since I created the plugin back in moodle 2.3
I have Moodle 2.8.5+ (Build: 20150424) Version 2014111005.1. All I know is: users were not added to any group, but after I enrolled them first, everything works as expected.
On Mon, Apr 27, 2015 at 1:58 AM, TIm St.Clair notifications@github.com wrote:
what moodle version are you using this on, and what are the important config settings you have? This hasn't been a problem since I created the plugin back in moodle 2.3
— Reply to this email directly or view it on GitHub https://github.com/frumbert/wp2moodle--wordpress-/issues/10#issuecomment-96449880 .
This change looks good (after minor edits). I've accepted the change and checked it into the master branch on the https://github.com/frumbert/wp2moodle-moodle plugin. Thanks for the pick-up.
Hello, apparently startign Moodle 2.0, you must separately enroll the user before you're able to add to group/cohort. Here's more info: https://moodle.org/mod/forum/discuss.php?d=188794
I made it work by adding, inside wp2moodlemoodle/login.php, this function: /* By default, enrolls everyone as student / function enrol_into_course($courseid, $userid, $roleid = 5) { global $DB; $manualenrol = enrol_get_plugin('manual'); // get the enrolment plugin $enrolinstance = $DB->get_record('enrol', array('courseid'=>$courseid, 'status'=>ENROL_INSTANCEENABLED, 'enrol'=>'manual' ), '', MUST_EXIST); // retrieve enrolment instance associated with your course //echo 'inside enrol_into_course';exit; return $manualenrol->enrol_user($enrolinstance, $userid, $roleid); // enrol the user }
and calling if before adding to group:
$grouprow = $DB->get_record('groups', array('idnumber'=>$group)); //NEW LINE enrol_into_course($grouprow->courseid, $user->id); if (!$DB->record_exists('groups_members', array('groupid'=>$grouprow->id, 'userid'=>$user->id))) { // internally triggers groups_member_added event groups_add_member($grouprow->id, $user->id); // not a component ,'enrol_wp2moodle'); }
Thanks for your great work!