Completed
Push — develop ( 38be37...f8baa2 )
by
unknown
07:07
created

ViewModelTemplateFilterAbstract::getJsonLdHelper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 Jobs\View\Helper\JsonLd;
16
use Zend\Filter\FilterInterface;
17
use Zend\View\Model\ViewModel;
18
19
/**
20
 * assembles a ViewModel for job templates.
21
 * this class needs to be extended for specific assignments
22
 * Class viewModelTemplateFilterAbstract
23
 * @package Jobs\Filter
24
 */
25
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...
26
{
27
28
    /**
29
     * @var array assembles all data for the viewmodel
30
     */
31
    protected $container;
32
33
    /**
34
     * @var Job
35
     */
36
    protected $job;
37
38
    /**
39
     * @var array
40
     */
41
    protected $config;
42
43
    /**
44
     * creating absolute links like the apply-link
45
     * absolute links are needed on the server of the provider
46
     *
47
     * @var $urlPlugin \Zend\Mvc\Controller\Plugin\Url
48
     */
49
    protected $urlPlugin;
50
51
    /**
52
     * also needed to create absolute links
53
     * @var
54
     */
55
    protected $basePathHelper;
56
57
    /**
58
     * @var $serverUrlHelper \Zend\View\Helper\ServiceUrl
59
     */
60
    protected $serverUrlHelper;
61
62
    /**
63
     * @var $imageFileCacheHelper \Organizations\ImageFileCache\Manager
64
     */
65
    protected $imageFileCacheHelper;
66
67
    /**
68
     *
69
     *
70
     * @var JsonLd
71
     */
72
    protected $jsonLdHelper;
73
74
    /**
75
     * @param \Jobs\View\Helper\JsonLd $jsonLdHelper
76
     *
77
     * @return self
78
     */
79
    public function setJsonLdHelper(JsonLd $jsonLdHelper)
80
    {
81
        $this->jsonLdHelper = $jsonLdHelper;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return \Jobs\View\Helper\JsonLd
88
     */
89
    public function getJsonLdHelper()
90
    {
91
        return $this->jsonLdHelper;
92
    }
93
94
    /**
95
     * @param $config
96
     */
97
    public function setConfig($config)
98
    {
99
        $this->config = $config;
100
        return;
101
    }
102
103
    /**
104
     * @param $urlPlugin
105
     */
106
    public function setUrlPlugin($urlPlugin)
107
    {
108
        $this->urlPlugin = $urlPlugin;
109
        return;
110
    }
111
112
    /**
113
     * @param $basePathHelper \Zend\View\Helper\Basepath
114
     */
115
    public function setBasePathHelper($basePathHelper)
116
    {
117
        $this->basePathHelper = $basePathHelper;
118
        return;
119
    }
120
121
    /**
122
     * @return mixed
123
     */
124
    public function getBasePathHelper()
125
    {
126
        return $this->basePathHelper;
127
    }
128
129
    /**
130
     * @param $serverUrlHelper
131
     */
132
    public function setServerUrlHelper($serverUrlHelper)
133
    {
134
        $this->serverUrlHelper = $serverUrlHelper;
135
        return;
136
    }
137
138
	/**
139
     * @return mixed
140
     */
141
    public function getServerUrlHelper()
142
    {
143
        return $this->serverUrlHelper;
144
    }
145
146
    /**
147
     * @return mixed
148
     */
149
    public function setImageFileCacheHelper($imageFileCacheHelper)
150
    {
151
        $this->imageFileCacheHelper=$imageFileCacheHelper;
152
        return;
153
    }
154
155
    /**
156
     * @return mixed
157
     */
158
    public function getImageFileCacheHelper()
159
    {
160
        return $this->imageFileCacheHelper;
161
    }
162
163
    /**
164
     * @param mixed $value
165
     * @return mixed|ViewModel
166
     * @throws \InvalidArgumentException
167
     */
168
    public function filter($value)
169
    {
170
        $model = new ViewModel();
171
        $this->container = array();
172
        $this->extract($value);
173
        $model->setVariables($this->container);
174
        if (!isset($this->job)) {
175
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without an $job');
176
        }
177
        $model->setTemplate('templates/' . $this->job->getTemplate() . '/index');
178
        return $model;
179
    }
180
181
    /**
182
     * should be overwritten
183
     * here are all assignments to container arr administered
184
     * input-attributes are the job and the configuration
185
     * output-attribute is the container
186
     * @param $value
187
     * @return mixed
188
     */
189
    abstract protected function extract($value);
190
191
    /**
192
     * Set the apply buttons of the job posting
193
     *
194
     * @return ViewModelTemplateFilterAbstract
195
     * @throws \InvalidArgumentException
196
     */
197
    protected function setApplyData()
198
    {
199
        if (!isset($this->job)) {
200
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
201
        }
202
        
203
        $data = [
204
            'applyId' => $this->job->getApplyId(),
205
            'uri' => null,
206
            'oneClickProfiles' => []
207
        ];
208
        $atsMode = $this->job->getAtsMode();
209
        
210
        if ($atsMode->isIntern() || $atsMode->isEmail()) {
211
            $data['uri'] = $this->urlPlugin->fromRoute('lang/apply', ['applyId' => $this->job->getApplyId()], ['force_canonical' => true]);
212
        } elseif ($atsMode->isUri()) {
213
            $data['uri'] = $atsMode->getUri();
214
        }
215
        
216
        if ($atsMode->isIntern() && $atsMode->getOneClickApply()) {
217
            $data['oneClickProfiles'] = $atsMode->getOneClickApplyProfiles();
218
        }
219
        
220
        $this->container['applyData'] = $data;
221
        
222
        return $this;
223
    }
224
225
    /**
226
     * Sets the location of a jobs
227
     *
228
     * @return $this
229
     * @throws \InvalidArgumentException
230
     */
231
    protected function setLocation()
232
    {
233
        if (!isset($this->job)) {
234
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without aa $job');
235
        }
236
        $location = $this->job->getLocation();
237
        $this->container['location'] = isset($location)?$location:'';
238
        return $this;
239
    }
240
241
    /**
242
     * Sets the company description of a job. Use the description of an organization as default
243
     *
244
     * @return $this
245
     * @throws \InvalidArgumentException
246
     */
247
    protected function setDescription()
248
    {
249
        if (!isset($this->job)) {
250
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
251
        }
252
253
        if (empty($this->job->getTemplateValues()->getDescription()) && is_object($this->job->getOrganization())) {
254
            $this->job->getTemplateValues()->setDescription($this->job->getOrganization()->getDescription());
255
        }
256
        $description = $this->job->getTemplateValues()->getDescription();
257
258
        $this->container['description'] = isset($description)?$description:'';
259
        return $this;
260
    }
261
262
    /**
263
     * Sets the organizations contact address
264
     *
265
     * @return $this
266
     * @throws \InvalidArgumentException
267
     */
268
    protected function setOrganizationInfo()
269
    {
270
        if (!isset($this->job)) {
271
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
272
        }
273
        $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...
274
        $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...
275
        $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...
276
        $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...
277
        $organization = $this->job->getOrganization();
278
        $user = $this->job->getUser();
279
280
        if (isset($organization)) {
281
            $organizationName = $organization->getOrganizationName()->getName();
282
            $organizationStreet = $organization->getContact()->getStreet().' '.$organization->getContact()->getHouseNumber();
283
            $organizationPostalCode = $organization->getContact()->getPostalcode();
284
            $organizationPostalCity = $organization->getContact()->getCity();
285
            $organizationPhone = $organization->getContact()->getPhone();
286
            $organizationFax = $organization->getContact()->getFax();
287
        } else {
288
            $organizationName =
289
            $organizationStreet =
290
            $organizationPostalCode =
291
            $organizationPostalCity =
292
            $organizationPhone =
293
            $organizationFax = '';
294
        }
295
        $this->container['contactEmail'] = $user ? $user->getInfo()->getEmail() : '';
296
        $this->container['organizationName'] = $organizationName;
297
        $this->container['street'] = $organizationStreet;
298
        $this->container['postalCode'] = $organizationPostalCode;
299
        $this->container['city'] = $organizationPostalCity;
300
        $this->container['phone'] = $organizationPhone;
301
        $this->container['fax'] = $organizationFax;
302
303
        if (is_object($organization) && is_object($organization->getImage()) && $organization->getImage()->getUri()) {
304
            $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...
305
        } else {
306
            $this->container['uriLogo'] = $this->makeAbsolutePath($this->config->default_logo);
307
        }
308
        return $this;
309
    }
310
311
    /**
312
     * Sets the default values of an organizations job template
313
     *
314
     * @return $this
315
     * @throws \InvalidArgumentException
316
     */
317
    protected function setTemplateDefaultValues()
318
    {
319
        if (!isset($this->job)) {
320
            throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
321
        }
322
        $labelQualifications='';
323
        $labelBenefits='';
324
        $labelRequirements='';
325
326
        $organization = $this->job->getOrganization();
327
        if (isset($organization)) {
328
            $labelRequirements = $organization->getTemplate()->getLabelRequirements();
329
            $labelQualifications = $organization->getTemplate()->getLabelQualifications();
330
            $labelBenefits = $organization->getTemplate()->getLabelBenefits();
331
        }
332
        $this->container['labelRequirements'] = $labelRequirements;
333
        $this->container['labelQualifications'] = $labelQualifications;
334
        $this->container['labelBenefits'] = $labelBenefits;
335
336
        return $this;
337
    }
338
339
    /**
340
     * Sets the template
341
     *
342
     * @return $this
343
     */
344
    protected function setTemplate()
345
    {
346
        $this->container['templateName'] = $this->job->getTemplate();
347
        return $this;
348
    }
349
350
    /**
351
     * combines two helper
352
     *
353
     * @param $path
354
     * @return mixed
355
     */
356
    protected function makeAbsolutePath($path)
357
    {
358
        $path = $this->serverUrlHelper->__invoke($this->basePathHelper->__invoke($path));
359
        return $path;
360
    }
361
}
362