Ejemplo n.º 1
0
 /**
  * Save the settings for the random allocator to execute it later
  */
 public function init()
 {
     global $PAGE, $DB;
     $result = new teamwork_allocation_result($this);
     $customdata = array();
     $customdata['teamwork'] = $this->teamwork;
     $current = $DB->get_record('teamworkallocation_scheduled', array('teamworkid' => $this->teamwork->id), '*', IGNORE_MISSING);
     $customdata['current'] = $current;
     $this->mform = new teamwork_scheduled_allocator_form($PAGE->url, $customdata);
     if ($this->mform->is_cancelled()) {
         redirect($this->teamwork->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 = teamwork_random_allocator_setting::instance_from_object($settings);
             $this->store_settings($enabled, $reset, $settings, $result);
             if ($enabled) {
                 $msg = get_string('resultenabled', 'teamworkallocation_scheduled');
             } else {
                 $msg = get_string('resultdisabled', 'teamworkallocation_scheduled');
             }
             $result->set_status(teamwork_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 = teamwork_random_allocator_setting::instance_from_text($current->settings);
                 $data->enablescheduled = $current->enabled;
                 $this->mform->set_data($data);
             }
             $result->set_status(teamwork_allocation_result::STATUS_VOID);
             return $result;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Allocate submissions as requested by user
  *
  * @return teamwork_allocation_result
  */
 public function init()
 {
     global $PAGE;
     $result = new teamwork_allocation_result($this);
     $customdata = array();
     $customdata['teamwork'] = $this->teamwork;
     $this->mform = new teamwork_random_allocator_form($PAGE->url, $customdata);
     if ($this->mform->is_cancelled()) {
         redirect($this->teamwork->view_url());
     } else {
         if ($settings = $this->mform->get_data()) {
             $settings = teamwork_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(teamwork_allocation_result::STATUS_VOID);
             return $result;
         }
     }
 }