SubmissionsFields.php
2.68 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
110
111
112
113
114
115
<?php
class NF_Adapters_SubmissionsFields implements ArrayAccess, Iterator
{
protected $fields;
protected $fields_by_key = [];
public function __construct($fields = [], $form_id)
{
foreach ($fields as $field) {
if (is_array($field)) {
if (!isset($field['key'])) {
continue;
}
$key = $field['key'];
} else {
if (!method_exists($field, 'get_setting')) {
continue;
}
$key = $field->get_setting('key');
}
$this->fields_by_key[$key] = $field;
}
$fields_sorted = apply_filters('ninja_forms_get_fields_sorted', array(), $this->fields, $this->fields_by_key, $form_id);
if (!empty($fields_sorted)) {
$this->fields = $fields_sorted;
} else {
$this->fields = $fields;
}
}
public function get_value($id)
{
return $this->fields[$id]['value'];
}
/*
|--------------------------------------------------------------------------
| ArrayAccess
|--------------------------------------------------------------------------
*/
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->fields[] = $value;
} else {
$this->fields[$offset] = $value;
}
}
public function offsetExists($offset)
{
if (isset($this->fields[$offset])) {
return true;
}
if (isset($this->fields_by_key[$offset])) {
return true;
}
return false;
}
public function offsetUnset($offset)
{
unset($this->fields[ $offset ]);
}
public function offsetGet($offset)
{
if (isset($this->fields[$offset])) {
return $this->fields[$offset];
}
if (isset($this->fields_by_key[$offset])) {
return $this->fields_by_key[$offset];
}
return array(
'type' => '',
'label' => '',
'admin_label' => '',
'value' => ''
);
}
/*
|--------------------------------------------------------------------------
| Iterator
|--------------------------------------------------------------------------
*/
public function key()
{
return key($this->fields);
}
public function current()
{
return current($this->fields);
}
public function next()
{
next($this->fields);
}
public function rewind()
{
reset($this->fields);
}
public function valid()
{
return current($this->fields);
}
}