<?php

namespace EssentialTv\EtvBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * RegisterRepository
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class QuotesRepository extends EntityRepository {

    /**
     * Get Reaction & Response against that reaction
     *
     * @return \EssentialTv\EtvBundle\Entity\Quotes 
     */
    public function getAllQuotes(){
        $query = $this->getEntityManager()
                ->createQueryBuilder()
                ->select("Q.quoteCharacterId, Q.quoteEpisodeId")
                ->from('EssentialTvEtvBundle:Quotes', 'Q')
                ->orderBy('Q.quoteCreatedOn', 'DESC');


        $strQuery = $query->getQuery();

        return $strQuery->execute();
    }
    
    public function getEpisodeQuotesWthUser($episodeID = 0) {
        $query = $this->getEntityManager()
                ->createQueryBuilder()
                ->select("Q.quoteText,Q.quoteId")
                ->addSelect("U.userFirstName")
                ->addSelect("C.characterTitle")
                ->addSelect("C.characterOriginalDataSupersede")
                ->addSelect("C.characterApiImages")
                ->addSelect("C.characterBannerImage")
//                ->addSelect("u.userFirstName")
                ->from('EssentialTvEtvBundle:Quotes', 'Q')
                ->leftJoin("EssentialTvEtvBundle:Users", "U", "WITH", "U.userId=Q.quoteUserId")
                ->leftJoin("EssentialTvEtvBundle:Characters", "C", "WITH", "C.characterId=Q.quoteCharacterId")
                ->where('Q.quoteEpisodeId = :episodeId')
                ->setParameter('episodeId', $episodeID)
                ->orderBy('Q.quoteCreatedOn', 'DESC');


        $strQuery = $query->getQuery();

        return $strQuery->execute();
    }
    public function getQuotesByCharacterOrdrDesc($characterID = 0) {
        $query = $this->getEntityManager()
                ->createQueryBuilder()
                ->select("Q")
                ->addSelect("U.userFirstName")
                ->addSelect("C.characterTitle")
                ->addSelect("C.characterOriginalDataSupersede")
                ->addSelect("C.characterApiImages")
                ->addSelect("C.characterBannerImage")
//                ->addSelect("u.userFirstName")
                ->from('EssentialTvEtvBundle:Quotes', 'Q')
                ->leftJoin("EssentialTvEtvBundle:Users", "U", "WITH", "U.userId=Q.quoteUserId")
                ->leftJoin("EssentialTvEtvBundle:Characters", "C", "WITH", "C.characterId=Q.quoteCharacterId")
                ->where('Q.quoteCharacterId = :characterID')
                ->andWhere("Q.quoteStatus = 'active'")
                ->setParameter('characterID', $characterID)
                ->orderBy('Q.quoteCreatedOn', 'DESC');


        $strQuery = $query->getQuery();

        return $strQuery->execute();
    }
    
    
    public function getQuotesChar($characterId){
        $query = $this->getEntityManager()
                ->createQueryBuilder()
                ->select("Q.quoteText,Q.quoteId")
                ->addSelect("U.userFirstName")
                ->addSelect("C.characterTitle")
                ->addSelect("C.characterOriginalDataSupersede")
                ->addSelect("C.characterApiImages")
                ->addSelect("C.characterBannerImage")
//                ->addSelect("u.userFirstName")
                ->from('EssentialTvEtvBundle:Quotes', 'Q')
                ->leftJoin("EssentialTvEtvBundle:Users", "U", "WITH", "U.userId=Q.quoteUserId")
                ->leftJoin("EssentialTvEtvBundle:Characters", "C", "WITH", "C.characterId=Q.quoteCharacterId")
                ->where('Q.quoteCharacterId = :characterId')
                ->setParameter('characterId', $characterId)
                ->orderBy('Q.quoteCreatedOn', 'DESC');


        $strQuery = $query->getQuery();

        return $strQuery->execute();
    }

}
