SubmissionsSubmission.php
2.29 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
<?php
// namespace NinjaForms\Pdf\Adapters;
final class NF_Adapters_SubmissionsSubmission extends NF_Adapters_SubmissionsFields
{
protected $fields;
protected $submission;
public function __construct($fields, $form_id, $submission)
{
parent::__construct($fields, $form_id);
$this->submission = $submission;
}
/*
|--------------------------------------------------------------------------
| ArrayAccess
|--------------------------------------------------------------------------
*/
public function offsetExists($offset)
{
if (isset($this->fields[$offset])) {
return true;
}
return $this->offsetMaybeCreate($offset);
}
public function offsetGet($offset)
{
if (isset($this->fields[$offset])) {
return $this->fields[$offset];
}
return $this->offsetMaybeCreate($offset);
}
protected function offsetMaybeCreate($offset)
{
foreach ($this->fields as $field) {
if ($offset != $field->get_setting('key')) {
continue;
}
return $this->fields[$offset] = [
'id' => $field->get_id(),
'type' => $field->get_setting('type'),
'label' => $field->get_setting('label'),
'admin_label' => $field->get_setting('admin_label'),
'value' => $this->submission->get_field_value($field->get_id()),
'key' => $field->get_setting( 'key' ),
'options' => $field->get_setting( 'options' )
];
}
return false;
}
/*
|--------------------------------------------------------------------------
| Iterator
|--------------------------------------------------------------------------
*/
public function current()
{
$field = current($this->fields);
return [
'id' => $field->get_id(),
'type' => $field->get_setting('type'),
'label' => $field->get_setting('label'),
'admin_label' => $field->get_setting('admin_label'),
'value' => $this->submission->get_field_value($field->get_id()),
'key' => $field->get_setting( 'key' ),
'options' => $field->get_setting( 'options' )
];
}
}