From 241e58e44b1e23bbf153c9cf4df5a082a888ea47 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 14 Jan 2011 14:16:10 +0100 Subject: [PATCH] MDL-25982 Workshop: users from the same group may be excluded from allocation in visible group mode If the Workshop is in the visible group mode, members of the same group can be now optionally excluded from random allocation for a given user. --- .../lang/en/workshopallocation_random.php | 1 + mod/workshop/allocation/random/lib.php | 31 ++++++++++++++++--- .../allocation/random/settings_form.php | 8 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/mod/workshop/allocation/random/lang/en/workshopallocation_random.php b/mod/workshop/allocation/random/lang/en/workshopallocation_random.php index 59913529c60..6a541defdcc 100644 --- a/mod/workshop/allocation/random/lang/en/workshopallocation_random.php +++ b/mod/workshop/allocation/random/lang/en/workshopallocation_random.php @@ -32,6 +32,7 @@ $string['allocationsettings'] = 'Allocation settings'; $string['assessmentdeleteddetail'] = 'Assessment deallocated: {$a->reviewername} is no longer reviewer of {$a->authorname}'; $string['assesswosubmission'] = 'Participants can assess without having submitted anything'; $string['confignumofreviews'] = 'Default number of submissions to be randomly allocated'; +$string['excludesamegroup'] = 'Prevent reviews by peers from the same group'; $string['noallocationtoadd'] = 'No allocations to add'; $string['nogroupusers'] = '

Warning: If the workshop is in \'visible groups\' mode or \'separate groups\' mode, then users MUST be part of at least one group to have peer-assessments allocated to them by this tool. Non-grouped users can still be given new self-assessments or have existing assessments removed.

These users are currently not in a group: {$a}

'; diff --git a/mod/workshop/allocation/random/lib.php b/mod/workshop/allocation/random/lib.php index 761d120c08e..13a41859063 100644 --- a/mod/workshop/allocation/random/lib.php +++ b/mod/workshop/allocation/random/lib.php @@ -76,6 +76,7 @@ class workshop_random_allocator implements workshop_allocator { $o = array(); // list of output messages $numofreviews = required_param('numofreviews', PARAM_INT); $numper = required_param('numper', PARAM_INT); + $excludesamegroup = optional_param('excludesamegroup', false, PARAM_BOOL); $removecurrent = optional_param('removecurrent', false, PARAM_BOOL); $assesswosubmission = optional_param('assesswosubmission', false, PARAM_BOOL); $addselfassessment = optional_param('addselfassessment', false, PARAM_BOOL); @@ -96,7 +97,11 @@ class workshop_random_allocator implements workshop_allocator { } else { $curassessments = $assessments; } - $randomallocations = $this->random_allocation($authors, $reviewers, $curassessments, $numofreviews, $numper, $o); + $options = array(); + $options['numofreviews'] = $numofreviews; + $options['numper'] = $numper; + $options['excludesamegroup'] = $excludesamegroup; + $randomallocations = $this->random_allocation($authors, $reviewers, $curassessments, $o, $options); $newallocations = array_merge($newallocations, $randomallocations); $o[] = 'ok::' . get_string('numofrandomlyallocatedsubmissions', 'workshopallocation_random', count($randomallocations)); unset($randomallocations); @@ -398,19 +403,27 @@ class workshop_random_allocator implements workshop_allocator { * is to connect each "circle" (circles are representing either authors or reviewers) with a required * number of "squares" (the other type than circles are). * + * The passed $options array must provide keys: + * (int)numofreviews - number of reviews to be allocated to each circle + * (int)numper - what user type the circles represent. + * (bool)excludesamegroup - whether to prevent peer submissions from the same group in visible group mode + * * @param array $authors structure of grouped authors * @param resource $reviewers structure of grouped reviewers * @param array $assessments currently assigned assessments to be kept - * @param mixed $numofreviews number of reviews to be allocated to each circle - * @param mixed $numper what user type the circles represent * @param array $o reference to an array of log messages + * @param array $options allocation options * @return array array of (reviewerid => authorid) pairs */ - protected function random_allocation($authors, $reviewers, $assessments, $numofreviews, $numper, &$o) { + protected function random_allocation($authors, $reviewers, $assessments, &$o, array $options) { if (empty($authors) || empty($reviewers)) { // nothing to be done return array(); } + + $numofreviews = $options['numofreviews']; + $numper = $options['numper']; + if (self::USERTYPE_AUTHOR == $numper) { // circles are authors, squares are reviewers $o[] = 'info::Trying to allocate ' . $numofreviews . ' review(s) per author'; // todo translate @@ -514,6 +527,16 @@ class workshop_random_allocator implements workshop_allocator { } elseif (VISIBLEGROUPS == $gmode) { $trygroups = array_diff_key($squaregroupsworkload, array(0 => null)); // all but [0] $trygroups = array_diff_key($trygroups, array_flip($failedgroups)); // without previous failures + if ($options['excludesamegroup']) { + // exclude groups the circle is member of + $excludegroups = array(); + foreach (array_diff_key($allcircles, array(0 => null)) as $exgroupid => $exgroupmembers) { + if (array_key_exists($circleid, $exgroupmembers)) { + $excludegroups[$exgroupid] = null; + } + } + $trygroups = array_diff_key($trygroups, $excludegroups); + } $targetgroup = $this->get_element_with_lowest_workload($trygroups); } if ($targetgroup === false) { diff --git a/mod/workshop/allocation/random/settings_form.php b/mod/workshop/allocation/random/settings_form.php index 4b30f5b3e24..3762e418089 100644 --- a/mod/workshop/allocation/random/settings_form.php +++ b/mod/workshop/allocation/random/settings_form.php @@ -74,6 +74,14 @@ class workshop_random_allocator_form extends moodleform { $mform->setDefault('numper', workshop_random_allocator::USERTYPE_AUTHOR); $mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshopallocation_random'), array(' '), false); + + if (VISIBLEGROUPS == $gmode) { + $mform->addElement('checkbox', 'excludesamegroup', get_string('excludesamegroup', 'workshopallocation_random')); + $mform->setDefault('excludesamegroup', 0); + } else { + $mform->addElement('hidden', 'excludesamegroup', 0); + } + $mform->addElement('checkbox', 'removecurrent', get_string('removecurrentallocations', 'workshopallocation_random')); $mform->setDefault('removecurrent', 0);