fix lists in readme
[mixstore.git] / src / Mixstore / StoreBundle / Entity / PackageRepository.php
... / ...
CommitLineData
1<?php
2
3namespace Mixstore\StoreBundle\Entity;
4
5use Doctrine\ORM\EntityRepository;
6
7class PackageRepository extends EntityRepository
8{
9 function safeFindById($id)
10 {
11 if ($id > 0)
12 {
13 $qb = $this->createQueryBuilder('p');
14 $qb->where('p.id = '.$id);
15 $package = $qb->getQuery()->getResult()[0];
16 }
17 else
18 $package = new Package();
19
20 return $package;
21 }
22
23 function getAllNames()
24 {
25 return $this
26 ->createQueryBuilder('p')
27 ->select('p.id, p.name')
28 ->getQuery()
29 ->getResult();
30 }
31
32 function getBannersUrls()
33 {
34 $bannersUrls = $this
35 ->createQueryBuilder('p')
36 ->select('p.id, p.bannerpath')
37 ->where('p.bannerpath IS NOT NULL')
38 ->getQuery()
39 ->getResult();
40 $result = array();
41 for ($i=0; $i<count($bannersUrls); $i++)
42 $result[$bannersUrls[$i]['id']] = $bannersUrls[$i]['bannerpath'];
43 return $result;
44 }
45
46 function getLastNews()
47 {
48 return $this
49 ->createQueryBuilder('p')
50 ->select('p.id, p.name, p.created')
51 ->orderBy('p.created', 'DESC')
52 ->setMaxResults(3) //currently hard-coded
53 ->getQuery()
54 ->getResult();
55 }
56}