[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/admin/tool/task/classes/ -> edit_scheduled_task_form.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Form for scheduled tasks admin pages.
  19   *
  20   * @package    tool_task
  21   * @copyright  2013 Damyon Wiese <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir.'/formslib.php');
  28  
  29  /**
  30   * Edit scheduled task form.
  31   *
  32   * @copyright  2013 Damyon Wiese <[email protected]>
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class tool_task_edit_scheduled_task_form extends moodleform {
  36      public function definition() {
  37          $mform = $this->_form;
  38          /** @var \core\task\scheduled_task $task */
  39          $task = $this->_customdata;
  40  
  41          $lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : get_string('never');
  42          $nextrun = $task->get_next_run_time();
  43          if ($task->get_disabled()) {
  44              $nextrun = get_string('disabled', 'tool_task');
  45          } else if ($nextrun > time()) {
  46              $nextrun = userdate($nextrun);
  47          } else {
  48              $nextrun = get_string('asap', 'tool_task');
  49          }
  50          $mform->addElement('static', 'lastrun', get_string('lastruntime', 'tool_task'), $lastrun);
  51          $mform->addElement('static', 'nextrun', get_string('nextruntime', 'tool_task'), $nextrun);
  52  
  53          $mform->addElement('text', 'minute', get_string('taskscheduleminute', 'tool_task'));
  54          $mform->setType('minute', PARAM_RAW);
  55          $mform->addHelpButton('minute', 'taskscheduleminute', 'tool_task');
  56  
  57          $mform->addElement('text', 'hour', get_string('taskschedulehour', 'tool_task'));
  58          $mform->setType('hour', PARAM_RAW);
  59          $mform->addHelpButton('hour', 'taskschedulehour', 'tool_task');
  60  
  61          $mform->addElement('text', 'day', get_string('taskscheduleday', 'tool_task'));
  62          $mform->setType('day', PARAM_RAW);
  63          $mform->addHelpButton('day', 'taskscheduleday', 'tool_task');
  64  
  65          $mform->addElement('text', 'month', get_string('taskschedulemonth', 'tool_task'));
  66          $mform->setType('month', PARAM_RAW);
  67          $mform->addHelpButton('month', 'taskschedulemonth', 'tool_task');
  68  
  69          $mform->addElement('text', 'dayofweek', get_string('taskscheduledayofweek', 'tool_task'));
  70          $mform->setType('dayofweek', PARAM_RAW);
  71          $mform->addHelpButton('dayofweek', 'taskscheduledayofweek', 'tool_task');
  72  
  73          $mform->addElement('advcheckbox', 'disabled', get_string('disabled', 'tool_task'));
  74          $mform->addHelpButton('disabled', 'disabled', 'tool_task');
  75  
  76          $mform->addElement('advcheckbox', 'resettodefaults', get_string('resettasktodefaults', 'tool_task'));
  77          $mform->addHelpButton('resettodefaults', 'resettasktodefaults', 'tool_task');
  78  
  79          $mform->disabledIf('minute', 'resettodefaults', 'checked');
  80          $mform->disabledIf('hour', 'resettodefaults', 'checked');
  81          $mform->disabledIf('day', 'resettodefaults', 'checked');
  82          $mform->disabledIf('dayofweek', 'resettodefaults', 'checked');
  83          $mform->disabledIf('month', 'resettodefaults', 'checked');
  84          $mform->disabledIf('disabled', 'resettodefaults', 'checked');
  85  
  86          $mform->addElement('hidden', 'task', get_class($task));
  87          $mform->setType('task', PARAM_RAW);
  88          $mform->addElement('hidden', 'action', 'edit');
  89          $mform->setType('action', PARAM_ALPHANUMEXT);
  90          $this->add_action_buttons(true, get_string('savechanges'));
  91  
  92          // Do not use defaults for existing values, the set_data() is the correct way.
  93          $this->set_data(\core\task\manager::record_from_scheduled_task($task));
  94      }
  95  }
  96  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1