|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013-2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @author cbleek |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Jobs\Controller\Plugin; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\Mvc\Controller\Plugin\AbstractPlugin; |
|
14
|
|
|
use Core\Repository\RepositoryService; |
|
15
|
|
|
use Auth\AuthenticationService; |
|
16
|
|
|
use Zend\Mvc\Controller\Plugin\Params; |
|
17
|
|
|
use Acl\Service\Acl; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class InitializeJob |
|
21
|
|
|
* |
|
22
|
|
|
* @package Jobs\Controller\Plugin |
|
23
|
|
|
*/ |
|
24
|
|
|
class InitializeJob extends AbstractPlugin { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var RepositoryService |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $repositoryService; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var AuthenticationService |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $auth; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var \Acl\Controller\Plugin\Acl |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $acl; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct(RepositoryService $repositoryService,AuthenticationService $auth, Acl $acl) { |
|
42
|
|
|
$this->repositoryService=$repositoryService; |
|
43
|
|
|
$this->auth=$auth; |
|
44
|
|
|
$this->acl=$acl; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function __invoke() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param Params $params |
|
54
|
|
|
* @param bool $allowDraft |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Jobs\Entity\Job|object |
|
57
|
|
|
* @throws \Doctrine\ODM\MongoDB\LockException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function get(Params $params,$allowDraft = false) |
|
60
|
|
|
{ |
|
61
|
|
|
/* @var \Jobs\Repository\Job $jobRepository */ |
|
62
|
|
|
$jobRepository = $this->repositoryService->get('Jobs/Job'); |
|
63
|
|
|
// @TODO three different method to obtain the job-id ?, simplify this |
|
64
|
|
|
$id_fromRoute = $params('id', 0); |
|
|
|
|
|
|
65
|
|
|
$id_fromQuery = $params->fromQuery('id', 0); |
|
|
|
|
|
|
66
|
|
|
$id_fromSubForm = $params->fromPost('job', 0); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$id = empty($id_fromRoute)? (empty($id_fromQuery)?$id_fromSubForm:$id_fromQuery) : $id_fromRoute; |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
if (empty($id) && $allowDraft) { |
|
71
|
|
|
$this->acl->__invoke('Jobs/Manage', 'new'); |
|
72
|
|
|
$user = $this->auth->getUser(); |
|
73
|
|
|
/** @var \Jobs\Entity\Job $job */ |
|
74
|
|
|
$job = $jobRepository->findDraft($user); |
|
75
|
|
|
if (empty($job)) { |
|
76
|
|
|
$job = $jobRepository->create(); |
|
77
|
|
|
$job->setIsDraft(true); |
|
78
|
|
|
$job->setUser($user); |
|
79
|
|
|
$this->repositoryService->store($job); |
|
80
|
|
|
} |
|
81
|
|
|
return $job; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$job = $jobRepository->find($id); |
|
85
|
|
|
if (!$job) { |
|
86
|
|
|
throw new \RuntimeException('No job found with id "' . $id . '"'); |
|
87
|
|
|
} |
|
88
|
|
|
return $job; |
|
89
|
|
|
} |
|
90
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..