1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @filesource |
6
|
|
|
* @copyright (c) 2013-2016 Cross Solution (http://cross-solution.de) |
7
|
|
|
* @author Carsten Bleek <[email protected]> |
8
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jobs\Controller\Plugin; |
13
|
|
|
|
14
|
|
|
use Jobs\Entity\StatusInterface; |
15
|
|
|
use Laminas\Mvc\Controller\Plugin\AbstractPlugin; |
16
|
|
|
use Core\Repository\RepositoryService; |
17
|
|
|
use Auth\AuthenticationService; |
18
|
|
|
use Laminas\Mvc\Controller\Plugin\Params; |
19
|
|
|
use Acl\Controller\Plugin\Acl; |
20
|
|
|
use Core\Entity\Exception\NotFoundException; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class InitializeJob |
24
|
|
|
* |
25
|
|
|
* @package Jobs\Controller\Plugin |
26
|
|
|
*/ |
27
|
|
|
class InitializeJob extends AbstractPlugin |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var RepositoryService |
32
|
|
|
*/ |
33
|
|
|
protected $repositoryService; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var AuthenticationService |
37
|
|
|
*/ |
38
|
|
|
protected $auth; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Acl\Controller\Plugin\Acl |
42
|
|
|
*/ |
43
|
|
|
protected $acl; |
44
|
|
|
|
45
|
|
|
public function __construct(RepositoryService $repositoryService, AuthenticationService $auth, Acl $acl) |
46
|
|
|
{ |
47
|
|
|
$this->repositoryService=$repositoryService; |
48
|
|
|
$this->auth=$auth; |
49
|
|
|
$this->acl=$acl; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __invoke() |
53
|
|
|
{ |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Params $params |
59
|
|
|
* @param bool $allowDraft |
60
|
|
|
* |
61
|
|
|
* @return \Jobs\Entity\Job|object |
62
|
|
|
* @throws \Doctrine\ODM\MongoDB\LockException |
63
|
|
|
* @throws NotFoundException |
64
|
|
|
*/ |
65
|
|
|
public function get(Params $params, $allowDraft = false, $getSnapshot = false) |
66
|
|
|
{ |
67
|
|
|
/* @var \Jobs\Repository\Job $jobRepository */ |
68
|
|
|
$jobRepository = $this->repositoryService->get('Jobs/Job'); |
69
|
|
|
$idFromRoute = $params('id', 0); |
70
|
|
|
$idFromQuery = $params->fromQuery('id', 0); |
71
|
|
|
$idFromSubForm = $params->fromPost('job', 0); |
72
|
|
|
|
73
|
|
|
$id = empty($idFromRoute)? (empty($idFromQuery)?$idFromSubForm:$idFromQuery) : $idFromRoute; |
74
|
|
|
$snapshotId = $params->fromPost('snapshot') ?: ($params->fromQuery('snapshot') ?: null); |
75
|
|
|
|
76
|
|
|
if (empty($id) && empty($snapshotId) && $allowDraft) { |
77
|
|
|
$this->acl->__invoke('Jobs/Manage', 'new'); |
78
|
|
|
$user = $this->auth->getUser(); |
79
|
|
|
/** @var \Jobs\Entity\Job $job */ |
80
|
|
|
$job = $jobRepository->findDraft($user); |
81
|
|
|
if (empty($job)) { |
82
|
|
|
$job = $jobRepository->create(); |
83
|
|
|
$job->setIsDraft(true); |
84
|
|
|
$job->setUser($user); |
85
|
|
|
$this->repositoryService->store($job); |
86
|
|
|
} |
87
|
|
|
return $job; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if ($snapshotId) { |
91
|
|
|
$snapshotRepo = $this->repositoryService->get('Jobs/JobSnapshot'); |
92
|
|
|
$job = $snapshotRepo->find($snapshotId); |
93
|
|
|
} else { |
94
|
|
|
/* @var \Jobs\Entity\Job $job */ |
95
|
|
|
$job = $jobRepository->find($id); |
96
|
|
|
if ($job && $getSnapshot && !$job->isDraft() && $job->getStatus()->getName() != \Jobs\Entity\StatusInterface::CREATED) { |
|
|
|
|
97
|
|
|
$snapshotRepo = $this->repositoryService->get('Jobs/JobSnapshot'); |
98
|
|
|
$snapshot = $snapshotRepo->findLatest($job->getId(), /*isDraft*/ true); |
|
|
|
|
99
|
|
|
|
100
|
|
|
$job = $snapshot ?: $snapshotRepo->create($job, true); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if (!$job || $job->isDeleted()) { |
105
|
|
|
throw new NotFoundException($id); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $job; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.