<?php
/**
 * Folder
 * 
 * Folder FileSystem Item, represents an folder item
 * 
 * @author Visual Media 
 */

namespace VisualM\MediaManagerBundle\FileSystem;

use Symfony\Component\Finder\SplFileInfo;
use VisualM\MediaManagerBundle\Configuration\ConfigurationInterface;

/**
 * Folder
 * 
 * @author Visual Media 
 */
class Folder implements ItemInterface
{    
    /**
     * Configuration
     * @var ConfigurationInterface
     */
    private $configuration;
    
    /**
     * Base relative path
     * @var string
     */
    private $base_rel_path;
    
    /**
     * SPL file item
     * @var SplFileInfo
     */
    private $file_item;

    /**
     * Constructor
     * 
     * @param ConfigurationInterface $configuration Configuration
     * @param string                 $base_rel_path Base relative path
     * @param SplFileInfo            $file_item     File Info
     */
    function __construct(ConfigurationInterface $configuration, $base_rel_path, SplFileInfo $file_item)
    {
        $this->configuration = $configuration;
        $this->base_rel_path = $base_rel_path;
        $this->file_item = $file_item;
    }

    /**
     * {@inheritDoc}
     */
    public function getType()
    {
        return 'folder';
    }
    
    /**
     * {@inheritDoc}
     */
    public function getName() {
        return $this->file_item->getRelativePathName();
    }
    
    /**
     * {@inheritDoc}
     */
    public function getRelativePath() {
        return $this->base_rel_path . $this->file_item->getRelativePathName() . DIRECTORY_SEPARATOR;
    }
    
    /**
     * {@inheritDoc}
     */
    public function getAbsolutePath() {
        return $this->file_item->getRealPath();
    }
    
    /**
     * {@inheritDoc}
     */
    public function isViewable() {
        $flags = $this->configuration->getFolderFlags($this->file_item->getRealPath());
        return (($flags & ConfigurationInterface::FLAG_VIEW) == ConfigurationInterface::FLAG_VIEW);
    }
    
    /**
     * {@inheritDoc}
     */
    public function isEditable() {
        $flags = $this->configuration->getFolderFlags($this->file_item->getRealPath());
        return (($flags & ConfigurationInterface::FLAG_EDIT) == ConfigurationInterface::FLAG_EDIT);
    }
    
    /**
     * {@inheritDoc}
     */
    public function isDeleteable() {
        $flags = $this->configuration->getFolderFlags($this->file_item->getRealPath());
        return (($flags & ConfigurationInterface::FLAG_DELETE) == ConfigurationInterface::FLAG_DELETE);
    }
    
    /**
     * {@inheritDoc}
     */
    public function getIcon() {
        return 'bundles/visualmmediamanager/filetypes/folder.png';
    } 
    
}