Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Scheduled allocator's settings
  20   *
  21   * @package     workshopallocation_scheduled
  22   * @subpackage  mod_workshop
  23   * @copyright   2012 David Mudrak <david@moodle.com>
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->dirroot.'/lib/formslib.php');
  30  require_once (__DIR__ . '/../random/settings_form.php'); // parent form
  31  
  32  /**
  33   * Allocator settings form
  34   *
  35   * This is used by {@see workshop_scheduled_allocator::ui()} to set up allocation parameters.
  36   */
  37  class workshop_scheduled_allocator_form extends workshop_random_allocator_form {
  38  
  39      /**
  40       * Definition of the setting form elements
  41       */
  42      public function definition() {
  43          global $OUTPUT;
  44  
  45          $mform = $this->_form;
  46          $workshop = $this->_customdata['workshop'];
  47          $current = $this->_customdata['current'];
  48  
  49          if (!empty($workshop->submissionend)) {
  50              $strtimeexpected = workshop::timestamp_formats($workshop->submissionend);
  51          }
  52  
  53          if (!empty($current->timeallocated)) {
  54              $strtimeexecuted = workshop::timestamp_formats($current->timeallocated);
  55          }
  56  
  57          $mform->addElement('header', 'scheduledallocationsettings', get_string('scheduledallocationsettings', 'workshopallocation_scheduled'));
  58          $mform->addHelpButton('scheduledallocationsettings', 'scheduledallocationsettings', 'workshopallocation_scheduled');
  59  
  60          $mform->addElement('checkbox', 'enablescheduled', get_string('enablescheduled', 'workshopallocation_scheduled'), get_string('enablescheduledinfo', 'workshopallocation_scheduled'), 1);
  61  
  62          $mform->addElement('header', 'scheduledallocationinfo', get_string('currentstatus', 'workshopallocation_scheduled'));
  63  
  64          if ($current === false) {
  65              $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
  66                  get_string('resultdisabled', 'workshopallocation_scheduled').' '. $OUTPUT->pix_icon('i/invalid', ''));
  67  
  68          } else {
  69              if (!empty($current->timeallocated)) {
  70                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
  71                      get_string('currentstatusexecution1', 'workshopallocation_scheduled', $strtimeexecuted).' '.
  72                      $OUTPUT->pix_icon('i/valid', ''));
  73  
  74                  if ($current->resultstatus == workshop_allocation_result::STATUS_EXECUTED) {
  75                      $strstatus = get_string('resultexecuted', 'workshopallocation_scheduled').' '.
  76                          $OUTPUT->pix_icon('i/valid', '');
  77  
  78                  } else if ($current->resultstatus == workshop_allocation_result::STATUS_FAILED) {
  79                      $strstatus = get_string('resultfailed', 'workshopallocation_scheduled').' '.
  80                          $OUTPUT->pix_icon('i/invalid', '');
  81  
  82                  } else {
  83                      $strstatus = get_string('resultvoid', 'workshopallocation_scheduled').' '.
  84                          $OUTPUT->pix_icon('i/invalid', '');
  85  
  86                  }
  87  
  88                  if (!empty($current->resultmessage)) {
  89                      $strstatus .= html_writer::empty_tag('br').$current->resultmessage; // yes, this is ugly. better solution suggestions are welcome.
  90                  }
  91                  $mform->addElement('static', 'inforesult', get_string('currentstatusresult', 'workshopallocation_scheduled'), $strstatus);
  92  
  93                  if ($current->timeallocated < $workshop->submissionend) {
  94                      $mform->addElement('static', 'infoexpected', get_string('currentstatusnext', 'workshopallocation_scheduled'),
  95                          get_string('currentstatusexecution2', 'workshopallocation_scheduled', $strtimeexpected).' '.
  96                          $OUTPUT->pix_icon('i/caution', ''));
  97                      $mform->addHelpButton('infoexpected', 'currentstatusnext', 'workshopallocation_scheduled');
  98                  } else {
  99                      $mform->addElement('checkbox', 'reenablescheduled', get_string('currentstatusreset', 'workshopallocation_scheduled'),
 100                         get_string('currentstatusresetinfo', 'workshopallocation_scheduled'));
 101                      $mform->addHelpButton('reenablescheduled', 'currentstatusreset', 'workshopallocation_scheduled');
 102                  }
 103  
 104              } else if (empty($current->enabled)) {
 105                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
 106                      get_string('resultdisabled', 'workshopallocation_scheduled').' '.
 107                          $OUTPUT->pix_icon('i/invalid', ''));
 108  
 109              } else if ($workshop->phase != workshop::PHASE_SUBMISSION) {
 110                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
 111                      get_string('resultfailed', 'workshopallocation_scheduled').' '.
 112                      $OUTPUT->pix_icon('i/invalid', '') .
 113                      html_writer::empty_tag('br').
 114                      get_string('resultfailedphase', 'workshopallocation_scheduled'));
 115  
 116              } else if (empty($workshop->submissionend)) {
 117                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
 118                      get_string('resultfailed', 'workshopallocation_scheduled').' '.
 119                      $OUTPUT->pix_icon('i/invalid', '') .
 120                      html_writer::empty_tag('br').
 121                      get_string('resultfaileddeadline', 'workshopallocation_scheduled'));
 122  
 123              } else if ($workshop->submissionend < time()) {
 124                  // next cron will execute it
 125                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
 126                      get_string('currentstatusexecution4', 'workshopallocation_scheduled').' '.
 127                      $OUTPUT->pix_icon('i/caution', ''));
 128  
 129              } else {
 130                  $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'workshopallocation_scheduled'),
 131                      get_string('currentstatusexecution3', 'workshopallocation_scheduled', $strtimeexpected).' '.
 132                      $OUTPUT->pix_icon('i/caution', ''));
 133              }
 134          }
 135  
 136          parent::definition();
 137  
 138          $mform->addHelpButton('randomallocationsettings', 'randomallocationsettings', 'workshopallocation_scheduled');
 139      }
 140  }