|
1
|
|
|
<?php namespace XoopsModules\Smartobject\Form\Elements; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Contains the SmartObjectControl class |
|
5
|
|
|
* |
|
6
|
|
|
* @license GNU |
|
7
|
|
|
* @author marcan <[email protected]> |
|
8
|
|
|
* @link http://smartfactory.ca The SmartFactory |
|
9
|
|
|
* @package SmartObject |
|
10
|
|
|
* @subpackage SmartObjectForm |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
use XoopsModules\Smartobject; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class SmartFormSelectElement |
|
17
|
|
|
* @package XoopsModules\Smartobject\Form\Elements |
|
18
|
|
|
*/ |
|
19
|
|
|
class SmartFormSelectElement extends \XoopsFormSelect |
|
20
|
|
|
{ |
|
21
|
|
|
public $multiple = false; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* SmartFormSelectElement constructor. |
|
25
|
|
|
* @param string $object |
|
26
|
|
|
* @param string $key |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct($object, $key) |
|
29
|
|
|
{ |
|
30
|
|
|
$var = $object->vars[$key]; |
|
31
|
|
|
$size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
|
32
|
|
|
|
|
33
|
|
|
// Adding the options inside this SelectBox |
|
34
|
|
|
// If the custom method is not from a module, than it's from the core |
|
35
|
|
|
$control = $object->getControl($key); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$value = isset($control['value']) ? $control['value'] : $object->getVar($key, 'e'); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
parent::__construct($var['form_caption'], $key, $value, $size, $this->multiple); |
|
40
|
|
|
|
|
41
|
|
View Code Duplication |
if (isset($control['options'])) { |
|
|
|
|
|
|
42
|
|
|
$this->addOptionArray($control['options']); |
|
43
|
|
|
} else { |
|
44
|
|
|
// let's find if the method we need to call comes from an already defined object |
|
45
|
|
|
if (isset($control['object'])) { |
|
46
|
|
|
if (method_exists($control['object'], $control['method'])) { |
|
47
|
|
|
if ($option_array = $control['object']->{$control['method']}()) { |
|
48
|
|
|
// Adding the options array to the XoopsFormSelect |
|
49
|
|
|
$this->addOptionArray($option_array); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} else { |
|
53
|
|
|
// finding the itemHandler; if none, let's take the itemHandler of the $object |
|
54
|
|
|
if (isset($control['itemHandler'])) { |
|
55
|
|
|
if (!$control['module']) { |
|
56
|
|
|
// Creating the specified core object handler |
|
57
|
|
|
$controlHandler = xoops_getHandler($control['itemHandler']); |
|
58
|
|
|
} else { |
|
59
|
|
|
$controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
|
60
|
|
|
} |
|
61
|
|
|
} else { |
|
62
|
|
|
$controlHandler = $object->handler; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Checking if the specified method exists |
|
66
|
|
|
if (method_exists($controlHandler, $control['method'])) { |
|
67
|
|
|
// TODO: How could I pass the parameters in the following call ... |
|
68
|
|
|
if ($option_array = $controlHandler->{$control['method']}()) { |
|
69
|
|
|
// Adding the options array to the XoopsFormSelect |
|
70
|
|
|
$this->addOptionArray($option_array); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.