/** * 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; } } }
/** * Stores the pre-defined random allocation settings for later usage * * @param bool $enabled is the scheduled allocation enabled * @param bool $reset reset the recent execution info * @param teamwork_random_allocator_setting $settings settings form data * @param teamwork_allocation_result $result logger */ protected function store_settings($enabled, $reset, teamwork_random_allocator_setting $settings, teamwork_allocation_result $result) { global $DB; $data = new stdClass(); $data->teamworkid = $this->teamwork->id; $data->enabled = $enabled; $data->submissionend = $this->teamwork->submissionend; $data->settings = $settings->export_text(); if ($reset) { $data->timeallocated = null; $data->resultstatus = null; $data->resultmessage = null; $data->resultlog = null; } $result->log($data->settings, 'debug'); $current = $DB->get_record('teamworkallocation_scheduled', array('teamworkid' => $data->teamworkid), '*', IGNORE_MISSING); if ($current === false) { $DB->insert_record('teamworkallocation_scheduled', $data); } else { $data->id = $current->id; $DB->update_record('teamworkallocation_scheduled', $data); } }