Skip to content

Commit

Permalink
Merge branch 'master' into ndunand#168-Fix-lost-groups-to-choose-whil…
Browse files Browse the repository at this point in the history
…e-restore
  • Loading branch information
NicoAlexH committed Jan 30, 2023
2 parents 213a2ef + af1d053 commit 275f5ec
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 28 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/moodle-plugin-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Moodle Plugin CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:10
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10.5
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
php: ['7.3', '7.4', '8.0']
moodle-branch: ['MOODLE_400_STABLE']
database: [pgsql, mariadb]

steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker || true

- name: Moodle PHPDoc Checker
if: ${{ always() }}
run: moodle-plugin-ci phpdoc || true

- name: Validating
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints || true

- name: Mustache Lint
if: ${{ always() }}
run: moodle-plugin-ci mustache || true

- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt

- name: PHPUnit tests
if: ${{ always() }}
run: moodle-plugin-ci phpunit

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
General information
====================

[![Moodle Plugin CI](https://github.com/ndunand/moodle-mod_choicegroup/workflows/Moodle%20Plugin%20CI/badge.svg?branch=master)](https://github.com/ndunand/moodle-mod_choicegroup/actions?query=workflow%3A%22Moodle+Plugin+CI%22+branch%3Amaster)

This module allows students to enrol themselves in a group within a course. The teacher can choose from which groups the students can chose, and the maximum nummber of students allowed in each group.

The students can view the members of each group before making a choise, and (if the teacher allows it) change their selected group until the deadline.
Expand Down
4 changes: 3 additions & 1 deletion amd/build/choicegroupdatadisplay.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/choicegroupdatadisplay.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion amd/build/select_all_choices.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions amd/build/select_all_choices.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
use core_completion\activity_custom_completion;

/**
* Activity custom completion subclass for the choice activity.
* Activity custom completion subclass for the choicegroup activity.
*
* Class for defining mod_choice's custom completion rules and fetching the completion statuses
* of the custom completion rules for a given choice instance and a user.
* Class for defining mod_choicegroup's custom completion rules and fetching the completion statuses
* of the custom completion rules for a given choicegroup instance and a user.
*
* @package mod_choice
* @package mod_choicegroup
* @copyright 2021 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
5 changes: 4 additions & 1 deletion lang/en/choicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$string['allowupdate'] = 'Allow choice to be updated';
$string['answered'] = 'Answered';
$string['completionsubmit'] = 'Show as complete when user makes a choice';
$string['completiondetail:submit'] = 'Choose a group';
$string['defaultsettings'] = 'Default settings';
$string['displayhorizontal'] = 'Display horizontally';
$string['displaymode'] = 'Display mode';
Expand Down Expand Up @@ -128,7 +129,7 @@
<li><a href="{$a->linkgroups}">manage course groups</a></li>
<li><a href="{$a->linkcourse}">get back to the course</a></li>
</ul>';
$string['pleaseselectonegroup'] = 'Please select at least one group to chose from.';
$string['pleaseselectonegroup'] = 'Please select at least one group to choose from.';

$string['multipleenrollmentspossible'] = 'Allow enrollment to multiple groups';
$string['and'] = 'and';
Expand Down Expand Up @@ -165,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
128 changes: 127 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
define('CHOICEGROUP_SORTGROUPS_CREATEDATE', '1');
define('CHOICEGROUP_SORTGROUPS_NAME', '2');

// Ugly hack to make 3.11 and 4.0 work seamlessly.
if (!defined('FEATURE_MOD_PURPOSE')) {
define('FEATURE_MOD_PURPOSE', 'mod_purpose');
}
if (!defined('MOD_PURPOSE_COLLABORATION')) {
define('MOD_PURPOSE_COLLABORATION', 'collaboration');
}

/** @global array $CHOICEGROUP_PUBLISH */
global $CHOICEGROUP_PUBLISH;
$CHOICEGROUP_PUBLISH = array (CHOICEGROUP_PUBLISH_ANONYMOUS => get_string('publishanonymous', 'choicegroup'),
Expand Down Expand Up @@ -356,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 @@ -373,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 Expand Up @@ -990,6 +1023,7 @@ function choicegroup_supports($feature) {
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;
case FEATURE_MOD_PURPOSE: return MOD_PURPOSE_COLLABORATION;

default: return null;
}
Expand Down Expand Up @@ -1116,3 +1150,95 @@ function mod_choicegroup_core_calendar_provide_event_action(calendar_event $even
);
}

/**
* Mark the activity completed (if required) and trigger the course_module_viewed event.
*
* @param stdClass $choicegroup choicegroup object
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @since Moodle 3.0
*/
function choicegroup_view($choicegroup, $course, $cm, $context) {

// TODO: Trigger course_module_viewed event.
$params = array(
'context' => $context,
'objectid' => $choicegroup->id
);

// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
}

/**
* Add a get_coursemodule_info function in case any choicegroup type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function choicegroup_get_coursemodule_info($coursemodule) {
global $DB;

$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, name, intro, introformat, completionsubmit, timeopen, timeclose';
if (!$choicegroup = $DB->get_record('choicegroup', $dbparams, $fields)) {
return false;
}

$result = new cached_cm_info();
$result->name = $choicegroup->name;

if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('choicegroup', $choicegroup, $coursemodule->id, false);
}

// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$result->customdata['customcompletionrules']['completionsubmit'] = $choicegroup->completionsubmit;
}
// Populate some other values that can be used in calendar or on dashboard.
if ($choicegroup->timeopen) {
$result->customdata['timeopen'] = $choicegroup->timeopen;
}
if ($choicegroup->timeclose) {
$result->customdata['timeclose'] = $choicegroup->timeclose;
}

return $result;
}

/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules']
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_choicegroup_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (empty($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}

$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (!empty($val)) {
$descriptions[] = get_string('completionsubmit', 'choicegroup');
}
break;
default:
break;
}
}
return $descriptions;
}

0 comments on commit 275f5ec

Please sign in to comment.