1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Form
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 JFormHelper::loadFieldClass('list');
13
14 /**
15 * Form Field to load a list of content authors
16 *
17 * @since 3.2
18 */
19 class JFormFieldAuthor extends JFormFieldList
20 {
21 /**
22 * The form field type.
23 *
24 * @var string
25 * @since 3.2
26 */
27 public $type = 'Author';
28
29 /**
30 * Cached array of the category items.
31 *
32 * @var array
33 * @since 3.2
34 */
35 protected static $options = array();
36
37 /**
38 * Method to get the options to populate list
39 *
40 * @return array The field option objects.
41 *
42 * @since 3.2
43 */
44 protected function getOptions()
45 {
46 // Accepted modifiers
47 $hash = md5($this->element);
48
49 if (!isset(static::$options[$hash]))
50 {
51 static::$options[$hash] = parent::getOptions();
52
53 $db = JFactory::getDbo();
54
55 // Construct the query
56 $query = $db->getQuery(true)
57 ->select('u.id AS value, u.name AS text')
58 ->from('#__users AS u')
59 ->join('INNER', '#__content AS c ON c.created_by = u.id')
60 ->group('u.id, u.name')
61 ->order('u.name');
62
63 // Setup the query
64 $db->setQuery($query);
65
66 // Return the result
67 if ($options = $db->loadObjectList())
68 {
69 static::$options[$hash] = array_merge(static::$options[$hash], $options);
70 }
71 }
72
73 return static::$options[$hash];
74 }
75 }
76