Moodle

Manually assigning a role in a course does not record timestart and timeend values for courses with enrollment durations

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.8.1
  • Fix Version/s: 2.0
  • Component/s: Roles / Access
  • Labels:
    None
  • Environment:
    PHP 4.4.6 and MySQL 5.0.27 running on Linux/Apache
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_18_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

To reproduce:
1. Enter a course that has an enrollment duration specified in its settings.
2. Click "Assign Roles" in the Administration panel.
3. Click "Student" under Roles.
4. Select a student in the "potential users" pane on the right and click the left-arrow button to assign that user as a student in the course.
5. Check (using something like phpMyAdmin) the new entry in mdl_role_assignments. Its "timestart" and "timeend" values will each be "0".

A quick and dirty fix:
In the file admin/roles/assign.php, add the following two lines of code around line 142 (in 1.8.1):
$timestart = time();
$timeend = time() + $course->enrolperiod;
I am not a Moodle developer and am not familiar with the intricacies and dependencies of the code in this file, so this should be used with caution. Hopefully a real Moodle developer can check into it.

A final observation:
At the top of admin/roles/assign.php is a series of parameter checks. This includes $timestart and $timeend, although apparently these do not actually do anything (since timestart and timeend have to be defined manually, as in the code above, to have any values). Having said that, there is a typo in line 19:
$timeend = optional_param('timened', 0, PARAM_INT);
Should be:
$timeend = optional_param('timeend', 0, PARAM_INT);

Issue Links

Activity

Hide
Yu Zhang added a comment -

Hi Rob,

Thanks for that, we are actually aware of this issue. It has been addressed in MDL-10181, as part of the User Management Improvements Google Summer of Code project. In this improvement you can also specify the enrollment period during manual enrollment. The issue is that there are so much stuff changed in 1.9 that I do not think it is possible to backport them to 1.8.

Cheers,

Yu

Show
Yu Zhang added a comment - Hi Rob, Thanks for that, we are actually aware of this issue. It has been addressed in MDL-10181, as part of the User Management Improvements Google Summer of Code project. In this improvement you can also specify the enrollment period during manual enrollment. The issue is that there are so much stuff changed in 1.9 that I do not think it is possible to backport them to 1.8. Cheers, Yu
Hide
mh added a comment -

I too have noticed that and used a similar fix. One thing you might want to add is a check for the role id, unless you want teachers to have an enrolment durations.

Here is what I have - I added checks to be sure there needs to be an end date and that it didn't get set already:

if($roleid > 4)
{
if($timestart == 0 && $course->enrolperiod >= 0)

{ $timestart = time(); }

if($timeend == 0 && $course->enrolperiod >= 0)

{ $timeend = $timestart + $course->enrolperiod; }

}

M=

Show
mh added a comment - I too have noticed that and used a similar fix. One thing you might want to add is a check for the role id, unless you want teachers to have an enrolment durations. Here is what I have - I added checks to be sure there needs to be an end date and that it didn't get set already: if($roleid > 4) { if($timestart == 0 && $course->enrolperiod >= 0) { $timestart = time(); } if($timeend == 0 && $course->enrolperiod >= 0) { $timeend = $timestart + $course->enrolperiod; } } M=
Hide
Sergio Gómez added a comment - - edited

I've the same problem that Robes describes, but I detected that the issue also affect if you use external users and enroles database.

To fix this issue, I've replaced the next line (144) in /enrol/database/enrol.php:

role_assign($role->id, $user->id, 0, $context->id, 0, 0, 0, 'database');

For this one:

role_assign($role->id, $user->id, 0, $context->id, time(), $timeend = time()+$course->enrolperiod, 0, 'database');

By the way, I'm working with Moodle 1.8.2+ (2007021520).

Show
Sergio Gómez added a comment - - edited I've the same problem that Robes describes, but I detected that the issue also affect if you use external users and enroles database. To fix this issue, I've replaced the next line (144) in /enrol/database/enrol.php: role_assign($role->id, $user->id, 0, $context->id, 0, 0, 0, 'database'); For this one: role_assign($role->id, $user->id, 0, $context->id, time(), $timeend = time()+$course->enrolperiod, 0, 'database'); By the way, I'm working with Moodle 1.8.2+ (2007021520).
Hide
Petr Škoda (skodak) added a comment -

fixing of enrolemnt duration will require bigger chanes, sorry
we are discussing possible solution for 2.0 now

Show
Petr Škoda (skodak) added a comment - fixing of enrolemnt duration will require bigger chanes, sorry we are discussing possible solution for 2.0 now
Hide
Petr Škoda (skodak) added a comment -

Hello,
the durations were completely removed from role_assignmetns table, enrolment plugins are now responsible for role assignments and unassignments. This should be a lot more flexible.

Thank you for the report.

Petr Skoda

Show
Petr Škoda (skodak) added a comment - Hello, the durations were completely removed from role_assignmetns table, enrolment plugins are now responsible for role assignments and unassignments. This should be a lot more flexible. Thank you for the report. Petr Skoda

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: