forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultsetData.zep
More file actions
80 lines (67 loc) · 2.1 KB
/
ResultsetData.zep
File metadata and controls
80 lines (67 loc) · 2.1 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
/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Html\Helper\Input\Select;
use InvalidArgumentException;
use Phalcon\Mvc\Model\ResultsetInterface;
class ResultsetData implements SelectDataInterface
{
/**
* @var ResultsetInterface
*/
protected resultset;
/**
* @var array
*/
protected using = [];
/**
* @param ResultsetInterface resultset
* @param array using
*/
public function __construct(<ResultsetInterface> resultset, array using)
{
if unlikely count(using) !== 2 {
throw new InvalidArgumentException(
"The 'using' parameter requires exactly two values"
);
}
let this->resultset = resultset;
let this->using = using;
}
/**
* @return array
*/
public function getOptions() -> array
{
var option, optionText, optionValue, options, usingZero, usingOne;
let usingZero = this->using[0],
usingOne = this->using[1],
options = [];
for option in this->resultset {
if typeof option == "object" {
if method_exists(option, "readAttribute") {
let optionValue = option->readAttribute(usingZero),
optionText = option->readAttribute(usingOne);
} else {
let optionValue = option->{usingZero},
optionText = option->{usingOne};
}
} else {
if unlikely typeof option != "array" {
throw new InvalidArgumentException(
"Resultset returned an invalid value"
);
}
let optionValue = option[usingZero],
optionText = option[usingOne];
}
let options[optionValue] = optionText;
}
return options;
}
}