Completed
Push — develop ( 96e586...d6e286 )
by
unknown
07:43
created

Confirmation::getApplicationLink()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 3
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
 */
9
10
/** Confirmation.php */
11
namespace Applications\Mail;
12
13
use Auth\Entity\AnonymousUser;
14
use Auth\Entity\UserInterface;
15
use Core\Mail\StringTemplateMessage;
16
use Applications\Entity\ApplicationInterface;
17
use Zend\Mvc\Router\RouteStackInterface;
18
19
/**
20
 * Sends an confirmation Mail to the applicant.
21
 *
22
 * @package Applications\Mail
23
 */
24
class Confirmation extends StringTemplateMessage
25
{
26
    /**
27
     * @var ApplicationInterface
28
     */
29
    protected $application;
30
   
31
    protected $callbacks = array(
32
        'anrede_formell' => 'getFormalSalutation',
33
        'salutation_formal' => 'getFormalSalutation',
34
        'anrede_informell' => 'getInformalSalutation',
35
        'salutation_informal' => 'getInformalSalutation',
36
        'job_title' => 'getJobTitle',
37
        'date' => 'getDate',
38
        'link' => 'getApplicationLink',
39
    );
40
41
    /**
42
     *
43
     *
44
     * @var RouteStackInterface
45
     */
46
    protected $router;
47
48
    /**
49
     *
50
     *
51
     * @var UserInterface
52
     */
53
    protected $user;
54
55
    /**
56
     * @param RouteStackInterface $router
57
     *
58
     * @return self
59
     */
60
    public function setRouter($router)
61
    {
62
        $this->router = $router;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param UserInterface $user
69
     *
70
     * @return self
71
     */
72
    public function setUser($user)
73
    {
74
        $this->user = $user;
75
76
        return $this;
77
    }
78
79
80
81
82
    /**
83
     * @param ApplicationInterface $application
84
     * @return StringTemplateMessage
85
     */
86 View Code Duplication
    public function setVariablesFromApplication(ApplicationInterface $application)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
87
    {
88
        $contact = $application->getContact();
89
        $name    = $contact->getDisplayName();
90
        
91
        $variables = array(
92
            'name' => $name,
93
        );
94
        return $this->setVariables($variables);
95
    }
96
97
    /**
98
     * @param ApplicationInterface $application
99
     * @return $this
100
     */
101 View Code Duplication
    public function setApplication(ApplicationInterface $application)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
102
    {
103
        $this->application = $application;
104
        $this->setTo($application->getContact()->getEmail(), $application->getContact()->getDisplayName());
105
        $this->setVariablesFromApplication($application);
106
        return $this;
107
    }
108
109
    /**
110
     * @param $recruiter
111
     * @return $this
112
     */
113
    public function setRecruiter($recruiter)
114
    {
115
        $this->recruiter = $recruiter;
0 ignored issues
show
Bug introduced by
The property recruiter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
116
        return $this;
117
    }
118
119
    /**
120
     * @return string
121
     */
122 View Code Duplication
    protected function getFormalSalutation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
123
    {
124
        $contact = $this->application->getContact();
125
        $name    = $contact->getDisplayName();
126
        $gender  = $contact->getGender();
127
        $translator = $this->getTranslator();
128
        
129
        $salutation = 'male' == $gender
130
                    ? $translator->translate('Dear Mr. %s')
131
                    : $translator->translate('Dear Ms. %s');
132
        
133
        return sprintf($salutation, $name);
134
    }
135
136
    /**
137
     * @return string
138
     */
139 View Code Duplication
    protected function getInformalSalutation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
140
    {
141
        $contact = $this->application->getContact();
142
        $name    = $contact->getDisplayName();
143
        
144
        $salutation = $this->getTranslator()
145
                    ->translate('Hello %s');
146
        
147
        return sprintf($salutation, $name);
148
    }
149
150
    /**
151
     * @return mixed
152
     */
153
    protected function getJobTitle()
154
    {
155
        return $this->application->getJob()->getTitle();
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    protected function getDate()
162
    {
163
        /** @var $date \DateTime */
164
        $date = $this->application->getDateCreated();
165
        return strftime('%x', $date->getTimestamp());
166
    }
167
168
    protected function getApplicationLink()
169
    {
170
        $router = $this->router;
171
        $user   = $this->user;
172
173
        if (!$router || !$user) { return ''; }
174
175
        $token = $user instanceOf AnonymousUser ? '?token=' . $user->getToken() : '';
176
        $href  = $router->assemble(
177
                        ['id' => $this->application->getId()],
178
                        ['name'=>'lang/applications/detail', 'force_canonical'=>true]
179
        ) . $token;
180
181
        return $href;
182
183
    }
184
185
    /**
186
     * @param string $subject
187
     * @param bool $translate
188
     * @return \Zend\Mail\Message
189
     */
190
    public function setSubject($subject, $translate = true)
191
    {
192
        $subject = $this->isTranslatorEnabled() && $translate
193
                 ? $this->getTranslator()->translate($subject, $this->getTranslatorTextDomain())
194
                 : $subject;
195
        return parent::setSubject($subject);
196
    }
197
}
198