<?php

namespace OfficeBrain\Bundle\ServiceGroupBundle\Entity;

use Doctrine\ORM\EntityRepository;

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

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

        return $this;
    }

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

    public function prepareProjectSettingData()
    {
        $this->instanceId = $this->projectSetting['instance_id'];
        $this->instanceType = $this->projectSetting['instance_type'];
        $this->userId = $this->projectSetting['user_id'];
        $this->cultureId = $this->projectSetting['culture_id'];
        $this->cultureCode = $this->projectSetting['culture_code'];
    }

    /**
     * To add Rule Mapping Column Qty.
     *
     * @param object $serviceRuleMappingColumnQty
     *
     * @return \OfficeBrain\Bundle\ServiceGroupBundle\Entity\ServiceRuleMappingColumnQtyRepository
     */
    public function addServiceRuleMappingColumnQty($serviceRuleMappingColumnQty)
    {
        $serviceRuleMappingColumnQty->setCreatedUid($this->userId);
        $serviceRuleMappingColumnQty->setUpdatedUid($this->userId);
        $serviceRuleMappingColumnQty->setInstanceId($this->instanceId);
        $serviceRuleMappingColumnQty->setInstanceType($this->instanceType);

        $this->_em->persist($serviceRuleMappingColumnQty);
        $this->_em->flush();

        return $serviceRuleMappingColumnQty;
    }
    
    public function findByServiceRuleMappingId($serviceRuleMappingMasterObj)
    {
        $query = $this->createQueryBuilder('srmcq')->select('srmcq')
                ->where('srmcq.serviceRuleMappingId =:serviceRuleMappingId')
                ->setParameter('serviceRuleMappingId', $serviceRuleMappingMasterObj);
        $result = $query->getQuery()->getResult();

        return $result;
    }
    
    public function removeColumnQty($serviceRuleMappingMasterObj)
    {
        $query = $this->createQueryBuilder('srmcq')
                ->delete('OfficeBrainServiceGroupBundle:ServiceRuleMappingColumnQty', 'srmcq')
                ->where('srmcq.serviceRuleMappingId =:serviceRuleMappingId')
                ->setParameter('serviceRuleMappingId', $serviceRuleMappingMasterObj);
        $result = $query->getQuery()->execute();

        return $result;
    }
}
