<?php

namespace OfficeBrain\CustomBundle\CmsBundle\Entity;

use Doctrine\ORM\EntityRepository;
use OfficeBrain\CustomBundle\CmsBundle\Entity\UploadArtworkCenter;
use OfficeBrain\CustomBundle\CmsBundle\Form\UploadArtworkCenterType;

/**
 * UploadArtworkCenterRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class UploadArtworkCenterRepository extends EntityRepository
{
    protected $projectSetting;
    protected $instanceId;
    protected $instanceType;
    protected $cultureId;
    protected $cultureCode;

    /**
     * @author Employee Id: 4795
     * Description : Set project settings
     */
    public function setProjectSetting($projetSetting)
    {
        $this->projectSetting = $projetSetting;
        $this->prepareProjectSettingData();
    }

    /**
     * @author Employee Id: 4795
     * Description : Get project settings
     */
    public function getProjectSetting()
    {
        return $this->projetSetting;
    }

    /**
     * @author Employee Id: 4795
     * Description : Prepare data from project setting
     */
    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'];
    }    


    public function findByOption($option, $keyword)
    {    		
    	$return = $this->createQueryBuilder('cp')
    	->select(['cp']);
    	$return->where('cp.'.$option.' LIKE :keyword cp.deletedAt is NULL');    
    	$return->setParameter(':keyword', '%'.$keyword.'%')
    	->orderBy('cp.id', 'DESC')
    	->getQuery()
    	->getResult();
    
    	return $return;
    } 


    public function insertUploadArtworkCenter(UploadArtworkCenter $uploadArtworkCenter)
    {    	
    	$em = $this->getEntityManager();
		$em->persist($uploadArtworkCenter);
		$em->flush();
    }


    public function deleteUploadArtworkCenter(UploadArtworkCenter $uploadArtworkCenter)
    {    	
    	$em = $this->getEntityManager();
		$em->remove($uploadArtworkCenter);		
		$em->flush();
    }
    
    public function findAll()
    {
        return $this->findBy(array(), array('id' => 'DESC'));
    }
    
    public function getArtWorkList()
    {
    	return $this->createQueryBuilder('cp')
    	->select('cp.id, cp.senderFirstName , cp.senderEmailAddress, cp.poNumber ,cp.companyName, cp.uploadedFile , cp.message')	
    	->orderBy('cp.id', 'DESC')
    	->getQuery()
    	->getResult();
    }
}
