Completed
Push — develop ( f8651f...893e32 )
by greg
02:30
created

MemoryCard   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 132
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 104 1
A getServiceManager() 0 4 1
A setServiceManager() 0 6 1
1
<?php
2
3
namespace PlaygroundGame\Form\Admin;
4
5
use Zend\Form\Element;
6
use ZfcUser\Form\ProvidesEventsForm;
7
use Zend\Mvc\I18n\Translator;
8
use Zend\ServiceManager\ServiceManager;
9
10
class MemoryCard 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' => 'memory_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
            'type' => 'Zend\Form\Element\Textarea',
50
            'name' => 'description',
51
            'options' => array(
52
                'label' => $translator->translate('Description', 'playgroundgame'),
53
            ),
54
            'required' => false,
55
                'cols' => '40',
56
                'rows' => '10',
57
                'id' => 'description',
58
        ));
59
60
        // Adding an empty upload field to be able to correctly handle this on the service side.
61
        $this->add(array(
62
                'name' => 'upload_image',
63
                'attributes' => array(
64
                    'type'  => 'file',
65
                ),
66
                'options' => array(
67
                    'label' => $translator->translate('Image', 'playgroundgame'),
68
                    'label_attributes' => array(
69
                        'class' => 'control-label',
70
                    ),
71
                ),
72
        ));
73
        $this->add(array(
74
                'name' => 'image',
75
                'type'  => 'Zend\Form\Element\Hidden',
76
                'attributes' => array(
77
                    'value' => '',
78
                ),
79
        ));
80
        $this->add(array(
81
                'name' => 'delete_image',
82
                'type' => 'Zend\Form\Element\Hidden',
83
                'attributes' => array(
84
                    'value' => '',
85
                    'class' => 'delete_image',
86
                ),
87
        ));
88
89
        $this->add(array(
90
            'type' => 'Zend\Form\Element\Textarea',
91
            'name' => 'jsonData',
92
            'options' => array(
93
                'label' => $translator->translate('Json Data', 'playgroundgame'),
94
                'label_attributes' => array(
95
                    'class' => 'control-label',
96
                ),
97
            ),
98
            'attributes' => array(
99
                'required' => false,
100
                'cols' => '40',
101
                'rows' => '10',
102
                'id' => 'jsonData',
103
            ),
104
        ));
105
106
        $submitElement = new Element\Button('submit');
107
        $submitElement->setAttributes(array(
108
            'type'  => 'submit',
109
            'class' => 'btn btn-primary',
110
        ));
111
112
        $this->add($submitElement, array(
113
            'priority' => -100,
114
        ));
115
    }
116
117
118
    /**
119
     * Retrieve service manager instance
120
     *
121
     * @return ServiceManager
122
     */
123
    public function getServiceManager()
124
    {
125
        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...
126
    }
127
128
    /**
129
     * Set service manager instance
130
     *
131
     * @param  ServiceManager $serviceManager
132
     *
133
     * @return InstantWinOccurrence
134
     */
135
    public function setServiceManager(ServiceManager $serviceManager)
136
    {
137
        $this->serviceManager = $serviceManager;
138
139
        return $this;
140
    }
141
}
142