Completed
Push — develop ( 4bf430...c74260 )
by
unknown
18:30
created

Job::renderPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 55
rs 9.7692
cc 1
eloc 7
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** Jobs forms */
11
namespace Jobs\Form;
12
13
use Core\Form\Event\FormEvent;
14
use Core\Form\WizardContainer;
15
use Zend\EventManager\EventManager;
16
use Zend\EventManager\EventManagerInterface;
17
use Zend\View\Renderer\PhpRenderer as Renderer;
18
use Core\Form\propagateAttributeInterface;
19
20
/**
21
 * Jobs form container. Defines all formulars for entering a job position.
22
 *
23
 * @author Mathias Weitz <[email protected]>
24
 */
25
class Job extends WizardContainer
26
{
27
    /**
28
     * The event manager
29
     *
30
     * @var EventManagerInterface
31
     */
32
    protected $events;
33
34
    public function setEventManager(EventManagerInterface $events)
35
    {
36
        $this->events = $events;
37
38
        return $this;
39
    }
40
41
    public function getEventManager()
42
    {
43
        if (!$this->events) {
44
            $this->setEventManager(new EventManager());
45
        }
46
47
        return $this->events;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     *
53
     * Adds the standard forms and child containers.
54
     *
55
     * @see \Zend\Form\Element::init()
56
     */
57
    public function init()
58
    {
59
        $elements = [
60
            'general' => [
61
                'priority' => 100,
62
                'options' => [ 'label' => 'Basic Data' ],
63
                'property' => true,
64
                'forms' => [
65
66
                    'locationForm' => array(
67
                        'type' => 'Jobs/Base',
68
                        'property' => true,
69
                        'options' => array(
70
                            'enable_descriptions' => true,
71
                            'description' => /*@translate*/ 'Please choose a descriptive title and a location for your job posting ',
72
                            'display_mode' => 'summary'
73
                        )
74
                    ),
75
                    'nameForm' => array(
76
                        'type' => 'Jobs/CompanyName',
77
                        'property' => true,
78
                        'options' => array(
79
                            'enable_descriptions' => true,
80
                            'description' => /*@translate*/ 'Please choose the name of the hiring organization. The selected name defines the template of the job opening.',
81
                            'display_mode' => 'summary'
82
                        )
83
                    ),
84
                    'classifications' => [
85
                        'type' => 'Jobs/Classifications',
86
                        'options' => [
87
                            'enable_descriptions' => true,
88
                            'description' => /*@translate*/ 'Classify the job.',
89
                            'display_mode' => 'summary',
90
                        ],
91
                    ],
92
                    'portalForm' => array(
93
                        'type' => 'Jobs/Multipost',
94
                        'property' => true,
95
                        'options' => array(
96
                            'enable_descriptions' => true,
97
                            'description' => /*@translate*/ 'Please choose the portals, where you wish to publish your job opening.',
98
                            'display_mode' => 'summary'
99
                        )
100
                    ),
101
                ],
102
            ],
103
104
            'description' => [
105
                'priority' => '80',
106
                'options' => [ 'label' => 'Job opening' ],
107
                'property' => true,
108
                'forms' => [
109
                    'descriptionForm' => array(
110
                        'type' => 'Jobs/Description',
111
                        'property' => true,
112
                    ),
113
                ],
114
            ],
115
116
            'preview' => [
117
                'priority' => 60,
118
                'options' => [ 'label' => 'Preview' ],
119
                'property' => true,
120
                'forms' => [
121
                    'previewForm' => array(
122
                        'type' => 'Jobs/Preview',
123
                        'property' => true,
124
                    ),
125
                ],
126
            ],
127
128
        ];
129
130
        $this->setForms($elements);
131
132
        $events  = $this->getEventManager();
133
        $events->trigger(FormEvent::EVENT_INIT, $this);
134
    }
135
136
    public function renderPost(Renderer $renderer)
137
    {
138
        $coreformsjs   = $renderer->basepath('/Core/js/core.forms.js');
0 ignored issues
show
Unused Code introduced by
$coreformsjs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
139
        $javaScript = <<<JS
140
        $(document).ready(function() {
141
142
            console.log('attached yk.forms.done to ', \$('form'));
143
144
             \$('form').on('yk.forms.done', function(event, data) {
145
                //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {}
146
                if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {
147
                    if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) {
148
                        $('#job_incomplete').hide();
149
                        \$('.wizard-container .finish').removeClass('disabled');
150
                    }
151
                    else {
152
                        $('#job_incomplete').show();
153
                        \$('.wizard-container .finish').addClass('disabled');
154
                    }
155
                }
156
                \$('#job_errormessages').empty();
157
158
                if (typeof data['data']['errorMessage'] != 'undefined') {
159
                    $('#job_errormessages').append(data['data']['errorMessage']);
160
                }
161
                console.debug('job-form-inline', event, data);
162
             });
163
             \$('.wizard-container').on('wizard:tabShow.jobcontainer', function(e, \$tab, \$nav, index) {
164
                var \$link = \$tab.find('a');
165
                var href = \$link.attr('href');
166
                var \$target = \$(href);
167
                var \$iframe = \$target.find('iframe');
168
169
                \$iframe.each(function() { this.contentDocument.location.reload(true); });
170
171
                var \$productList = \$target.find('#product-list-wrapper');
172
                if (\$productList.length) {
173
                    \$productList.html('').load('/' + lang + '/jobs/channel-list?id=' + \$('#general-nameForm-job').val());
174
                }
175
             });
176
177
             \$('.wizard-container .finish a').click(function (e) {
178
                if (\$(e.currentTarget).parent().hasClass('disabled')) {
179
                    e.preventDefault();
180
                    return false;
181
                }
182
             });
183
184
        });
185
JS;
186
187
        $renderer->headScript()->appendScript($javaScript);
188
189
        return parent::renderPost($renderer);
190
    }
191
192
193
    public function enableAll($enable = true)
194
    {
195
        foreach ($this->activeForms as $formkey) {
196
            $forms = $this->getForm($formkey);
197
            if ($forms instanceof propagateAttributeInterface) {
198
                $forms->enableAll($enable);
199
            }
200
        }
201
        return $this;
202
    }
203
}
204