示例#1
0
    /**
     * Save the settings for the random allocator to execute it later
     */
    public function init() {
        global $PAGE, $DB;

        $result = new workshop_allocation_result($this);

        $customdata = array();
        $customdata['workshop'] = $this->workshop;

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

        $customdata['current'] = $current;

        $this->mform = new workshop_scheduled_allocator_form($PAGE->url, $customdata);

        if ($this->mform->is_cancelled()) {
            redirect($this->workshop->view_url());
        } else if ($settings = $this->mform->get_data()) {
            if (empty($settings->enablescheduled)) {
                $enabled = false;
            } else {
                $enabled = true;
            }
            if (empty($settings->reenablescheduled)) {
                $reset = false;
            } else {
                $reset = true;
            }
            $settings = workshop_random_allocator_setting::instance_from_object($settings);
            $this->store_settings($enabled, $reset, $settings, $result);
            if ($enabled) {
                $msg = get_string('resultenabled', 'workshopallocation_scheduled');
            } else {
                $msg = get_string('resultdisabled', 'workshopallocation_scheduled');
            }
            $result->set_status(workshop_allocation_result::STATUS_CONFIGURED, $msg);
            return $result;
        } else {
            // this branch is executed if the form is submitted but the data
            // doesn't validate and the form should be redisplayed
            // or on the first display of the form.

            if ($current !== false) {
                $data = workshop_random_allocator_setting::instance_from_text($current->settings);
                $data->enablescheduled = $current->enabled;
                $this->mform->set_data($data);
            }

            $result->set_status(workshop_allocation_result::STATUS_VOID);
            return $result;
        }
    }
示例#2
0
文件: lib.php 项目: JP-Git/moodle
    /**
     * Allocate submissions as requested by user
     *
     * @return workshop_allocation_result
     */
    public function init() {
        global $PAGE;

        $result = new workshop_allocation_result($this);
        $customdata = array();
        $customdata['workshop'] = $this->workshop;
        $this->mform = new $this->form_class($PAGE->url, $customdata);
        if ($this->mform->is_cancelled()) {
            redirect($this->workshop->view_url());
        } else if ($settings = $this->mform->get_data()) {
            $settings = workshop_random_allocator_setting::instance_from_object($settings);
            $this->execute($settings, $result);
            return $result;
        } else {
            // this branch is executed if the form is submitted but the data
            // doesn't validate and the form should be redisplayed
            // or on the first display of the form.
            $result->set_status(workshop_allocation_result::STATUS_VOID);
            return $result;
        }
    }