CoreFiles by mySites.guru
LogcreatorField.php76 lines, 2,027 bytes, from Joomla_4.2.1-rc2-Release_Candidate-Full_Package.zip
Raw History Compare with 4.2.1-rc1
md5
109959d4cbc101ebd2a5f6ad4442ec59
sha1
4f21cc05b660daa30514b185b61b6ac5cd465cd1
sha256
a648c8d8229d0f88ee905aa9f4962fe0b63fb9143dbf68b459bfcea0f9d3e789
<?php

/**
 * @package     Joomla.Administrator
 * @subpackage  com_actionlogs
 *
 * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Actionlogs\Administrator\Field;

use Joomla\CMS\Form\Field\ListField;

/**
 * Field to load a list of all users that have logged actions
 *
 * @since  3.9.0
 */
class LogcreatorField extends ListField
{
    /**
     * Cached array of the category items.
     *
     * @var    array
     * @since  3.9.0
     */
    protected static $options = [];

    /**
     * The form field type.
     *
     * @var    string
     * @since  3.9.0
     */
    protected $type = 'LogCreator';

    /**
     * Method to get the options to populate list
     *
     * @return  array  The field option objects.
     *
     * @since   3.9.0
     */
    protected function getOptions()
    {
        // Accepted modifiers
        $hash = md5($this->element);

        if (!isset(static::$options[$hash])) {
            static::$options[$hash] = parent::getOptions();

            $db = $this->getDatabase();

            // Construct the query
            $query = $db->getQuery(true)
                ->select($db->quoteName('u.id', 'value'))
                ->select($db->quoteName('u.username', 'text'))
                ->from($db->quoteName('#__users', 'u'))
                ->join('INNER', $db->quoteName('#__action_logs', 'c') . ' ON ' . $db->quoteName('c.user_id') . ' = ' . $db->quoteName('u.id'))
                ->group($db->quoteName('u.id'))
                ->group($db->quoteName('u.username'))
                ->order($db->quoteName('u.username'));

            // Setup the query
            $db->setQuery($query);

            // Return the result
            if ($options = $db->loadObjectList()) {
                static::$options[$hash] = array_merge(static::$options[$hash], $options);
            }
        }

        return static::$options[$hash];
    }
}

The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.