Skip to content

Commit

Permalink
Merge pull request #181 from ndunand/dev
Browse files Browse the repository at this point in the history
Fix for issue #175
  • Loading branch information
ndunand authored Jan 3, 2023
2 parents 0fd383b + a63b966 commit cd9760c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lang/en/choicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
$string['activitydate:willopen'] = 'Opens:';
$string['activitydate:hasopened'] = 'Opened:';
$string['activitydate:willclose'] = 'Closes:';
$string['activitydate:exceeded'] = 'Due date exceeded.';
$string['activitydate:notavailableyet'] = 'Not available yet.';
$string['mustchoosemax'] = 'You must choose a maximum of {$a} groups. Nothing was saved.';
$string['maxenrollments'] = 'Max. enrollments';
$string['maxenrollments_help'] = 'This option allows to limit the number of group enrollments for a participant. Use default value **0** if there is no limit.';
Expand Down
27 changes: 26 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,35 @@ function choicegroup_prepare_options($choicegroup, $user, $coursemodule, $allres
}

/**
* @global object
* @throws \moodle_exception
*/
function check_restrictions($choicegroup, $userid) {
check_date_restrictions($choicegroup);
//TODO check other restrictions
}


/**
* @throws \moodle_exception
*/
function check_date_restrictions($choicegroup) {
if($choicegroup->timeopen !== '0' && time() < $choicegroup->timeopen) {
throw new moodle_exception(get_string('activitydate:notavailableyet', 'mod_choicegroup'));
}

if($choicegroup->timeclose !== '0' && time() > $choicegroup->timeclose) {
throw new moodle_exception(get_string('activitydate:exceeded', 'mod_choicegroup'));
}
}

/**
* @param int $formanswer
* @param object $choicegroup
* @param int $userid
* @param object $course Course object
* @param object $cm
* @throws \moodle_exception
* @global object
*/
function choicegroup_user_submit_response($formanswer, $choicegroup, $userid, $course, $cm) {
global $DB, $CFG;
Expand All @@ -381,6 +404,8 @@ function choicegroup_user_submit_response($formanswer, $choicegroup, $userid, $c
'objectid' => $choicegroup->id
);

check_restrictions($choicegroup, $userid);

$selected_option = $DB->get_record('choicegroup_options', array('id' => $formanswer));

$current = choicegroup_get_user_answer($choicegroup, $userid);
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022092202;
$plugin->version = 2022092203;
$plugin->requires = 2020061500; // Moodle 3.9
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.38 for Moodle 3.9-4.0 (Build: 2022092202)';
Expand Down

0 comments on commit cd9760c

Please sign in to comment.