original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Executes the allocation
  
  @return workshop_allocation_result
docstring_tokens: Executes the allocation