<?php
namespace Notaris\AdminBundle\Entity;
use Doctrine\ORM\EntityRepository;
/**
* HomeBannerRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class HomeBannerRepository extends EntityRepository
{
/**
* @param $locale
* @param int $offset
* @param array $sort_arr
* @param int $limit
* @return array|bool
*/
public function getAllHomeBanner($locale, $offset = 0, $sort_arr = array(), $limit = 50)
{
//start orders
$orders_arr = array();
$order_type = $sort_arr['type'];
$order_columns = array(
0 => 'hb.position',
'hb.link',
'hb.is_active',
);
if (isset($order_columns[$sort_arr['column']]) && $order_columns[$sort_arr['column']]) {
$orders_arr[] = $order_columns[$sort_arr['column']] . ' ' . $order_type;
}
//end orders
$em = $this->getEntityManager();
$con = $em->getConnection();
$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
FROM home_banner hb
WHERE hb.locale = :locale
GROUP BY hb.id
ORDER BY " . implode(', ', $orders_arr) . '
LIMIT ' . $offset . ', ' . $limit;
$stmt = $con->prepare($sql);
$stmt->bindValue('locale', $locale);
$stmt = $stmt->execute();
$result = $stmt->fetchAll();
//all count
$sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.locale = :locale";
$stmt = $con->prepare($sql);
$stmt->bindValue('locale', $locale);
$stmt = $stmt->execute();
$count = $stmt->fetchOne();
$online = $offline = $scheduled = 0;
if ($count) {
//online
$sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.is_active = 1 AND hb.locale = :locale";
$stmt = $con->prepare($sql);
$stmt->bindValue('locale', $locale);
$stmt = $stmt->execute();
$online = $stmt->fetchOne();
//offline
$sql = "SELECT count(*) as count FROM home_banner hb WHERE hb.is_active = 0 AND hb.locale = :locale";
$stmt = $con->prepare($sql);
$stmt->bindValue('locale', $locale);
$stmt = $stmt->execute();
$offline = $stmt->fetchOne();
}
return array(
'result' => $result,
'count' => $count,
'online' => $online,
'offline' => $offline
);
}
public function findActiveByLanguage($locale){
$query = $this->getEntityManager()
->createQuery(
'SELECT b FROM
NotarisAdminBundle:HomeBanner b
WHERE b.locale = :locale
AND b.isActive = 1
ORDER BY b.position ASC, b.id ASC'
)
->setParameter('locale', $locale);
$banners = $query->getResult();
if ($banners) {
return $banners;
}
return false;
}
}