- Posts: 7902
Student not enrolled in Moodle: Hikashop order confirmed
- Antonio Durán
-
- Offline
- Moderator
-
Less
More
12 years 11 months ago #11
by Antonio Durán
Replied by Antonio Durán on topic Student not enrolled in Moodle: Hikashop order confirmed
Hi all.
- Subscription systems, like AEC or Payplans. Joomdle already integrates with them, so this can be controlled there.
Users are enroled on subscription, and enrolment is suspended when plans expires.
In this case, enrol period is controlled in Joomla side only (setting enrolmet time to unlimited in Moodle)
As this is a real integration, there is no way a user can access anything is not allowed to, going to moodle or any other way.
Now, with the case here: Ric is right, this is not working. I don't know if the problem is similar to Paypal's linked one, as I have not read that.
In our case, the problem is with Joomdle, as it does not modify the enrolment period with new purchases (this is what needs to be done, not adding another row to the table)
I have modified it to do it , and it seems to be working fine.
I also have modified the timestart to use current one with hours minutes and seconds, instead of 12:00.
If you want to test the change, replace enrol_user function in moodle/auth/joomdle/auth.php by:
Please let us know how it goes if you try it.
Thanks for the feedback!
- Subscription systems, like AEC or Payplans. Joomdle already integrates with them, so this can be controlled there.
Users are enroled on subscription, and enrolment is suspended when plans expires.
In this case, enrol period is controlled in Joomla side only (setting enrolmet time to unlimited in Moodle)
As this is a real integration, there is no way a user can access anything is not allowed to, going to moodle or any other way.
Now, with the case here: Ric is right, this is not working. I don't know if the problem is similar to Paypal's linked one, as I have not read that.
In our case, the problem is with Joomdle, as it does not modify the enrolment period with new purchases (this is what needs to be done, not adding another row to the table)
I have modified it to do it , and it seems to be working fine.
I also have modified the timestart to use current one with hours minutes and seconds, instead of 12:00.
If you want to test the change, replace enrol_user function in moodle/auth/joomdle/auth.php by:
Code:
function enrol_user ($username, $course_id, $roleid = 5)
{
global $CFG, $DB, $PAGE;
$username = utf8_decode ($username);
$username = strtolower ($username);
/* Create the user before if it is not created yet */
$conditions = array ('username' => $username);
$user = $DB->get_record('user',$conditions);
if (!$user)
$this->create_joomdle_user ($username);
$user = $DB->get_record('user',$conditions);
$conditions = array ('id' => $course_id);
$course = $DB->get_record('course', $conditions);
if (!$course)
return 0;
// Get enrol start and end dates of manual enrolment plugin
if ($CFG->version >= 2011061700)
$manager = new course_enrolment_manager($PAGE, $course);
else
$manager = new course_enrolment_manager($course);
$instances = $manager->get_enrolment_instances();
$plugins = $manager->get_enrolment_plugins();
$enrolid = 1; //manual
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), date ('H', $today), date ('i', $today), date ('s', $today));
$timestart = $today;
$timeend = 0;
$found = false;
foreach ($instances as $instance)
{
if ($instance->enrol == 'manual')
{
$found = true;
break;
}
}
if (!$found)
return 0;
$plugin = $plugins['manual'];
if ( $instance->enrolperiod)
$timeend = $timestart + $instance->enrolperiod;
// First, check if user is already enroled but suspended, so we just need to enable it
$conditions = array ('courseid' => $course_id, 'enrol' => 'manual');
$enrol = $DB->get_record('enrol', $conditions);
if (!$enrol)
return 0;
$conditions = array ('username' => $username);
$user = $DB->get_record('user', $conditions);
if (!$user)
return 0;
$conditions = array ('enrolid' => $enrol->id, 'userid' => $user->id);
$ue = $DB->get_record('user_enrolments', $conditions);
if ($ue)
{
// User already enroled
// Can be suspended, or maybe enrol time passed
// Just activate enrolment and set new dates
$ue->status = 0; //active
$ue->timestart = $timestart;
$ue->timeend = $timeend;
$DB->update_record('user_enrolments', $ue);
return 1;
}
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend);
return 1;
}
Please let us know how it goes if you try it.
Thanks for the feedback!
Please Log in or Create an account to join the conversation.
- Ric Morte`
- Topic Author
- Offline
- New Member
-
Less
More
- Posts: 11
12 years 11 months ago - 12 years 11 months ago #12
by Ric Morte`
Replied by Ric Morte` on topic Student not enrolled in Moodle: Hikashop order confirmed
Hello Antonio,
Thank you very much for your reply. I inserted the new code for the enrol_user function and I am happy to report that it worked straight away.
First, the old enrolment row for the user (_user_enrolments) is not deleted and a new row created; instead the existing row is updated with the new start and end dates. The functionality is therefore exactly as you describe.
Note however that "timemodified" is not updated to represent the last transaction - it remains unchanged. Updating this field might be useful for auditing purposes?
I really appreciate the extra mile you've taken to update the timestamps for enrolment period. Joomdle PayPal plugin does this (but not re-enrolment) - though I still want to test that in v2.5. (Over the last 24 hrs I've taken the opportunity to rebuild the development server and discard the dozens of test sites and databases: testing Moodle 2.5 will be something I shall do later today. If anthing affects this issue I'll report it here; otherwise for any other Joomdle issues I'll create a separate thread).
Thanks again and grateful for the very fast response!
Regards,
Ric
Thank you very much for your reply. I inserted the new code for the enrol_user function and I am happy to report that it worked straight away.
First, the old enrolment row for the user (_user_enrolments) is not deleted and a new row created; instead the existing row is updated with the new start and end dates. The functionality is therefore exactly as you describe.
Note however that "timemodified" is not updated to represent the last transaction - it remains unchanged. Updating this field might be useful for auditing purposes?
I really appreciate the extra mile you've taken to update the timestamps for enrolment period. Joomdle PayPal plugin does this (but not re-enrolment) - though I still want to test that in v2.5. (Over the last 24 hrs I've taken the opportunity to rebuild the development server and discard the dozens of test sites and databases: testing Moodle 2.5 will be something I shall do later today. If anthing affects this issue I'll report it here; otherwise for any other Joomdle issues I'll create a separate thread).
Thanks again and grateful for the very fast response!
Regards,
Ric
Last edit: 12 years 11 months ago by Ric Morte`.
Please Log in or Create an account to join the conversation.
- Antonio Durán
-
- Offline
- Moderator
-
Less
More
- Posts: 7902
12 years 11 months ago #13
by Antonio Durán
Replied by Antonio Durán on topic Student not enrolled in Moodle: Hikashop order confirmed
Thank you for reporting back, and also for the tip about timemodified: I have added a new line to change it when enrolment is updated:
Code:
$ue->timemodified = $timestart;
Please Log in or Create an account to join the conversation.