<?php

namespace OfficeBrain\Bundle\CmsBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * SitemapRouteMasterRepository.
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class SitemapRouteMasterRepository extends EntityRepository
{
    protected $projectSetting;
    protected $instanceAccessRoutes;

    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to set project settings
     *
     * @param 1: $projectSetting
     *
     * @return: NULL
     *
     * @throws Exception: Null
     */
    public function setProjectSetting($projetSetting)
    {
        $this->projectSetting = $projetSetting;
        $this->prepareProjectSettingData();
    }

    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to get project settings
     *
     * @param : None
     *
     * @return: project setting array
     *
     * @throws Exception: Null
     */
    public function getProjectSetting()
    {
        return $this->projetSetting;
    }

    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to set member variables default value
     *
     * @param : None
     *
     * @return: NULL
     *
     * @throws Exception: Null
     */
    public function prepareProjectSettingData()
    {
        $this->instanceAccessRoutes = $this->projectSetting['instance_access_routes'];
    }

    /**
     * @author Employee Id: 4464
     *
     * Description : Find public routes instance wise
     *
     * @param null
     *
     * @return : array of sitemap routes master Object
     *
     * @throws Exception: Null
     */
    public function getRoutes()
    {
        $queryBuilder = $this->createQueryBuilder('sm');
        if (!empty($this->instanceAccessRoutes)) {
            $queryBuilder->select('sm')->where($queryBuilder->expr()->in('sm.path', $this->instanceAccessRoutes));
            $routes = $queryBuilder->getQuery()->getResult();
        }
        if (empty($routes)) {
            $routes = null;
        }

        return $routes;
    }
}
