Commit | Line | Data |
---|---|---|
929ca066 BA |
1 | <?php |
2 | ||
3 | namespace Mixstore\StoreBundle\Entity; | |
4 | ||
5 | use Doctrine\ORM\EntityRepository; | |
6 | ||
7 | class UsecaseRepository extends EntityRepository | |
8 | { | |
9 | function safeFindById($id) | |
10 | { | |
11 | if ($id > 0) | |
12 | { | |
13 | $qb = $this->createQueryBuilder('u'); | |
14 | $qb->where('u.id = '.$id); | |
15 | $usecase = $qb->getQuery()->getResult()[0]; | |
16 | } | |
17 | else | |
18 | $usecase = new Usecase(); | |
19 | ||
20 | return $usecase; | |
21 | } | |
22 | ||
23 | function countByPkgId($pkgid) | |
24 | { | |
25 | return $this | |
26 | ->createQueryBuilder('u') | |
27 | ->select('COUNT(u.id) AS ucscount, AVG(u.grade) AS rating') | |
28 | ->where('u.package = '.$pkgid) | |
29 | ->getQuery() | |
30 | ->getResult()[0]; | |
31 | //->getSingleScalarResult(); | |
32 | } | |
33 | } |