<?php

namespace OfficeBrain\Bundle\RequestInfoBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * RequestInfoRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class CommentRequestInfoRepository extends EntityRepository
{
	public function setRequestComment($data,$config)
	{
		$em=$this->getEntityManager();
		$requestInfoObj=$this->getRequestInfoById($data->requestInfoId,$em);
		$commentRequestInfo=new CommentRequestinfo();
		$commentRequestInfo->setRequestId($requestInfoObj);
		$commentRequestInfo->setSendBy($data->getSendBy());
		$commentRequestInfo->setComment($data->getComment());
		$commentRequestInfo->setCreatedUid($config['user_id']);
		$commentRequestInfo->setUpatedUid($config['user_id']);
		$commentRequestInfo->setInstanceId($config['instance_id']);
		$commentRequestInfo->setInstanceType($config['instance_type']);
		$em->persist($commentRequestInfo);
		$em->flush();
		
		return array("status"=>"COMMENT_ADDED_SUCESSFULLY","requestinfoObj"=>$requestInfoObj);
		
	}
	
	public function getRequestInfoById($requestInfoId){
		$query = $this->getEntityManager()->getRepository('OfficeBrainRequestInfoBundle:RequestInfo')->createQueryBuilder('r');
		$query->where('r.id = :infoId')
		->setParameter('infoId', $requestInfoId);
		return $result= $query->getQuery()->getSingleResult();
	}
	
	public function getCommentRequestInfoDetailById($requestInfoId){
		$query = $this->getEntityManager()->getRepository('OfficeBrainRequestInfoBundle:CommentRequestInfo')->createQueryBuilder('r');
		$query->select('r')
				->where('r.requestId = :requestId')
			 	->setParameter('requestId', $requestInfoId)
				->orderBy('r.id', 'ASC');
		return $result= $query->getQuery()->getResult();	
	}
	
	
}
