Completed
Push — develop ( 168e99...0122be )
by
unknown
18:37 queued 07:11
created

Job::renderPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
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
60
        $elements = [
61
            'general' => [
62
                'priority' => 0,
63
                'options' => [ 'label' => 'General' ],
64
                'property' => true,
65
                'forms' => [
66
67
                    'locationForm' => array(
68
                        'type' => 'Jobs/Base',
69
                        'property' => true,
70
                        'options' => array(
71
                            'enable_descriptions' => true,
72
                            'description' => /*@translate*/ 'Please choose a descriptive title and a location for your job posting ',
73
                            'display_mode' => 'summary'
74
                        )
75
                    ),
76
                    'nameForm' => array(
77
                        'type' => 'Jobs/CompanyName',
78
                        'property' => true,
79
                        'options' => array(
80
                            'enable_descriptions' => true,
81
                            'description' => /*@translate*/ 'Please choose the name of the hiring organization. The selected name defines the template of the job opening.',
82
                            'display_mode' => 'summary'
83
                        )
84
                    ),
85
                    'portalForm' => array(
86
                        'type' => 'Jobs/Multipost',
87
                        'property' => true,
88
                        'options' => array(
89
                            'enable_descriptions' => true,
90
                            'description' => /*@translate*/ 'Please choose the portals, where you wish to publish your job opening.',
91
                            'display_mode' => 'summary'
92
                        )
93
                    ),
94
                ],
95
            ],
96
97
            'description' => [
98
                'priority' => '0',
99
                'options' => [ 'label' => 'Description' ],
100
                'property' => true,
101
                'forms' => [
102
                    'descriptionForm' => array(
103
                        'type' => 'Jobs/Description',
104
                        'property' => true,
105
                    ),
106
                ],
107
            ],
108
109
            'preview' => [
110
                'priority' => 0,
111
                'options' => [ 'label' => 'Preview' ],
112
                'property' => true,
113
                'forms' => [
114
                    'previewForm' => array(
115
                        'type' => 'Jobs/Preview',
116
                        'property' => true,
117
                    ),
118
                ],
119
            ],
120
        ];
121
122
        $this->setForms($elements);
123
124
        $events  = $this->getEventManager();
125
        $events->trigger(FormEvent::EVENT_INIT, $this);
126
    }
127
128
    public function renderPost(Renderer $renderer)
129
    {
130
        $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...
131
        $javaScript = <<<JS
132
        $(document).ready(function() {
133
134
            console.log('attached yk.forms.done to ', \$('form'));
135
136
             \$('form').on('yk.forms.done', function(event, data) {
137
                //if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {}
138
                if (typeof data != 'undefined' && typeof data['data'] != 'undefined') {
139
                    if (typeof data['data']['jobvalid'] != 'undefined' && data['data']['jobvalid'] === true) {
140
                        $('#job_incomplete').hide();
141
                        \$('.wizard-container .finish').removeClass('disabled');
142
                    }
143
                    else {
144
                        $('#job_incomplete').show();
145
                        \$('.wizard-container .finish').addClass('disabled');
146
                    }
147
                }
148
                \$('#job_errormessages').empty();
149
150
                if (typeof data['data']['errorMessage'] != 'undefined') {
151
                    $('#job_errormessages').append(data['data']['errorMessage']);
152
                }
153
                console.debug('job-form-inline', event, data);
154
             });
155
             \$('.wizard-container').on('wizard:tabShow.jobcontainer', function(e, \$tab, \$nav, index) {
156
                var \$link = \$tab.find('a');
157
                var href = \$link.attr('href');
158
                var \$target = \$(href);
159
                var \$iframe = \$target.find('iframe');
160
161
                \$iframe.each(function() { this.contentDocument.location.reload(true); });
162
163
                var \$productList = \$target.find('#product-list-wrapper');
164
                if (\$productList.length) {
165
                    \$productList.html('').load('/' + lang + '/jobs/channel-list?id=' + \$('#general-nameForm-job').val());
166
                }
167
             });
168
169
             \$('.wizard-container .finish a').click(function (e) {
170
                if (\$(e.currentTarget).parent().hasClass('disabled')) {
171
                    e.preventDefault();
172
                    return false;
173
                }
174
             });
175
176
        });
177
JS;
178
179
        $renderer->headScript()->appendScript($javaScript);
180
181
        return parent::renderPost($renderer);
182
    }
183
184
185
    public function enableAll($enable = true)
186
    {
187
        foreach ($this->activeForms as $formkey) {
188
            $forms = $this->getForm($formkey);
189
            if ($forms instanceof propagateAttributeInterface) {
190
                $forms->enableAll($enable);
191
            }
192
        }
193
        return $this;
194
    }
195
}
196