<?php

namespace OfficeBrain\CustomBundle\CmsBundle\Entity;

use  OfficeBrain\Bundle\CmsBundle\Entity\CmsMediaLibraryRepository as BasCmsMediaLibraryRepository;

/**
 * CmsMediaLibraryRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class CmsMediaLibraryRepository extends BasCmsMediaLibraryRepository
{
	
    /**
     * @author Employee Id: 5412
     *
     * Description : Find single  based on ID
     *
     * @param $id
     *
     * @return : Feedback Master Object
     *
     * @throws Exception: Null
     */
    public function findMediaById($id)
    {
    	//$this->instanceId = 1;
 	  return $this->createQueryBuilder('ml')
        ->select('ml')
      //  ->where('ml.instanceId = :instanceId')       
        ->Where('ml.createdUid = :id')
        ->andWhere('ml.deletedAt IS NULL')
        ->setParameter(':id', $id)
       // ->setParameter(':instanceId', $this->instanceId)
       	->orderBy('ml.id', 'DESC')
        ->getQuery()
     	->getResult();
    }

    /**
     * @author Employee Id: 5412
     *
     * Description : Count media  based on user id 
     * 
     * @param $id
     *
     * @return : Feedback Master Object
     *
     * @throws Exception: Null
     */
    public function CountMedia($id){
		return $this->createQueryBuilder('ml')
	        ->select('COUNT(ml)')
	        ->where('ml.createdUid = :id')
	        ->andWhere(' ml.deletedAt IS NULL ')
	        ->setParameter(':id', $id)
	        ->getQuery()
		    ->getSingleScalarResult();
    }
    

}
