<?php
namespace OfficeBrain\CustomBundle\CmsBundle\Manager\AbstractManager;


abstract class CmsMediaLibraryAbstract
{
    protected $entityManager;
    protected $request;
    protected $projectSettings;
    protected $cmsConfigurations;
    protected $mediaFileUrl;
    protected $mediaFilePath;
    protected $cmsMediaLibraryRepository;
    protected $recordsPerPage;
    protected $knpPaginator;
    
    protected $cmsMediaAllowedImages;
    protected $cmsMediaAllowedDocuments;
    protected $cmsMediaAllowedPdf;
    protected $cmsMediaDefaultTab;
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to set member variables default value
     *
     * @param 1: $entityManager
     * @param 2: $request
     * @param 3: $knpPaginator
     * @param 4: $mediaFileUrl
     * @param 5: $mediaFilePath
     *
     * @return: NULL
     *
     * @throws Exception: Null
     */
    public function __construct($entityManager, $request, $knpPaginator, $mediaFileUrl, $mediaFilePath)
    {
        $this->entityManager = $entityManager;
        $this->request = $request;
        $this->mediaFileUrl = $mediaFileUrl;
        $this->mediaFilePath = $mediaFilePath;
        $this->projectSettings = $this->request->get('project_setting');
        $this->cmsConfigurations = $this->projectSettings['configuration_rule']['site_management']['option']['cms'];
        $this->cmsMediaLibraryRepository = $this->entityManager->getRepository('OfficeBrainCmsBundle:CmsMediaLibrary');
        $this->cmsMediaLibraryRepository->setProjectSetting($this->projectSettings);
        $this->recordsPerPage = $this->projectSettings['configuration_rule']['site_management']['option']['cms']['option']['cms_media_record_per_page']['status'];
        $this->knpPaginator = $knpPaginator;
        
        $this->cmsMediaAllowedImages = $this->projectSettings['configuration_rule']['site_management']['option']['cms']['option']['cms_media_allowd_files']['option']['image'];
        $this->cmsMediaAllowedDocuments = $this->projectSettings['configuration_rule']['site_management']['option']['cms']['option']['cms_media_allowd_files']['option']['document'];
        $this->cmsMediaAllowedPdf = $this->projectSettings['configuration_rule']['site_management']['option']['cms']['option']['cms_media_allowd_files']['option']['pdf'];
        $this->cmsMediaDefaultTab = $this->projectSettings['configuration_rule']['site_management']['option']['cms']['option']['cms_media_default_file_type']['status'];
        
        $this->cmsMediaLibraryRepository->setPaginatorService($this->knpPaginator);
    }
    
    /**
     * @author Employee Id: 4464
     *
     * 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->mediaFileUrl);
        unset($this->mediaFilePath);
        unset($this->recordsPerPage);
        unset($this->knpPaginator);
        
        unset($this->cmsMediaAllowedImages);
        unset($this->cmsMediaAllowedDocuments);
        unset($this->cmsMediaAllowedPdf);
        unset($this->cmsMediaDefaultTab);
        unset($this->cmsMediaLibraryRepository);
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to store the uploaded media's data into database
     *
     * @param : $file
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function uploadMediaFile($file)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to validate the uploaded file and move it to the targeted direvtory
     *
     * @param : $formData
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function moveFile($file)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to store the uploaded media's data into database
     *
     * @param : $uploadedMediaInfo
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function setMedia($uploadedMediaInfo)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to check the upload file's type
     *
     * @param : $file object
     *
     * @return type of the file
     *
     * @throws Exception : Null
     *
     **/
    public function checkUploadedMediaType($file)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to check the size of the uploaded file
     *
     * @param : $file object
     *
     * @return boolean
     *
     * @throws Exception : Null
     *
     **/
    public function checkUploadedMediaSize($file)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to fetch the uploaded media from database
     *
     * @param : Null
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function getMedia()
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to download a file
     *
     * @param : $name
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function downloadMedia($name)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to delete a file permanantly
     *
     * @param : $name
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function deleteMedia($name)
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to view the image
     *
     * @param : Null
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function getImage()
    {
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function checks if the file exists or not.
     *
     * @param : $fileName
     *
     * @return $fileName
     *
     * @throws Exception : Null
     *
     **/
    public function getNewFileNameIfFileExists($fileName)
    {
        /* $i = 1;
        if (file_exists($this->mediaFilePath.'/'.$fileName)) {
            $fileInfo = array();
            $newFileName = $fileName;
            while (file_exists($this->mediaFilePath.'/'.$newFileName)) {
                $fileInfo = pathinfo($this->mediaFilePath.'/'.$fileName);
                $newFileName = $fileInfo['filename'].$i.'.'.$fileInfo['extension'];
                $i++;
            }
            $fileName = $newFileName;
            unset($newFileName);
            unset($fileInfo);
        }
        unset($i); */
        
        $currentDateTime = new \DateTime();
        
        $fileInfo = pathinfo($this->mediaFilePath.'/'.$fileName);
        $fileInfo['filename'] = str_replace(" ","-",$fileInfo['filename']);
        $fileName = $currentDateTime->format('YmdHis').'_'.$fileInfo['filename'].'.'.$fileInfo['extension'];
        
        unset($currentDateTime);
        unset($fileInfo);
        
        return $fileName;
    }
    
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to view the image
     *
     * @param : Null
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function getMediaLibraryRecords($mediaType = null)
    {
    }
    
    /**
     * @author Employee Id: 4471
     *
     * Description : This function is used to view the image using pagination
     *
     * @param : Null
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    
    public function getMediaLibraryRecordsWithPagination($mediaType = null,$page=1,$noOfRecord=12)
    {
    	
    }
    /**
     * @author Employee Id: 4464
     *
     * Description : This function is used to view the image
     *
     * @param : Null
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function createMediaFileDirectory()
    {
        if (!is_dir($this->mediaFilePath)) {
            if (!file_exists($this->mediaFilePath)) {
                if (false === @mkdir($this->mediaFilePath, 0777, true)) {
                    $error[]='Unable to create the directory';
                    return array('error' => $error);
                }
            }
        }
    }
    
    /**
     * @author Employee Id: 4471
     *
     * Description : This function is used to copy file from one folder to another
     *
     * @param : $fromFolder, $toFolder ,$originalImageName , $duplicateImageName
     *
     * @return Null
     *
     * @throws Exception : Null
     *
     **/
    public function copyMedia($fromFolder, $toFolder, $originalImageName, $duplicateImageName='')
    {
    }
}
