[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/classes/task/ -> adhoc_task.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   * Adhoc task abstract class.
  19   *
  20   * All background tasks should extend this class.
  21   *
  22   * @package    core
  23   * @category   task
  24   * @copyright  2013 Damyon Wiese
  25   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  namespace core\task;
  29  
  30  /**
  31   * Abstract class defining an adhoc task.
  32   * @copyright  2013 Damyon Wiese
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  abstract class adhoc_task extends task_base {
  36  
  37      /** @var string $customdata - Custom data required for when this task is executed. */
  38      private $customdata = '';
  39  
  40      /** @var integer|null $id - Adhoc tasks each have their own database record id. */
  41      private $id = null;
  42  
  43      /**
  44       * Setter for $id.
  45       * @param int|null $id
  46       */
  47      public function set_id($id) {
  48          $this->id = $id;
  49      }
  50  
  51      /**
  52       * Getter for $id.
  53       * @return int|null $id
  54       */
  55      public function get_id() {
  56          return $this->id;
  57      }
  58  
  59      /**
  60       * Setter for $customdata.
  61       * @param mixed $customdata (anything that can be handled by json_encode)
  62       */
  63      public function set_custom_data($customdata) {
  64          $this->customdata = json_encode($customdata);
  65      }
  66  
  67      /**
  68       * Alternate setter for $customdata. Expects the data as a json_encoded string.
  69       * @param string $customdata json_encoded string
  70       */
  71      public function set_custom_data_as_string($customdata) {
  72          $this->customdata = $customdata;
  73      }
  74  
  75      /**
  76       * Getter for $customdata.
  77       * @return mixed (anything that can be handled by json_decode).
  78       */
  79      public function get_custom_data() {
  80          return json_decode($this->customdata);
  81      }
  82  
  83      /**
  84       * Alternate getter for $customdata.
  85       * @return string this is the raw json encoded version.
  86       */
  87      public function get_custom_data_as_string() {
  88          return $this->customdata;
  89      }
  90  
  91  
  92  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1