Completed
Push — master ( a5446b...0a03f7 )
by greg
06:15 queued 03:04
created

TradingCardModel::setServiceManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PlaygroundGame\Form\Admin;
4
5
use Zend\Form\Element;
6
use ZfcBase\Form\ProvidesEventsForm;
7
use Zend\Mvc\I18n\Translator;
8
use Zend\ServiceManager\ServiceManager;
9
10
class TradingCardModel extends ProvidesEventsForm
11
{
12
    public function __construct($name, ServiceManager $serviceManager, Translator $translator)
13
    {
14
        parent::__construct($name);
15
16
        $this->setAttribute('method', 'post');
17
        $this->setAttribute('enctype', 'multipart/form-data');
18
19
        $this->setServiceManager($serviceManager);
20
21
        $this->add(array(
22
            'name' => 'trading_card_id',
23
            'type'  => 'Zend\Form\Element\Hidden',
24
            'attributes' => array(
25
                'value' => 0,
26
            ),
27
        ));
28
29
        $this->add(array(
30
            'name' => 'id',
31
            'type'  => 'Zend\Form\Element\Hidden',
32
            'attributes' => array(
33
                'value' => 0,
34
            ),
35
        ));
36
37
        $this->add(array(
38
            'name' => 'title',
39
            'options' => array(
40
                'label' => $translator->translate('Title', 'playgroundgame'),
41
            ),
42
            'attributes' => array(
43
                'type' => 'text',
44
                'id' => 'title'
45
            ),
46
        ));
47
48
        $this->add(array(
49
            'name' => 'type',
50
            'options' => array(
51
                'label' => $translator->translate('Type (Collector / Standard)', 'playgroundgame'),
52
            ),
53
            'attributes' => array(
54
                'type' => 'text',
55
                'id' => 'type'
56
            ),
57
        ));
58
59
        $this->add(array(
60
            'name' => 'family',
61
            'options' => array(
62
                'label' => $translator->translate('Family', 'playgroundgame'),
63
            ),
64
            'attributes' => array(
65
                'type' => 'text',
66
                'id' => 'family'
67
            ),
68
        ));
69
70
        $this->add(array(
71
            'name' => 'points',
72
            'options' => array(
73
                'label' => $translator->translate('Points', 'playgroundgame'),
74
            ),
75
            'attributes' => array(
76
                'type' => 'text',
77
                'id' => 'points'
78
            ),
79
        ));
80
        $this->add(array(
81
            'type' => 'Zend\Form\Element\Textarea',
82
            'name' => 'description',
83
            'options' => array(
84
                'label' => $translator->translate('Description', 'playgroundgame'),
85
            ),
86
            'required' => false,
87
                'cols' => '40',
88
                'rows' => '10',
89
                'id' => 'description',
90
        ));
91
92
        $this->add(array(
93
            'name' => 'distribution',
94
            'options' => array(
95
                'label' => $translator->translate('probability drawing', 'playgroundgame'),
96
            ),
97
            'attributes' => array(
98
                'type' => 'text',
99
                'id' => 'distribution'
100
            ),
101
        ));
102
103
        // Adding an empty upload field to be able to correctly handle this on the service side.
104
        $this->add(array(
105
                'name' => 'upload_image',
106
                'attributes' => array(
107
                    'type'  => 'file',
108
                ),
109
                'options' => array(
110
                    'label' => $translator->translate('Image', 'playgroundgame'),
111
                    'label_attributes' => array(
112
                        'class' => 'control-label',
113
                    ),
114
                ),
115
        ));
116
        $this->add(array(
117
                'name' => 'image',
118
                'type'  => 'Zend\Form\Element\Hidden',
119
                'attributes' => array(
120
                    'value' => '',
121
                ),
122
        ));
123
        $this->add(array(
124
                'name' => 'delete_image',
125
                'type' => 'Zend\Form\Element\Hidden',
126
                'attributes' => array(
127
                    'value' => '',
128
                    'class' => 'delete_image',
129
                ),
130
        ));
131
132
        $this->add(array(
133
                'type' => 'Zend\Form\Element\DateTime',
134
                'name' => 'availability',
135
                'options' => array(
136
                    'label' => $translator->translate('Availability date', 'playgroundgame'),
137
                    'format' => 'd/m/Y H:i:s'
138
                ),
139
                'attributes' => array(
140
                    'type' => 'text',
141
                    'class'=> 'datepicker',
142
                    'id' => 'availability'
143
                ),
144
        ));
145
146
        $this->add(array(
147
            'type' => 'Zend\Form\Element\Textarea',
148
            'name' => 'jsonData',
149
            'options' => array(
150
                'label' => $translator->translate('Json Data', 'playgroundgame'),
151
                'label_attributes' => array(
152
                    'class' => 'control-label',
153
                ),
154
            ),
155
            'attributes' => array(
156
                'required' => false,
157
                'cols' => '40',
158
                'rows' => '10',
159
                'id' => 'jsonData',
160
            ),
161
        ));
162
163
        $submitElement = new Element\Button('submit');
164
        $submitElement->setAttributes(array(
165
            'type'  => 'submit',
166
            'class' => 'btn btn-primary',
167
        ));
168
169
        $this->add($submitElement, array(
170
            'priority' => -100,
171
        ));
172
    }
173
174
175
    /**
176
     * Retrieve service manager instance
177
     *
178
     * @return ServiceManager
179
     */
180
    public function getServiceManager()
181
    {
182
        return $this->serviceManager;
0 ignored issues
show
Bug introduced by
The property serviceManager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
183
    }
184
185
    /**
186
     * Set service manager instance
187
     *
188
     * @param  ServiceManager $serviceManager
189
     * @return InstantWinOccurrence
190
     */
191
    public function setServiceManager(ServiceManager $serviceManager)
192
    {
193
        $this->serviceManager = $serviceManager;
194
195
        return $this;
196
    }
197
}
198