|
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
|
|
|
namespace Jobs\View\Helper; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\View\Helper\AbstractHelper; |
|
14
|
|
|
use Jobs\Entity\JobInterface as Job; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Renders the link the an application form according to passed $options |
|
18
|
|
|
* linkOnly: Returns the relative link only |
|
19
|
|
|
* absolute: Make the link absolute |
|
20
|
|
|
* |
|
21
|
|
|
* Usage example with defaults: |
|
22
|
|
|
* <code> |
|
23
|
|
|
* <?=$this->applyUrl($job, ['linkOnly'=>true, 'absolute' => true])?> |
|
24
|
|
|
* </code> |
|
25
|
|
|
*/ |
|
26
|
|
|
/** |
|
27
|
|
|
* View helper to assemble an apply link according to the ATS configuration in a job entity. |
|
28
|
|
|
* |
|
29
|
|
|
* @method \Core\View\Helper\Params paramsHelper() |
|
30
|
|
|
* |
|
31
|
|
|
* @author Mathias Weitz <[email protected]> |
|
32
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
33
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
34
|
|
|
* @author Carsten Bleek <[email protected]> |
|
35
|
|
|
* @todo write test |
|
36
|
|
|
*/ |
|
37
|
|
|
class ApplyUrl extends AbstractHelper |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* Default options |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $options = [ |
|
45
|
|
|
'absolute' => false, |
|
46
|
|
|
'linkOnly' => false |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
protected $urlHelper; |
|
50
|
|
|
protected $translateHelper; |
|
51
|
|
|
protected $paramsHelper; |
|
52
|
|
|
protected $serverUrlHelper; |
|
53
|
|
|
|
|
54
|
|
|
public function setUrlHelper($helper) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->urlHelper = $helper; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function setTranslateHelper($helper) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->translateHelper = $helper; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function setParamsHelper($helper) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->paramsHelper = $helper; |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function setServerUrlHelper($helper) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->serverUrlHelper = $helper; |
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function __invoke(Job $jobEntity, $options = []) |
|
79
|
|
|
{ |
|
80
|
|
|
$options= array_merge($this->options, $options); |
|
81
|
|
|
|
|
82
|
|
|
$ats = $jobEntity->getAtsMode(); |
|
83
|
|
|
|
|
84
|
|
|
if ($ats->isDisabled()) { |
|
85
|
|
|
return ''; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$paramsHelper = $this->paramsHelper; |
|
89
|
|
|
$serverUrlHelper = $this->serverUrlHelper; |
|
90
|
|
|
$urlHelper = $this->urlHelper; |
|
91
|
|
|
|
|
92
|
|
|
if ($ats->isIntern() || $ats->isEmail()) { |
|
93
|
|
|
|
|
94
|
|
|
$query = [ 'subscriberUri' => $serverUrlHelper(array()) . '/subscriber/' . 1 ]; |
|
95
|
|
|
$route = 'lang/apply'; |
|
96
|
|
|
$params = [ |
|
97
|
|
|
'applyId' => $jobEntity->getApplyId(), |
|
98
|
|
|
'lang' => $paramsHelper('lang'), |
|
99
|
|
|
]; |
|
100
|
|
|
if ($paramsHelper('channel')) { |
|
101
|
|
|
$params['channel'] = $paramsHelper('channel'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$url = $urlHelper($route, $params, array('query' => $query)); |
|
105
|
|
|
} else { |
|
106
|
|
|
$url = $ats->getUri(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if($options['linkOnly']){ |
|
110
|
|
|
$result=$url; |
|
111
|
|
|
if($options['absolute']) { |
|
112
|
|
|
$result = $serverUrlHelper($url); |
|
113
|
|
|
} |
|
114
|
|
|
}else{ |
|
115
|
|
|
$translate = $this->translateHelper; |
|
116
|
|
|
$result = sprintf('<a href="%s" rel="nofollow">%s</a>', $url, $translate('Apply')); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return $result; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param $options |
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
public function setOptions($options){ |
|
|
|
|
|
|
126
|
|
|
foreach($options as $key=>$val) { |
|
127
|
|
|
if (array_key_exists($this->options,$key)) { |
|
128
|
|
|
$this->options[$key]=$val; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.