src/Notaris/AdminBundle/Entity/HomeBannerRepository.php line 99

Open in your IDE?
  1. <?php
  2. namespace Notaris\AdminBundle\Entity;
  3. use Doctrine\ORM\EntityRepository;
  4. /**
  5.  * HomeBannerRepository
  6.  *
  7.  * This class was generated by the Doctrine ORM. Add your own custom
  8.  * repository methods below.
  9.  */
  10. class HomeBannerRepository extends EntityRepository
  11. {
  12.     /**
  13.      * @param $locale
  14.      * @param int $offset
  15.      * @param array $sort_arr
  16.      * @param int $limit
  17.      * @return array|bool
  18.      */
  19.     public function getAllHomeBanner($locale, $offset = 0, $sort_arr = array(), $limit = 50)
  20.     {
  21.         //start orders
  22.         $orders_arr = array();
  23.         $order_type = $sort_arr['type'];
  24.         $order_columns = array(
  25.             0 => 'hb.position',
  26.             'hb.link',
  27.             'hb.is_active',
  28.         );
  29.         if (isset($order_columns[$sort_arr['column']]) && $order_columns[$sort_arr['column']]) {
  30.             $orders_arr[] = $order_columns[$sort_arr['column']] . ' ' . $order_type;
  31.         }
  32.         //end orders
  33.         $em = $this->getEntityManager();
  34.         $con = $em->getConnection();
  35.  
  36.         $sql = "SELECT hb.id, hb.user_id, hb.asset_id, hb.created, hb.updated, hb.position, hb.headline1, hb.headline2, hb.subline, hb.youtube, hb.is_active, hb.locale, hb.link
  37.                   FROM home_banner hb
  38.                   WHERE hb.locale = :locale
  39.                   GROUP BY hb.id
  40.                   ORDER BY " . implode(', ', $orders_arr) . '
  41.                   LIMIT ' . $offset . ', ' . $limit;
  42.         $stmt = $con->prepare($sql);
  43.         $stmt->bindValue('locale', $locale);
  44.         $stmt = $stmt->execute();
  45.         $result = $stmt->fetchAll();
  46.         //all count
  47.         $sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.locale = :locale";
  48.         $stmt = $con->prepare($sql);
  49.         $stmt->bindValue('locale', $locale);
  50.         $stmt = $stmt->execute();
  51.         $count = $stmt->fetchOne();
  52.         $online = $offline = $scheduled = 0;
  53.         if ($count) {
  54.             //online
  55.             $sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.is_active = 1 AND hb.locale = :locale";
  56.             $stmt = $con->prepare($sql);
  57.             $stmt->bindValue('locale', $locale);
  58.             $stmt = $stmt->execute();
  59.             $online = $stmt->fetchOne();
  60.             //offline
  61.             $sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.is_active = 0 AND hb.locale = :locale";
  62.             $stmt = $con->prepare($sql);
  63.             $stmt->bindValue('locale', $locale);
  64.             $stmt = $stmt->execute();
  65.             $offline = $stmt->fetchOne();
  66.         }
  67.         return array(
  68.             'result' => $result,
  69.             'count' => $count,
  70.             'online' => $online,
  71.             'offline' => $offline
  72.         );
  73.     }
  74.     public function findActiveByLanguage($locale){
  75.         $query = $this->getEntityManager()
  76.             ->createQuery(
  77.                 'SELECT b FROM
  78.                     NotarisAdminBundle:HomeBanner b
  79.                     WHERE b.locale = :locale
  80.                     AND b.isActive = 1
  81.                     ORDER BY b.position ASC, b.id ASC'
  82.             )
  83.             ->setParameter('locale', $locale);
  84.         $banners = $query->getResult();
  85.         if ($banners) {
  86.             return $banners;
  87.         }
  88.         return false;
  89.     }
  90. }