<?php
namespace OfficeBrain\Bundle\FeedBackBundle\Manager\AbstractManager;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\Translator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\JsonResponse;


/**
 * @author OfficeBrain 4493
 * Description : This is the abstract class which contains all the methods of its extended classes.
 *
 **/
abstract class SiteFeedBackAbstract
{
    protected $entityManager;
    protected $request;
    protected $session;
    protected $emailService;
    
    /**
     * @author Employee Id: 4493
     * Description : This function is used to set member variables default value
     * @return: NULL
     * @throws Exception: Null
     */
    public function __construct($entityManager, $request, $session,$emailService)
    {
        $this->entityManager = $entityManager;
        $this->request = $request;
        $this->session = $session;
        $this->emailService = $emailService;
        $this->projectSetting = $this->request->get('project_setting');
        $this->instanceId = $this->projectSetting['instance_id'];    
        $this->siteFeedBackRepositoryManager = $this->entityManager->getRepository('OfficeBrainFeedBackBundle:SiteFeedBack');
        $this->siteFeedBackCategoryRepositoryManager = $this->entityManager->getRepository('OfficeBrainFeedBackBundle:SiteFeedBackCategory');
    }
    
    /**
     * @author Employee Id: 4493
     * Description : This function is used to unset member variables
     * @param : None
     * @return NULL
     * @throws Exception: Null
     */
    
    public function __destruct()
    {
        unset($this->entityManager);
        unset($this->request);
        unset($this->session);
        unset($this->projectSetting);
        unset($this->instanceId);        
    }
    

    /**
     * @author Employee Id: 4493
     * OB eCommerce Product - Add Site Feedback
     * Function created for add Site FeedBack
     */
    
    public function addSiteFeedBack($siteFeedBackObj)
    {
    	$this->siteFeedBack = $this->siteFeedBackRepositoryManager->addSiteFeedBack($siteFeedBackObj);
    	if ($this->siteFeedBack) {
    		return array('status'=>'SUCCESS','data'=>$this->siteFeedBack);
    	}
    	return array('status'=>'FAIL');
    }
    

    /**
     * @author Employee Id: 4493
     * OB eCommerce Product - getSiteFeedBackCategory
     * Function created to get Site FeedBack Category
     */
    public function getSiteFeedBackCategory()
    {
    	$siteFeedBackCategory = $this->siteFeedBackCategoryRepositoryManager->getSiteFeedBackCategory();
    	$siteFeedBackCategoryArray = null;
    	foreach ($siteFeedBackCategory as $key=>$value) {
    		$siteFeedBackCategoryArray[$value['id']] = $value['name'];    		
    	}
    	    	
    	return $siteFeedBackCategoryArray;
    }
    
    
    /**
     * @author Employee Id: 4493
     * OB eCommerce Product - sendSiteFeedBackEmail
     * Function created for send site feedback email
     */
    public function sendSiteFeedBackEmail($form)
    {
    	$siteFeedBackData = $form->getData();
    	$eventKey = 'site_feedback_email'; 
    	$to = '';  
    	$params = array( 
    			'category' => $siteFeedBackData->getCategory(),
    			'summary' => $siteFeedBackData->getSummary(),
    			'comment' => $siteFeedBackData->getComment(),
    			'email' => $siteFeedBackData->getEmail(),
    	);
    	$languageId = $this->projectSetting['culture_id'];
    	$from =  $siteFeedBackData->getEmail();
    	$subject = 'Feedback for : '.$siteFeedBackData->getCategory();
    	$attachment = array();
    	$cc = array(); 
    	$bcc = array();
    	
    	$this->emailService->sendMail($eventKey, $to, $params, $languageId, $from, $subject, $attachment, $cc, $bcc);
    	
    	return true;    	
    }
    
}
