Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Field/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/Field/DaterangeField.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\Field;

use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\Field\ListField;

\defined('_JEXEC') or die;

class DaterangeField extends ListField
{
    protected $type = 'Daterange';
    
    protected function getOptions()
    {
        $include_never = (int) $this->element['never'];
        $duration = (string) $this->element['duration'];

        $options = parent::getOptions();

        // Field options
        $field_options = [
            'today' => 'LIB_TF_TODAY',
        ];

        $past_options = [
            'past_week' => 'LIB_TF_PAST_WEEK',
            'past_1month' => 'LIB_TF_PAST_1MONTH',
            'past_3month' => 'LIB_TF_PAST_3MONTH',
            'past_6month' => 'LIB_TF_PAST_6MONTH',
            'past_year' => 'LIB_TF_PAST_YEAR',
            'post_year' => 'LIB_TF_POST_YEAR',
        ];

        $future_options = [
            'next_week' => 'LIB_TF_NEXT_WEEK',
            'next_1month' => 'LIB_TF_NEXT_1MONTH',
            'next_3month' => 'LIB_TF_NEXT_3MONTH',
            'next_6month' => 'LIB_TF_NEXT_6MONTH',
            'next_year' => 'LIB_TF_NEXT_YEAR',
            'post_future_year' => 'LIB_TF_POST_FUTURE_YEAR',
        ];

        if ($duration == 'all')
        {
            $field_options = array_merge($field_options, $past_options, $future_options);
        }
        elseif ($duration == 'past')
        {
            $field_options = array_merge($field_options, $past_options);
        }
        elseif ($duration == 'future')
        {
            $field_options = array_merge($field_options, $future_options);
        }

        if ($include_never)
        {
            $field_options['never'] = 'LIB_TF_NEVER';
        }

        foreach ($field_options as $value => $text)
        {
            $options[] = (object) array('value' => $value, 'text' => $text);
        }

        return $options;
    }
}