|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
|
6
|
|
|
|
|
7
|
|
|
class AgreementRepository extends EntityRepository |
|
8
|
|
|
{ |
|
9
|
|
|
public function countHours(Agreement $agreement) |
|
10
|
|
|
{ |
|
11
|
|
|
return $this->getEntityManager() |
|
12
|
|
|
->createQuery('SELECT SUM(w.hours) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement') |
|
13
|
|
|
->setParameter('agreement', $agreement) |
|
14
|
|
|
->getSingleScalarResult(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
public function getRealFromDate(Agreement $agreement) |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
$date = $this->getEntityManager() |
|
20
|
|
|
->createQuery('SELECT MIN(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement') |
|
21
|
|
|
->setParameter('agreement', $agreement) |
|
22
|
|
|
->getSingleScalarResult(); |
|
23
|
|
|
|
|
24
|
|
|
return null === $date ?: new \DateTime($date); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
View Code Duplication |
public function getRealToDate(Agreement $agreement) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$date = $this->getEntityManager() |
|
30
|
|
|
->createQuery('SELECT MAX(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement') |
|
31
|
|
|
->setParameter('agreement', $agreement) |
|
32
|
|
|
->getSingleScalarResult(); |
|
33
|
|
|
|
|
34
|
|
|
return null === $date ?: new \DateTime($date); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getActivitiesStats(Agreement $agreement) |
|
38
|
|
|
{ |
|
39
|
|
|
$activities = $agreement->getActivities(); |
|
40
|
|
|
|
|
41
|
|
|
$result = $this->getEntityManager() |
|
42
|
|
|
->createQuery('SELECT a, SUM(t.hours), COUNT(a) FROM AppBundle:Activity a INNER JOIN AppBundle:Tracking t WITH t.activity = a.id INNER JOIN t.workday w WHERE w.agreement = :agreement AND a.id IN (:activities) GROUP BY a.id') |
|
43
|
|
|
->setParameter('agreement', $agreement) |
|
44
|
|
|
->setParameter('activities', $activities) |
|
45
|
|
|
->getResult(); |
|
46
|
|
|
|
|
47
|
|
|
return $result; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function delete(Agreement $agreement) |
|
51
|
|
|
{ |
|
52
|
|
|
// borrar informe si estaba cumplimentado |
|
53
|
|
|
if ($agreement->getReport()) { |
|
54
|
|
|
$this->getEntityManager()->remove($agreement->getReport()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// borrar calendario |
|
58
|
|
|
foreach ($agreement->getWorkdays() as $workday) { |
|
59
|
|
|
$this->getEntityManager()->remove($workday); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// borrar actividades de plan de formación individualizado |
|
63
|
|
|
$agreement->getActivities()->clear(); |
|
64
|
|
|
|
|
65
|
|
|
// borrar acuerdo |
|
66
|
|
|
$this->getEntityManager()->remove($agreement); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
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.