1 <?php
2 3 4 5 6 7 8
9
10 defined('_JEXEC') or die;
11
12 JFormHelper::loadFieldClass('usergroup');
13
14 15 16 17 18 19 20
21 class FOFFormFieldUsergroup extends JFormFieldUsergroup implements FOFFormField
22 {
23 protected $static;
24
25 protected $repeatable;
26
27
28 public $rowid;
29
30
31 public $item;
32
33 34 35 36 37 38 39 40 41
42 public function __get($name)
43 {
44 switch ($name)
45 {
46 case 'static':
47 if (empty($this->static))
48 {
49 $this->static = $this->getStatic();
50 }
51
52 return $this->static;
53 break;
54
55 case 'repeatable':
56 if (empty($this->repeatable))
57 {
58 $this->repeatable = $this->getRepeatable();
59 }
60
61 return $this->repeatable;
62 break;
63
64 default:
65 return parent::__get($name);
66 }
67 }
68
69 70 71 72 73 74 75 76
77 public function getStatic()
78 {
79 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
80
81 $params = $this->getOptions();
82
83 $db = FOFPlatform::getInstance()->getDbo();
84 $query = $db->getQuery(true);
85
86 $query->select('a.id AS value, a.title AS text');
87 $query->from('#__usergroups AS a');
88 $query->group('a.id, a.title');
89 $query->order('a.id ASC');
90 $query->order($query->qn('title') . ' ASC');
91
92
93 $db->setQuery($query);
94 $options = $db->loadObjectList();
95
96
97 if (is_array($params))
98 {
99 $options = array_merge($params, $options);
100 }
101
102
103 elseif ($params)
104 {
105 array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
106 }
107
108 return '<span id="' . $this->id . '" ' . $class . '>' .
109 htmlspecialchars(FOFFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
110 '</span>';
111 }
112
113 114 115 116 117 118 119 120
121 public function getRepeatable()
122 {
123 $class = $this->element['class'] ? (string) $this->element['class'] : '';
124
125 $db = FOFPlatform::getInstance()->getDbo();
126 $query = $db->getQuery(true);
127
128 $query->select('a.id AS value, a.title AS text');
129 $query->from('#__usergroups AS a');
130 $query->group('a.id, a.title');
131 $query->order('a.id ASC');
132 $query->order($query->qn('title') . ' ASC');
133
134
135 $db->setQuery($query);
136 $options = $db->loadObjectList();
137
138
139 return '<span class="' . $this->id . ' ' . $class . '">' .
140 htmlspecialchars(FOFFormFieldList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') .
141 '</span>';
142 }
143 }
144