simplecategories.php
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* @package Regular Labs Library
* @version 18.2.10140
*
* @author Peter van Westen <info@regularlabs.com>
* @link http://www.regularlabs.com
* @copyright Copyright © 2018 Regular Labs All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
if ( ! is_file(JPATH_LIBRARIES . '/regularlabs/autoload.php'))
{
return;
}
require_once JPATH_LIBRARIES . '/regularlabs/autoload.php';
use RegularLabs\Library\Document as RL_Document;
class JFormFieldRL_SimpleCategories extends \RegularLabs\Library\Field
{
public $type = 'SimpleCategories';
protected function getInput()
{
JHtml::_('jquery.framework');
RL_Document::script('regularlabs/script.min.js');
RL_Document::script('regularlabs/toggler.min.js');
$this->params = $this->element->attributes();
$size = (int) $this->get('size');
$attr = $this->get('onchange') ? ' onchange="' . $this->get('onchange') . '"' : '';
$categories = $this->getOptions();
$options = parent::getOptions();
if ($this->get('show_none', 1))
{
$options[] = JHtml::_('select.option', '', '- ' . JText::_('JNONE') . ' -');
}
if ($this->get('show_new', 1))
{
$options[] = JHtml::_('select.option', '-1', '- ' . JText::_('RL_NEW_CATEGORY') . ' -');
}
$options = array_merge($options, $categories);
if ( ! $this->get('show_new', 1))
{
return JHtml::_('select.genericlist',
$options,
$this->name,
trim($attr),
'value',
'text',
$this->value,
$this->id
);
}
RL_Document::script('regularlabs/simplecategories.min.js');
$selectlist = $this->selectListSimple(
$options,
$this->getName($this->fieldname . '_select'),
$this->value,
$this->getId('', $this->fieldname . '_select'),
$size,
false
);
$html = [];
$html[] = '<div class="rl_simplecategory">';
$html[] = '<input type="hidden" class="rl_simplecategory_value" id="' . $this->id . '" name="' . $this->name . '" value="' . $this->value . '" checked="checked">';
$html[] = '<div class="rl_simplecategory_select">';
$html[] = $selectlist;
$html[] = '</div>';
$html[] = '<div id="' . rand(1000000, 9999999) . '___' . $this->fieldname . '_select.-1" class="rl_toggler rl_toggler_nofx" style="display:none;">';
$html[] = '<div class="rl_simplecategory_new">';
$html[] = '<input type="text" id="' . $this->id . '_new" value="" placeholder="' . JText::_('RL_NEW_CATEGORY_ENTER') . '">';
$html[] = '</div>';
$html[] = '</div>';
$html[] = '</div>';
return implode('', $html);
}
protected function getOptions()
{
$table = $this->get('table');
if ( ! $table)
{
return [];
}
// Get the user groups from the database.
$query = $this->db->getQuery(true)
->select([
$this->db->quoteName('category', 'value'),
$this->db->quoteName('category', 'text'),
])
->from($this->db->quoteName('#__' . $table))
->where($this->db->quoteName('category') . ' != ' . $this->db->quote(''))
->group($this->db->quoteName('category'))
->order($this->db->quoteName('category') . ' ASC');
$this->db->setQuery($query);
return $this->db->loadObjectList();
}
}