1 <?php
2
3 namespace Balance\Form;
4
5 use Balance\Model\EntryType;
6 use Balance\Model\Persistence\ValueOptionsInterface;
7 use Zend\Form\Fieldset;
8 use Zend\Form\Form;
9 use Zend\ServiceManager\ServiceLocatorAwareInterface;
10 use Zend\ServiceManager\ServiceLocatorAwareTrait;
11
12 13 14
15 class Postings extends Form implements ServiceLocatorAwareInterface
16 {
17 use ServiceLocatorAwareTrait;
18
19 20 21
22 public function init()
23 {
24
25 $pAccounts = $this->getServiceLocator()->getServiceLocator()->get('Balance\Model\Persistence\Accounts');
26
27
28 if (! $pAccounts instanceof ValueOptionsInterface) {
29 throw new FormException('Invalid Model');
30 }
31
32
33 $this->add(array(
34 'type' => 'Hidden',
35 'name' => 'id',
36 ));
37
38
39 $this->add(array(
40 'type' => 'DateTime',
41 'name' => 'datetime',
42 ));
43
44
45 $this->add(array(
46 'type' => 'Textarea',
47 'name' => 'description',
48 ));
49
50
51 $subform = $this->getServiceLocator()->get('Fieldset');
52
53
54 $subform->add(array(
55 'type' => 'Select',
56 'name' => 'type',
57 'options' => array(
58 'value_options' => (new EntryType())->getDefinition(),
59 ),
60 ));
61
62
63 $subform->add(array(
64 'type' => 'Select',
65 'name' => 'account_id',
66 'options' => array(
67 'value_options' => $pAccounts->getValueOptions(),
68 ),
69 ));
70
71
72 $subform->add(array(
73 'type' => 'Currency',
74 'name' => 'value',
75 ));
76
77
78 $this->add(array(
79 'type' => 'Collection',
80 'name' => 'entries',
81 'options' => array(
82 'target_element' => $subform,
83 'allow_add' => true,
84 'count' => 2,
85 ),
86 ));
87 }
88 }
89