7
7
8
8
namespace Monarc \FrontOffice \Model \Table ;
9
9
10
- use Doctrine \ORM \EntityNotFoundException ;
11
10
use Monarc \Core \Model \Entity \ThreatSuperClass ;
12
11
use Monarc \Core \Model \Table \AbstractEntityTable ;
13
12
use Monarc \Core \Service \ConnectedUserService ;
@@ -36,11 +35,13 @@ public function started($anrId)
36
35
$ res = $ qb ->select ('COUNT(t.uuid) ' )
37
36
->where ('t.anr = :anrid ' )
38
37
->setParameter (':anrid ' , $ anrId )
39
- ->andWhere ('t.qualification != -1 ' )->getQuery ()->getSingleScalarResult ();
38
+ ->andWhere ('t.qualification != -1 ' )
39
+ ->getQuery ()
40
+ ->getSingleScalarResult ();
41
+
40
42
return $ res > 0 ;
41
43
}
42
44
43
-
44
45
/**
45
46
* @return Threat[]
46
47
*/
@@ -54,22 +55,9 @@ public function findByAnr(Anr $anr)
54
55
->getResult ();
55
56
}
56
57
57
- public function findUuidsAndCodesByAnr (Anr $ anr ): array
58
+ public function findByAnrAndUuid (Anr $ anr, string $ uuid ): ? Threat
58
59
{
59
- return $ this ->getRepository ()->createQueryBuilder ('t ' )
60
- ->select ('t.uuid, t.code ' )
61
- ->where ('t.anr = :anr ' )
62
- ->setParameter ('anr ' , $ anr )
63
- ->getQuery ()
64
- ->getScalarResult ();
65
- }
66
-
67
- /**
68
- * @throws EntityNotFoundException
69
- */
70
- public function findByAnrAndUuid (Anr $ anr , string $ uuid ): ThreatSuperClass
71
- {
72
- $ threat = $ this ->getRepository ()
60
+ return $ this ->getRepository ()
73
61
->createQueryBuilder ('t ' )
74
62
->where ('t.anr = :anr ' )
75
63
->andWhere ('t.uuid = :uuid ' )
@@ -78,31 +66,18 @@ public function findByAnrAndUuid(Anr $anr, string $uuid): ThreatSuperClass
78
66
->setMaxResults (1 )
79
67
->getQuery ()
80
68
->getOneOrNullResult ();
81
-
82
- if ($ threat === null ) {
83
- throw new EntityNotFoundException (
84
- sprintf ('Threat with anr ID "%d" and uuid "%s" has not been found. ' , $ anr ->getId (), $ uuid )
85
- );
86
- }
87
-
88
- return $ threat ;
89
69
}
90
70
91
- /**
92
- * @param Anr $anr
93
- * @param string[] $uuids
94
- *
95
- * @return array
96
- */
97
- public function findByAnrAndUuidsIndexedByField (Anr $ anr , array $ uuids , string $ indexField = 'uuid ' ): array
71
+ public function existsWithAnrAndCode (Anr $ anr , string $ code ): bool
98
72
{
99
- $ queryBuilder = $ this ->getRepository ()->createQueryBuilder ('t ' , 't. ' . $ indexField );
100
-
101
- return $ queryBuilder ->where ('t.anr = :anr ' )
102
- ->andWhere ($ queryBuilder ->expr ()->in ('t.uuid ' , $ uuids ))
103
- ->setParameter (':anr ' , $ anr )
73
+ return $ this ->getRepository ()->createQueryBuilder ('t ' )
74
+ ->where ('t.anr = :anr ' )
75
+ ->andWhere ('t.uuid = :code ' )
76
+ ->setParameter ('anr ' , $ anr )
77
+ ->setParameter ('code ' , $ code )
78
+ ->setMaxResults (1 )
104
79
->getQuery ()
105
- ->getResult () ;
80
+ ->getOneOrNullResult () !== null ;
106
81
}
107
82
108
83
public function saveEntity (ThreatSuperClass $ threat , bool $ flushAll = true ): void
0 commit comments