[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_scheduler/src/Field/ -> IntervalField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_scheduler
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Scheduler\Administrator\Field;
  12  
  13  use Joomla\CMS\Form\Field\NumberField;
  14  use Joomla\CMS\Form\FormField;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('_JEXEC') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Select style field for interval(s) in minutes, hours, days and months.
  22   *
  23   * @since  4.1.0
  24   */
  25  class IntervalField extends NumberField
  26  {
  27      /**
  28       * The form field type.
  29       *
  30       * @var    string
  31       * @since  4.1.0
  32       */
  33      protected $type = 'Intervals';
  34  
  35      /**
  36       * The subtypes supported by this field type => [minVal, maxVal]
  37       *
  38       * @var string[]
  39       * @since  4.1.0
  40       */
  41      private const SUBTYPES = [
  42          'minutes' => [1, 59],
  43          'hours'   => [1, 23],
  44          'days'    => [1, 30],
  45          'months'  => [1, 12],
  46      ];
  47  
  48      /**
  49       * The allowable maximum value of the field.
  50       *
  51       * @var    float
  52       * @since  4.1.0
  53       */
  54      protected $max;
  55  
  56      /**
  57       * The allowable minimum value of the field.
  58       *
  59       * @var    float
  60       * @since  4.1.0
  61       */
  62      protected $min;
  63  
  64      /**
  65       * The step by which value of the field increased or decreased.
  66       *
  67       * @var    float
  68       * @since  4.1.0
  69       */
  70      protected $step = 1;
  71  
  72      /**
  73       * Override the parent method to set deal with subtypes.
  74       *
  75       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form
  76       *                                       field object.
  77       * @param   mixed              $value    The form field value to validate.
  78       * @param   string             $group    The field name group control value. This acts as an array container for
  79       *                                       the field. For example if the field has `name="foo"` and the group value is
  80       *                                       set to "bar" then the full field name would end up being "bar[foo]".
  81       *
  82       * @return  boolean  True on success.
  83       *
  84       * @since   4.1.0
  85       */
  86      public function setup(\SimpleXMLElement $element, $value, $group = null): bool
  87      {
  88          $parentResult = FormField::setup($element, $value, $group);
  89          $subtype      = ((string) $element['subtype'] ?? '') ?: null;
  90  
  91          if (empty($subtype) || !\array_key_exists($subtype, self::SUBTYPES)) {
  92              return false;
  93          }
  94  
  95          [$this->min, $this->max] = self::SUBTYPES[$subtype];
  96  
  97          return $parentResult;
  98      }
  99  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer