1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 if (!class_exists('JFormFieldSql'))
12 {
13 require_once JPATH_LIBRARIES . '/joomla/form/fields/sql.php';
14 }
15
16 17 18 19 20 21 22
23 class extends FOFFormHeaderFieldselectable
24 {
25 26 27 28 29
30 protected function getOptions()
31 {
32 $options = array();
33
34
35 $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
36 $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
37 $applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
38 $modelName = (string) $this->element['model'];
39 $nonePlaceholder = (string) $this->element['none'];
40 $translate = empty($this->element['translate']) ? 'true' : (string) $this->element['translate'];
41 $translate = in_array(strtolower($translate), array('true','yes','1','on')) ? true : false;
42
43 if (!empty($nonePlaceholder))
44 {
45 $options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
46 }
47
48
49 $applyAccess = strtolower($applyAccess);
50 $applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
51
52
53 $parts = FOFInflector::explode($modelName);
54 $mName = ucfirst(array_pop($parts));
55 $mPrefix = FOFInflector::implode($parts);
56
57
58 $config = array('savestate' => 0);
59 $model = FOFModel::getTmpInstance($mName, $mPrefix, $config);
60
61 if ($applyAccess)
62 {
63 $model->applyAccessFiltering();
64 }
65
66
67 foreach ($this->element->children() as $stateoption)
68 {
69
70 if ($stateoption->getName() != 'state')
71 {
72 continue;
73 }
74
75 $stateKey = (string) $stateoption['key'];
76 $stateValue = (string) $stateoption;
77
78 $model->setState($stateKey, $stateValue);
79 }
80
81
82 $items = $model->getItemList(true);
83
84
85 if (!empty($items))
86 {
87 foreach ($items as $item)
88 {
89 if ($translate == true)
90 {
91 $options[] = JHtml::_('select.option', $item->$key, JText::_($item->$value));
92 }
93 else
94 {
95 $options[] = JHtml::_('select.option', $item->$key, $item->$value);
96 }
97 }
98 }
99
100
101 $options = array_merge(parent::getOptions(), $options);
102
103 return $options;
104 }
105 }
106