<?php

namespace OfficeBrain\Bundle\RewardReferralBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * RewardRedeemHistoryRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class RewardRedeemHistoryRepository extends EntityRepository
{
    protected $projectSetting;
    protected $instanceId;
    protected $instanceType;
    protected $cultureId;
    protected $cultureCode;
    protected $paginatorService;
    protected $projectSettingService;

    public function getPaginatorService()
    {
        return $this->paginatorService;
    }

    public function setPaginatorService($paginatorService)
    {
        $this->paginatorService = $paginatorService;
    }

    public function getProjectSetting()
    {
        return $this->paginatorService;
    }

    public function setProjectSetting($projectSetting)
    {
        $this->projectSetting = $projectSetting;
        $this->prepareProjectSettingData();
    }

    public function prepareProjectSettingData()
    {
        $this->userId = $this->projectSetting['user_id'];
        $this->createdUid = $this->upatedUid = $this->userId;
        $this->instanceId = $this->projectSetting['instance_id'];
        $this->instanceType = $this->projectSetting['instance_type'];
        $this->cultureId = $this->projectSetting['culture_id'];
        $this->cultureCode = $this->projectSetting['culture_code'];
    }
    
    /**
     * @Author Employee Id: 4589
     * Description : Function created for define a common querybuilder object
     *
     * @return object
     */
    public function getQueryBuilder()
    {
        return $this->getEntityManager()->getRepository('OfficeBrainRewardReferralBundle:RewardRedeemHistory')->createQueryBuilder('rrh');
    }
    
    /**
     * @Author Employee Id: 4589
     * Description : Function created for get redeem history by user
     *
     * @param 1 : $userId
     *
     * @return object
     */
    public function getRedeemHisotry($userId)
    {
        $qb = $this->getQueryBuilder();
        $qb->where('rrh.userId = :userId')
                ->setParameter('userId', $userId);
        $qb->orderBy('rrh.createdAt', 'DESC');
        $result = $qb->getQuery()->getResult();
        
        return $result;
    }
}
