|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cv\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use Core\Repository\AbstractRepository; |
|
6
|
|
|
use Auth\Entity\UserInterface; |
|
7
|
|
|
use Applications\Entity\Application; |
|
8
|
|
|
use Cv\Entity\Cv as CvEntity; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* class for accessing CVs |
|
12
|
|
|
* |
|
13
|
|
|
* @method CvEntity create(array $data = null, $persist = false) |
|
14
|
|
|
*/ |
|
15
|
|
|
class Cv extends AbstractRepository |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Look for an drafted Document of a given user |
|
19
|
|
|
* |
|
20
|
|
|
* @param $user |
|
21
|
|
|
* @return CvEntity|null |
|
|
|
|
|
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
public function findDraft($user) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
if ($user instanceof UserInterface) { |
|
26
|
|
|
$user = $user->getId(); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$document = $this->findOneBy( |
|
30
|
|
|
array( |
|
31
|
|
|
'isDraft' => true, |
|
32
|
|
|
'user' => $user |
|
33
|
|
|
) |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
if (!empty($document)) { |
|
37
|
|
|
return $document; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return null; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Application $application |
|
45
|
|
|
* @param UserInterface $user |
|
46
|
|
|
* @return CvEntity |
|
47
|
|
|
* @since 0.26 |
|
48
|
|
|
*/ |
|
49
|
|
|
public function createFromApplication(Application $application, UserInterface $user) |
|
50
|
|
|
{ |
|
51
|
|
|
$cv = $this->create(); |
|
52
|
|
|
$contact = $application->getContact(); |
|
53
|
|
|
$contactImage = $contact->getImage(); |
|
54
|
|
|
|
|
55
|
|
|
if ($contactImage) |
|
56
|
|
|
{ |
|
57
|
|
|
$contactImage->setUser($user); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$cv->setContact($contact); |
|
61
|
|
|
|
|
62
|
|
|
$applicationAttachments = $application->getAttachments(); |
|
63
|
|
|
|
|
64
|
|
|
if (count($applicationAttachments) > 0) |
|
65
|
|
|
{ |
|
66
|
|
|
$cvAttachments = []; |
|
67
|
|
|
|
|
68
|
|
|
/* @var $applicationAttachment \Applications\Entity\Attachment */ |
|
69
|
|
|
foreach ($applicationAttachments as $applicationAttachment) |
|
70
|
|
|
{ |
|
71
|
|
|
$file = new \Doctrine\MongoDB\GridFSFile(); |
|
72
|
|
|
$file->setBytes($applicationAttachment->getContent()); |
|
73
|
|
|
|
|
74
|
|
|
$cvAttachment = new \Cv\Entity\Attachment(); |
|
75
|
|
|
$cvAttachment->setName($applicationAttachment->getName()); |
|
76
|
|
|
$cvAttachment->setType($applicationAttachment->getType()); |
|
77
|
|
|
$cvAttachment->setPermissions($cvAttachment->getPermissions()); |
|
78
|
|
|
$cvAttachment->setUser($user); |
|
79
|
|
|
$cvAttachment->setFile($file); |
|
80
|
|
|
$cvAttachment->setDateUploaded($applicationAttachment->getDateUploaded()); |
|
81
|
|
|
|
|
82
|
|
|
$cvAttachments[] = $cvAttachment; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$cv->setAttachments(new \Doctrine\Common\Collections\ArrayCollection($cvAttachments)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $cv; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.