<?php

namespace OfficeBrain\Bundle\SearchBundle\Manager\AbstractManager;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;

abstract class BrowseCategoryAbstract
{
    protected $entityManager;
    protected $request;
    protected $projectSetting;
    protected $instanceId;
    protected $instanceType;
    protected $userId;
    protected $cultureId;
    protected $cultureCode;
    protected $accessRule;
    protected $configurationRule;
    protected $categoryManager;
    
    public function __construct($entityManager, $request, $categoryManager, $paginatorManager, $serviceContainer)
    {
        $this->entityManager = $entityManager;
        $this->request = $request;
        $this->categoryManager = $categoryManager;
        $this->paginatorManager = $paginatorManager;
        $this->serviceContainer = $serviceContainer;
        $this->languageId = null;
        
        $this->init();
    }
    
    public function __destruct()
    {
        unset($this->request);
        unset($this->entityManager);
        unset($this->paginatorManager);
        unset($this->serviceContainer);
        unset($this->projectSetting);
        unset($this->instanceId);
        unset($this->instanceType);
        unset($this->userId);
        unset($this->cultureId);
        unset($this->cultureCode);
        unset($this->accessRule);
        unset($this->categoryManager);
        unset($this->configurationRule);
        unset($this->searchHelper);
    }
    
    public function init()
    {
        $this->prepareProjectSetting();
        $this->languageId = $this->getLanguageId();
    }
    
    public function prepareProjectSetting()
    {
        $this->projectSetting = $this->request->get('project_setting');
        $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'];
        $this->configurationRule = $this->projectSetting['configuration_rule']['search'];
        $this->accessRule = $this->projectSetting['access_rule']['search'];
        $this->createdUid = $this->userId;
        $this->upatedUid =$this->userId;
    }
    
    public function getLanguageId()
    {
        switch ($this->cultureCode) {
            case 'fr':
                $language = '3';
                break;
            default:
                $language = '1';
                break;
        }
    }
}
