<?php

namespace OfficeBrain\Bundle\ServiceGroupBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * ServiceRuleChargesEquationRepository.
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ServiceRuleChargesEquationRepository 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.
     *
     * @param object $serviceRuleChargesEquationObj
     *
     * @return \OfficeBrain\Bundle\ServiceGroupBundle\Entity\ServiceRuleMappingMaster
     */
    public function addServiceRuleChargesEquation($serviceRuleChargesEquation, $serviceRuleMappingMasterObj)
    {
        $serviceRuleChargesEquation->setServiceRuleMappingId($serviceRuleMappingMasterObj);

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

        return $serviceRuleChargesEquation;
    }


    /**
     * To remove ServiceRuleMappingGroup.
     *
     * @param object $serviceRuleMappingMasterObj
     *
     * @return
     */
    public function removeServiceRuleChargesEquation($serviceRuleMappingMasterObj)
    {
        $query = $this->createQueryBuilder('srmg')
        ->delete('OfficeBrainServiceGroupBundle:ServiceRuleMappingGroup', 'srmg')
        ->where('srmg.serviceRuleMappingId =:serviceRuleMappingId')
        ->setParameter('serviceRuleMappingId', $serviceRuleMappingMasterObj);
        $result = $query->getQuery()->execute();

        return $result;
    }

    public function commit()
    {
        $em = $this->getEntityManager();
        $em->flush();
    }

    public function clear()
    {
        $em = $this->getEntityManager();
        $em->clear();
    }
}
