<?php

namespace OfficeBrain\CustomBundle\CmsBundle\Manager\AbstractManager;

abstract class OrderCatalogAbstract
{
	protected $container;
	protected $entityManager;
    protected $request;
    protected $emailManager;
    protected $projectSetting;
    protected $paginatorManager;
    protected $recordsPerPage;

    public function __construct($container,$entityManager, $request, $emailManager, $paginatorManager)
    {
    	$this->container          = $container;
    	$this->entityManager = $entityManager;
    	$this->request = $request;
    	$this->emailManager = $emailManager;
    	$this->paginatorManager = $paginatorManager;
    	$this->cultureId          = $this->projectSetting['culture_id'];
        $this->cultureCode        = $this->projectSetting['culture_code'];
        $this->instanceId         = $this->projectSetting['instance_id'];
        $this->instanceType       = $this->projectSetting['instance_type'];
        $this->userId             = $this->projectSetting['user_id'];
        $this->createdUid         = $this->userId;
        $this->updatedUid         = $this->userId;
        $this->deletedUid         = $this->userId;
        $this->sessionInstanceKey = $this->instanceId.'-'.$this->cultureId;
        $this->session            = $container->get('session');
        $this->translator         = $container->get('translator');
    	$this->projectSetting = $this->request->get('project_setting');
    	$this->recordsPerPage = $this->projectSetting['configuration_rule']['site_management']['option']['cms']['option']['cms_page_record_per_page']['status'];
        $this->orderCatalogRepository = $this->entityManager->getRepository('OfficeBrainCustomBundleCmsBundle:OrderCatalog');
        $this->orderCatalogRepository->setProjectSetting($this->projectSetting);
	}

    public function __destruct()
    {
        unset($this->entityManager);
        unset($this->request);
        unset($this->emailManager);
        unset($this->paginatorManager);
    }
    
    public function commit($entity)
    {
    	$this->entityManager->persist($entity);
    	$this->entityManager->flush();
    	return $entity;
    }
    
    public function remove($entity)
    {
    	$this->entityManager->remove($entity);
    	$this->entityManager->flush();
    }
}
