Your IP : 216.73.216.240


Current Path : /home/juvelize/martine/administrator/components/com_easybookreloaded/models/fields/
Upload File :
Current File : /home/juvelize/martine/administrator/components/com_easybookreloaded/models/fields/acl.php

<?php

/**
 * @copyright
 * @package    Easybook Reloaded - EBR for Joomla! 3.x
 * @author     Viktor Vogel <admin@kubik-rubik.de>
 * @version    3.4.1.1-FREE - 2021-08-29
 * @link       https://kubik-rubik.de/ebr-easybook-reloaded
 *
 * @license    GNU/GPL
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') || die('Restricted access');

use Joomla\CMS\{Form\FormHelper, Factory, Access\Access};

jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
FormHelper::loadFieldClass('list');

/**
 * Class JFormFieldACL
 *
 * @since   3.4.0-FREE
 * @version 3.4.1.0-FREE
 */
class JFormFieldACL extends JFormFieldList
{
    /**
     * @var string $type
     * @since 3.4.0-FREE
     */
    protected $type = 'ACL';

    /**
     * @return array
     * @since   3.4.0-FREE
     * @version 3.4.1.0-FREE
     */
    protected function getOptions(): array
    {
        $db = Factory::getDbo();
        $user = Factory::getUser();
        $query = $db->getQuery(true);

        $query->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level');
        $query->from('#__usergroups AS a');
        $query->join('LEFT', '`#__usergroups` AS b ON a.lft > b.lft AND a.rgt < b.rgt');

        if ($id = $this->form->getValue('id')) {
            $query->join('LEFT', '`#__usergroups` AS p ON p.id = ' . (int)$id);
            $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
        }

        $query->group('a.id');
        $query->order('a.lft ASC');

        $db->setQuery($query);
        $options = $db->loadObjectList();

        $n = count($options);

        for ($i = 0; $i < $n; $i++) {
            if ($user->authorise('core.admin') || (!Access::checkGroup($options[$i]->value, 'core.admin'))) {
                $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
            } else {
                unset($options[$i]);
            }
        }

        return array_merge(parent::getOptions(), $options);
    }
}