<commit_before><?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Allocates the submissions randomly
 *
 * @package   mod-workshop
 * @copyright 2009 <NAME> <<EMAIL>>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

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

global $CFG;    // access to global variables during unit test

require_once(dirname(dirname(__FILE__)) . '/lib.php');                  // interface definition
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php');    // workshop internal API
require_once(dirname(__FILE__) . '/settings_form.php');                 // settings form

/**
 * Constants used to pass status messages between init() and ui()
 */
define('WORKSHOP_ALLOCATION_RANDOM_MSG_SUCCESS',    1);

/**
 * Constants used in allocation settings form
 */
define('WORKSHOP_USERTYPE_AUTHOR',                  1);
define('WORKSHOP_USERTYPE_REVIEWER',                2);

/**
 * Allocates the submissions randomly
 */
class workshop_random_allocator implements workshop_allocator {

    /** workshop instance */
    protected $workshop;

    /** mform with settings */
    protected $mform;

    /**
     * @param workshop $workshop Workshop API object
     */
    public function __construct(workshop $workshop) {
        $this->workshop = $workshop;
    }

    /**
     * Allocate submissions as requested by user
     */
    public function init() {
        global $PAGE;

        $customdata = array();
        $customdata['workshop'] = $this->workshop;
        $this->mform = new workshop_random_allocator_form($PAGE->url, $customdata);
        if ($this->mform->is_cancelled()) {
            redirect($PAGE->url->out(false, array(), false));
        } else if ($settings = $this->mform->get_data()) {
            // process validated data
            if (!confirm_sesskey()) {
                throw new moodle_exception('confirmsesskeybad');
            }
            $o                  = array();      // list of output messages
            $numofreviews       = required_param('numofreviews', PARAM_INT);
            $numper             = required_param('numper', PARAM_INT);
            $removecurrent      = required_param('removecurrent', PARAM_INT);
            $assesswosubmission = required_param('assesswosubmission', PARAM_INT);
            $musthavesubmission = empty($assesswosubmission);
            $addselfassessment  = required_param('addselfassessment', PARAM_INT);

            $authors            = $this->workshop->get_peer_authors();
            $authors            = $this->workshop->get_grouped($authors);
            $reviewers          = $this->workshop->get_peer_reviewers($musthavesubmission);
            $reviewers          = $this->workshop->get_grouped($reviewers);
            $assessments        = $this->workshop->get_assessments();

            $newallocations     = array();      // array of (reviewer,reviewee) tuples

            if ($numofreviews) {
                if ($removecurrent) {
                    // behave as if there were no current assessments
                    $curassessments = array();
                } else {
                    $curassessments = $assessments;
                }
                $randomallocations  = $this->random_allocation($authors, $reviewers, $curassessments, $numofreviews, $numper, $o);
                $this->filter_current_assessments($randomallocations, $assessments);<commit_msg>Puttting a TODO note - return to this code once working on the Scheduled allocation<commit_after><?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Allocates the submissions randomly
 *
 * @package   mod-workshop
 * @copyright 2009 <NAME> <<EMAIL>>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

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

global $CFG;    // access to global variables during unit test

require_once(dirname(dirname(__FILE__)) . '/lib.php');                  // interface definition
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php');    // workshop internal API
require_once(dirname(__FILE__) . '/settings_form.php');                 // settings form

/**
 * Constants used to pass status messages between init() and ui()
 */
define('WORKSHOP_ALLOCATION_RANDOM_MSG_SUCCESS',    1);

/**
 * Constants used in allocation settings form
 */
define('WORKSHOP_USERTYPE_AUTHOR',                  1);
define('WORKSHOP_USERTYPE_REVIEWER',                2);

/**
 * Allocates the submissions randomly
 */
class workshop_random_allocator implements workshop_allocator {

    /** workshop instance */
    protected $workshop;

    /** mform with settings */
    protected $mform;

    /**
     * @param workshop $workshop Workshop API object
     */
    public function __construct(workshop $workshop) {
        $this->workshop = $workshop;
    }

    /**
     * Allocate submissions as requested by user
     */
    public function init() {
        global $PAGE;

        $customdata = array();
        $customdata['workshop'] = $this->workshop;
        $this->mform = new workshop_random_allocator_form($PAGE->url, $customdata);
        if ($this->mform->is_cancelled()) {
            redirect($PAGE->url->out(false, array(), false));
        } else if ($settings = $this->mform->get_data()) {
            // process validated data
            if (!confirm_sesskey()) {
                throw new moodle_exception('confirmsesskeybad');
            }
            $o                  = array();      // list of output messages
            $numofreviews       = required_param('numofreviews', PARAM_INT);
            $numper             = required_param('numper', PARAM_INT);
            $removecurrent      = required_param('removecurrent', PARAM_INT);
            $assesswosubmission = required_param('assesswosubmission', PARAM_INT);
            $musthavesubmission = empty($assesswosubmission);
            $addselfassessment  = required_param('addselfassessment', PARAM_INT);

            $authors            = $this->workshop->get_peer_authors();
            $authors            = $this->workshop->get_grouped($authors);
            $reviewers          = $this->workshop->get_peer_reviewers($musthavesubmission);
            $reviewers          = $this->workshop->get_grouped($reviewers);
            $assessments        = $this->workshop->get_assessments();

            $newallocations     = array();      // array of array(reviewer => reviewee)

            if ($numofreviews) {
                // TODO MDL-19870 rewrite this part to make it easier to maintain and extend.
                // $removecurrent -> remove it at the beginning and stop doing the magic with unkept allocation
                // (leading to possible bugs)
                if ($removecurrent) {
                    // behave as if there were no current assessments
                    $curassessments = array();
                } else {
                    $curassessments = $assessments;
                }
                $randomallocations  = $this->random_allocation($authors, $reviewers, $curassessments, $numofreviews, $numper, $o);
                $this->filter_current_assessments($randomallocations, $assessments);
{'fraction_non_alphanumeric': 0.11368197379294062, 'fraction_numerical': 0.002715145791524023, 'mean_word_length': 2.39015606242497, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4616860', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2250, 'n_words': 637}