public function init()
 {
     global $PAGE, $DB;
     $result = new workshop_allocation_result($this);
     $customdata = array();
     $customdata['workshop'] = $this->workshop;
     $record = $DB->get_record('workshopallocation_live', array('workshopid' => $this->workshop->id));
     if (!$record) {
         $record = new stdClass();
         $record->workshopid = $this->workshop->id;
         $record->enabled = false;
         $record->settings = '{}';
     }
     $this->mform = new workshop_live_allocator_form($PAGE->url, $customdata);
     if ($this->mform->is_cancelled()) {
         redirect($this->workshop->view_url());
     } else {
         if ($data = $this->mform->get_data()) {
             $record->enabled = !empty($data->enabled);
             $record->settings = json_encode(array('numofreviews' => $data->numofreviews, 'numper' => $data->numper, 'excludesamegroup' => !empty($data->excludesamegroup), 'addselfassessment' => !empty($data->addselfassessment)));
             if (isset($record->id)) {
                 $DB->update_record('workshopallocation_live', $record);
             } else {
                 $DB->insert_record('workshopallocation_live', $record);
             }
             if ($record->enabled) {
                 $msg = get_string('resultenabled', 'workshopallocation_live');
             } else {
                 $msg = get_string('resultdisabled', 'workshopallocation_live');
             }
             $result->set_status(workshop_allocation_result::STATUS_CONFIGURED, $msg);
         } else {
             $data = json_decode($record->settings) ?: new stdClass();
             $data->enabled = $record->enabled;
             $this->mform->set_data($data);
             $result->set_status(workshop_allocation_result::STATUS_VOID);
         }
     }
     return $result;
 }
示例#2
0
文件: lib.php 项目: evltuma/moodle
 /**
  * Allocate submissions as requested by user
  *
  * @return workshop_allocation_result
  */
 public function init()
 {
     global $PAGE;
     $mode = optional_param('mode', 'display', PARAM_ALPHA);
     $perpage = optional_param('perpage', null, PARAM_INT);
     if ($perpage and $perpage > 0 and $perpage <= 1000) {
         require_sesskey();
         set_user_preference('workshopallocation_manual_perpage', $perpage);
         redirect($PAGE->url);
     }
     $result = new workshop_allocation_result($this);
     switch ($mode) {
         case 'new':
             if (!confirm_sesskey()) {
                 throw new moodle_exception('confirmsesskeybad');
             }
             $reviewerid = required_param('by', PARAM_INT);
             $authorid = required_param('of', PARAM_INT);
             $m = array();
             // message object to be passed to the next page
             $submission = $this->workshop->get_submission_by_author($authorid);
             if (!$submission) {
                 // nothing submitted by the given user
                 $m[] = self::MSG_NOSUBMISSION;
                 $m[] = $authorid;
             } else {
                 // ok, we have the submission
                 $res = $this->workshop->add_allocation($submission, $reviewerid);
                 if ($res == workshop::ALLOCATION_EXISTS) {
                     $m[] = self::MSG_EXISTS;
                     $m[] = $submission->authorid;
                     $m[] = $reviewerid;
                 } else {
                     $m[] = self::MSG_ADDED;
                     $m[] = $submission->authorid;
                     $m[] = $reviewerid;
                 }
             }
             $m = implode('-', $m);
             // serialize message object to be passed via URL
             redirect($PAGE->url->out(false, array('m' => $m)));
             break;
         case 'del':
             if (!confirm_sesskey()) {
                 throw new moodle_exception('confirmsesskeybad');
             }
             $assessmentid = required_param('what', PARAM_INT);
             $confirmed = optional_param('confirm', 0, PARAM_INT);
             $assessment = $this->workshop->get_assessment_by_id($assessmentid);
             if ($assessment) {
                 if (!$confirmed) {
                     $m[] = self::MSG_CONFIRM_DEL;
                     $m[] = $assessment->id;
                     $m[] = $assessment->authorid;
                     $m[] = $assessment->reviewerid;
                     if (is_null($assessment->grade)) {
                         $m[] = 0;
                     } else {
                         $m[] = 1;
                     }
                 } else {
                     if ($this->workshop->delete_assessment($assessment->id)) {
                         $m[] = self::MSG_DELETED;
                         $m[] = $assessment->authorid;
                         $m[] = $assessment->reviewerid;
                     } else {
                         $m[] = self::MSG_DELETE_ERROR;
                         $m[] = $assessment->authorid;
                         $m[] = $assessment->reviewerid;
                     }
                 }
                 $m = implode('-', $m);
                 // serialize message object to be passed via URL
                 redirect($PAGE->url->out(false, array('m' => $m)));
             }
             break;
     }
     $result->set_status(workshop_allocation_result::STATUS_VOID);
     return $result;
 }
示例#3
0
    /**
     * Executes the allocation
     *
     * @return workshop_allocation_result
     */
    public function execute() {
        global $DB;

        $result = new workshop_allocation_result($this);

        // make sure the workshop itself is at the expected state

        if ($this->workshop->phase != workshop::PHASE_SUBMISSION) {
            $result->set_status(workshop_allocation_result::STATUS_FAILED,
                get_string('resultfailedphase', 'workshopallocation_scheduled'));
            return $result;
        }

        if (empty($this->workshop->submissionend)) {
            $result->set_status(workshop_allocation_result::STATUS_FAILED,
                get_string('resultfaileddeadline', 'workshopallocation_scheduled'));
            return $result;
        }

        if ($this->workshop->submissionend > time()) {
            $result->set_status(workshop_allocation_result::STATUS_VOID,
                get_string('resultvoiddeadline', 'workshopallocation_scheduled'));
            return $result;
        }

        $current = $DB->get_record('workshopallocation_scheduled',
            array('workshopid' => $this->workshop->id, 'enabled' => 1), '*', IGNORE_MISSING);

        if ($current === false) {
            $result->set_status(workshop_allocation_result::STATUS_FAILED,
                get_string('resultfailedconfig', 'workshopallocation_scheduled'));
            return $result;
        }

        if (!$current->enabled) {
            $result->set_status(workshop_allocation_result::STATUS_VOID,
                get_string('resultdisabled', 'workshopallocation_scheduled'));
            return $result;
        }

        if (!is_null($current->timeallocated) and $current->timeallocated >= $this->workshop->submissionend) {
            $result->set_status(workshop_allocation_result::STATUS_VOID,
                get_string('resultvoidexecuted', 'workshopallocation_scheduled'));
            return $result;
        }

        // so now we know that we are after the submissions deadline and either the scheduled allocation was not
        // executed yet or it was but the submissions deadline has been prolonged (and hence we should repeat the
        // allocations)

        $settings = workshop_random_allocator_setting::instance_from_text($current->settings);
        $randomallocator = $this->workshop->allocator_instance('random');
        $randomallocator->execute($settings, $result);

        // store the result in the instance's table
        $update = new stdClass();
        $update->id = $current->id;
        $update->timeallocated = $result->get_timeend();
        $update->resultstatus = $result->get_status();
        $update->resultmessage = $result->get_message();
        $update->resultlog = json_encode($result->get_logs());

        $DB->update_record('workshopallocation_scheduled', $update);

        return $result;
    }