/**
  * Save the settings for the random allocator to execute it later
  */
 public function init()
 {
     global $PAGE, $DB;
     $result = new workshopplus_allocation_result($this);
     $customdata = array();
     $customdata['workshopplus'] = $this->workshopplus;
     $current = $DB->get_record('workshopplusallocation_scheduled', array('workshopplusid' => $this->workshopplus->id), '*', IGNORE_MISSING);
     $customdata['current'] = $current;
     $this->mform = new workshopplus_scheduled_allocator_form($PAGE->url, $customdata);
     if ($this->mform->is_cancelled()) {
         redirect($this->workshopplus->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 = workshopplus_random_allocator_setting::instance_from_object($settings);
             $this->store_settings($enabled, $reset, $settings, $result);
             if ($enabled) {
                 $msg = get_string('resultenabled', 'workshopplusallocation_scheduled');
             } else {
                 $msg = get_string('resultdisabled', 'workshopplusallocation_scheduled');
             }
             $result->set_status(workshopplus_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 = workshopplus_random_allocator_setting::instance_from_text($current->settings);
                 $data->enablescheduled = $current->enabled;
                 $this->mform->set_data($data);
             }
             $result->set_status(workshopplus_allocation_result::STATUS_VOID);
             return $result;
         }
     }
 }
 /**
  * Allocate submissions as requested by user
  *
  * @return workshopplus_allocation_result
  */
 public function init()
 {
     global $PAGE;
     $result = new workshopplus_allocation_result($this);
     $customdata = array();
     $customdata['workshopplus'] = $this->workshopplus;
     $this->mform = new workshopplus_random_allocator_form($PAGE->url, $customdata);
     if ($this->mform->is_cancelled()) {
         redirect($this->workshopplus->view_url());
     } else {
         if ($settings = $this->mform->get_data()) {
             $settings = workshopplus_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(workshopplus_allocation_result::STATUS_VOID);
             return $result;
         }
     }
 }