Completed
Push — develop ( d809fa...f2a1ed )
by
unknown
08:20
created

ViewModelTemplateFilterAbstract::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 * @author    [email protected]
9
 */
10
11
12
namespace Jobs\Filter;
13
14
use Jobs\Entity\Job;
15
use Zend\Filter\FilterInterface;
16
use Zend\View\Model\ViewModel;
17
18
/**
19
 * assembles a ViewModel for job templates.
20
 * this class needs to be extended for specific assignments
21
 * Class viewModelTemplateFilterAbstract
22
 * @package Jobs\Filter
23
 */
24
abstract class ViewModelTemplateFilterAbstract implements FilterInterface
0 ignored issues
show
Coding Style introduced by
ViewModelTemplateFilterAbstract does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
25
{
26
27
    /**
28
     * @var array assembles all data for the viewmodel
29
     */
30
    protected $container;
31
32
    /**
33
     * @var Job
34
     */
35
    protected $job;
36
37
    /**
38
     * @var array
39
     */
40
    protected $config;
41
42
    /**
43
     * creating absolute links like the apply-link
44
     * absolute links are needed on the server of the provider
45
     *
46
     * @var $urlPlugin \Zend\Mvc\Controller\Plugin\Url
47
     */
48
    protected $urlPlugin;
49
50
    /**
51
     * also needed to create absolute links
52
     * @var
53
     */
54
    protected $basePathHelper;
55
56
    /**
57
     * @var $serverUrlHelper \Zend\View\Helper\ServiceUrl
58
     */
59
    protected $serverUrlHelper;
60
61
    /**
62
     * @var $imageFileCacheHelper \Organizations\ImageFileCache\Manager
63
     */
64
    protected $imageFileCacheHelper;
65
66
    /**
67
     * @param $config
68
     */
69
    public function setConfig($config)
70
    {
71
        $this->config = $config;
72
        return;
73
    }
74
75
    /**
76
     * @param $urlPlugin
77
     */
78
    public function setUrlPlugin($urlPlugin)
79
    {
80
        $this->urlPlugin = $urlPlugin;
81
        return;
82
    }
83
84
    /**
85
     * @param $basePathHelper \Zend\View\Helper\Basepath
86
     */
87
    public function setBasePathHelper($basePathHelper)
88
    {
89
        $this->basePathHelper = $basePathHelper;
90
        return;
91
    }
92
93
    /**
94
     * @return mixed
95
     */
96
    public function getBasePathHelper()
97
    {
98
        return $this->basePathHelper;
99
    }
100
101
    /**
102
     * @param $serverUrlHelper
103
     */
104
    public function setServerUrlHelper($serverUrlHelper)
105
    {
106
        $this->serverUrlHelper = $serverUrlHelper;
107
        return;
108
    }
109
110
	/**
111
     * @return mixed
112
     */
113
    public function getServerUrlHelper()
114
    {
115
        return $this->serverUrlHelper;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function setImageFileCacheHelper($imageFileCacheHelper)
122
    {
123
        $this->imageFileCacheHelper=$imageFileCacheHelper;
124
        return;
125
    }
126
127
    /**
128
     * @return mixed
129
     */
130
    public function getImageFileCacheHelper()
131
    {
132
        return $this->imageFileCacheHelper;
133
    }
134
135
    /**
136
     * @param mixed $value
137
     * @return mixed|ViewModel
138
     * @throws \InvalidArgumentException
139
     */
140
    public function filter($value)
141
    {
142
        $model = new ViewModel();
143
        $this->container = array();
144
        $this->extract($value);
145
        $model->setVariables($this->container);
146
        if (!isset($this->job)) {
147
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without an $job');
148
        }
149
        $model->setTemplate('templates/' . $this->job->getTemplate() . '/index');
150
        return $model;
151
    }
152
153
    /**
154
     * should be overwritten
155
     * here are all assignments to container arr administered
156
     * input-attributes are the job and the configuration
157
     * output-attribute is the container
158
     * @param $value
159
     * @return mixed
160
     */
161
    abstract protected function extract($value);
162
163
    /**
164
     * Set the apply buttons of the job posting
165
     *
166
     * @return ViewModelTemplateFilterAbstract
167
     * @throws \InvalidArgumentException
168
     */
169
    protected function setApplyData()
170
    {
171
        if (!isset($this->job)) {
172
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
173
        }
174
        
175
        $data = [
176
            'applyId' => $this->job->getApplyId(),
177
            'uri' => null,
178
            'oneClickProfiles' => []
179
        ];
180
        $atsMode = $this->job->getAtsMode();
181
        
182
        if ($atsMode->isIntern() || $atsMode->isEmail()) {
183
            $data['uri'] = $this->urlPlugin->fromRoute('lang/apply', ['applyId' => $this->job->getApplyId()], ['force_canonical' => true]);
184
        } elseif ($atsMode->isUri()) {
185
            $data['uri'] = $atsMode->getUri();
186
        }
187
        
188
        if ($atsMode->isIntern() && $atsMode->getOneClickApply()) {
189
            $data['oneClickProfiles'] = $atsMode->getOneClickApplyProfiles();
190
        }
191
        
192
        $this->container['applyData'] = $data;
193
        
194
        return $this;
195
    }
196
197
    /**
198
     * Sets the location of a jobs
199
     *
200
     * @return $this
201
     * @throws \InvalidArgumentException
202
     */
203
    protected function setLocation()
204
    {
205
        if (!isset($this->job)) {
206
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without aa $job');
207
        }
208
        $location = $this->job->getLocation();
209
        $this->container['location'] = isset($location)?$location:'';
210
        return $this;
211
    }
212
213
    /**
214
     * Sets the company description of a job. Use the description of an organization as default
215
     *
216
     * @return $this
217
     * @throws \InvalidArgumentException
218
     */
219
    protected function setDescription()
220
    {
221
        if (!isset($this->job)) {
222
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
223
        }
224
225
        if (empty($this->job->getTemplateValues()->getDescription()) && is_object($this->job->getOrganization())) {
226
            $this->job->getTemplateValues()->setDescription($this->job->getOrganization()->getDescription());
227
        }
228
        $description = $this->job->getTemplateValues()->getDescription();
229
230
        $this->container['description'] = isset($description)?$description:'';
231
        return $this;
232
    }
233
234
    /**
235
     * Sets the organizations contact address
236
     *
237
     * @return $this
238
     * @throws \InvalidArgumentException
239
     */
240
    protected function setOrganizationInfo()
241
    {
242
        if (!isset($this->job)) {
243
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
244
        }
245
        $organizationName = '';
0 ignored issues
show
Unused Code introduced by
$organizationName 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...
246
        $organizationStreet = '';
0 ignored issues
show
Unused Code introduced by
$organizationStreet 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...
247
        $organizationPostalCode = '';
0 ignored issues
show
Unused Code introduced by
$organizationPostalCode 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...
248
        $organizationPostalCity = '';
0 ignored issues
show
Unused Code introduced by
$organizationPostalCity 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...
249
        $organization = $this->job->getOrganization();
250
        $user = $this->job->getUser();
251
252
        if (isset($organization)) {
253
            $organizationName = $organization->getOrganizationName()->getName();
254
            $organizationStreet = $organization->getContact()->getStreet().' '.$organization->getContact()->getHouseNumber();
255
            $organizationPostalCode = $organization->getContact()->getPostalcode();
256
            $organizationPostalCity = $organization->getContact()->getCity();
257
            $organizationPhone = $organization->getContact()->getPhone();
258
            $organizationFax = $organization->getContact()->getFax();
259
        } else {
260
            $organizationName =
261
            $organizationStreet =
262
            $organizationPostalCode =
263
            $organizationPostalCity =
264
            $organizationPhone =
265
            $organizationFax = '';
266
        }
267
        $this->container['contactEmail'] = $user ? $user->getInfo()->getEmail() : '';
268
        $this->container['organizationName'] = $organizationName;
269
        $this->container['street'] = $organizationStreet;
270
        $this->container['postalCode'] = $organizationPostalCode;
271
        $this->container['city'] = $organizationPostalCity;
272
        $this->container['phone'] = $organizationPhone;
273
        $this->container['fax'] = $organizationFax;
274
275
        if (is_object($organization) && is_object($organization->getImage()) && $organization->getImage()->getUri()) {
276
            $this->container['uriLogo'] = $this->basePathHelper->__invoke($this->imageFileCacheHelper->getUri($organization->getImage(true)));
0 ignored issues
show
Unused Code introduced by
The call to OrganizationInterface::getImage() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
277
        } else {
278
            $this->container['uriLogo'] = $this->makeAbsolutePath($this->config->default_logo);
279
        }
280
        return $this;
281
    }
282
283
    /**
284
     * Sets the default values of an organizations job template
285
     *
286
     * @return $this
287
     * @throws \InvalidArgumentException
288
     */
289
    protected function setTemplateDefaultValues()
290
    {
291
        if (!isset($this->job)) {
292
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
293
        }
294
        $labelQualifications='';
295
        $labelBenefits='';
296
        $labelRequirements='';
297
298
        $organization = $this->job->getOrganization();
299
        if (isset($organization)) {
300
            $labelRequirements = $organization->getTemplate()->getLabelRequirements();
301
            $labelQualifications = $organization->getTemplate()->getLabelQualifications();
302
            $labelBenefits = $organization->getTemplate()->getLabelBenefits();
303
        }
304
        $this->container['labelRequirements'] = $labelRequirements;
305
        $this->container['labelQualifications'] = $labelQualifications;
306
        $this->container['labelBenefits'] = $labelBenefits;
307
308
        return $this;
309
    }
310
311
    /**
312
     * Sets the template
313
     *
314
     * @return $this
315
     */
316
    protected function setTemplate()
317
    {
318
        $this->container['templateName'] = $this->job->getTemplate();
319
        return $this;
320
    }
321
322
    /**
323
     * combines two helper
324
     *
325
     * @param $path
326
     * @return mixed
327
     */
328
    protected function makeAbsolutePath($path)
329
    {
330
        $path = $this->serverUrlHelper->__invoke($this->basePathHelper->__invoke($path));
331
        return $path;
332
    }
333
}
334