src/Repository/BlogRepository.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Blog;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Blog|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Blog|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Blog[]    findAll()
  10.  * @method Blog[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class BlogRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryBlog::class);
  17.     }
  18.    public function listBlog($desde$hasta$categoria$total=false$client_id) {
  19.        
  20.        $conn $this->getEntityManager()->getConnection();
  21.        $query "  SELECT     b.blog_id as blogId,
  22.                    b.title,
  23.                    b.cover_path as coverPath,
  24.                    b.content,
  25.                    DATE_FORMAT(b.created_at, '%M %d, %Y') as createdAt,
  26.                    bc.name,
  27.                    b.short_content as shortContent,
  28.                    bc.name AS categoryName
  29.                    FROM blog b
  30.                    LEFT JOIN blog_category bc ON bc.blog_category_id = b.blog_category_id
  31.                    WHERE b.is_published = 1 and b.is_active = 1 AND b.client_id = '$client_id
  32.        ";
  33.        
  34.        if($categoria != 'all'){
  35.            $query$query.=" AND b.blog_category_id = '$categoria'";
  36.        } 
  37.        if($total == false){
  38.            $query $query.="LIMIT $desde$hasta";
  39.        }
  40.        
  41.        return $conn->fetchAllAssociative($query);
  42.        /*$res = $this->getEntityManager()->getConnection()->prepare($query);
  43.        $res->execute();
  44.    
  45.        return $res->fetchAll();*/
  46.    }
  47.    public function getCategoriesBlog($slug) {
  48.        $conn $this->getEntityManager()->getConnection();
  49.        $query " SELECT 
  50.                     bc.*, 
  51.                     (SELECT COUNT(*) FROM blog WHERE blog.blog_category_id = bc.blog_category_id AND blog.is_active = 1 AND blog.is_published = 1) AS count_blogs 
  52.                         FROM blog_category bc, client c 
  53.                             WHERE bc.is_active = 1 
  54.                                 AND c.client_id = bc.client_id
  55.                                 AND c.slug = '$slug'
  56.                                     HAVING count_blogs > 0
  57.        ";
  58.        
  59.        return $conn->fetchAllAssociative($query);
  60.        /*$res = $this->getEntityManager()->getConnection()->prepare($query);
  61.        $res->execute();
  62.    
  63.        return $res->fetchAll();*/
  64.    }
  65.    
  66.    public function getBlogsGrouped() {
  67.         $conn $this->getEntityManager()->getConnection();
  68.        $query "    SELECT 
  69.                        count(blog_id) as count,
  70.                        month(created_at) as month_number, 
  71.                        year(created_at) as year 
  72.                            FROM blog 
  73.                                WHERE is_active = 1 and is_published = 1
  74.                                    GROUP BY  month(created_at), year(created_at) ";
  75.        return $conn->fetchAllAssociative($query);
  76.        /*
  77.        $res = $this->getEntityManager()->getConnection()->prepare($query);
  78.        $res->execute();
  79.    
  80.        return $res->fetchAll();*/
  81.    }
  82. }