fieldselectable.php
3.27 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
<?php
/**
* @package FrameworkOnFramework
* @subpackage form
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
/**
* Generic field header, with drop down filters
*
* @package FrameworkOnFramework
* @since 2.0
*/
class FOFFormHeaderFieldselectable extends FOFFormHeaderField
{
/**
* Create objects for the options
*
* @return array The array of option objects
*/
protected function getOptions()
{
$options = array();
// Get the field $options
foreach ($this->element->children() as $option)
{
// Only add <option /> elements.
if ($option->getName() != 'option')
{
continue;
}
// Create a new option object based on the <option /> element.
$options[] = JHtml::_(
'select.option',
(string) $option['value'],
JText::alt(
trim((string) $option),
preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)
),
'value', 'text', ((string) $option['disabled'] == 'true')
);
}
// Do we have a class and method source for our options?
$source_file = empty($this->element['source_file']) ? '' : (string) $this->element['source_file'];
$source_class = empty($this->element['source_class']) ? '' : (string) $this->element['source_class'];
$source_method = empty($this->element['source_method']) ? '' : (string) $this->element['source_method'];
$source_key = empty($this->element['source_key']) ? '*' : (string) $this->element['source_key'];
$source_value = empty($this->element['source_value']) ? '*' : (string) $this->element['source_value'];
$source_translate = empty($this->element['source_translate']) ? 'true' : (string) $this->element['source_translate'];
$source_translate = in_array(strtolower($source_translate), array('true','yes','1','on')) ? true : false;
$source_format = empty($this->element['source_format']) ? '' : (string) $this->element['source_format'];
if ($source_class && $source_method)
{
// Maybe we have to load a file?
if (!empty($source_file))
{
$source_file = FOFTemplateUtils::parsePath($source_file, true);
if (FOFPlatform::getInstance()->getIntegrationObject('filesystem')->fileExists($source_file))
{
include_once $source_file;
}
}
// Make sure the class exists
if (class_exists($source_class, true))
{
// ...and so does the option
if (in_array($source_method, get_class_methods($source_class)))
{
// Get the data from the class
if ($source_format == 'optionsobject')
{
$options = array_merge($options, $source_class::$source_method());
}
else
{
$source_data = $source_class::$source_method();
// Loop through the data and prime the $options array
foreach ($source_data as $k => $v)
{
$key = (empty($source_key) || ($source_key == '*')) ? $k : $v[$source_key];
$value = (empty($source_value) || ($source_value == '*')) ? $v : $v[$source_value];
if ($source_translate)
{
$value = JText::_($value);
}
$options[] = JHtml::_('select.option', $key, $value, 'value', 'text');
}
}
}
}
}
reset($options);
return $options;
}
}