<?php
/**
 * Column Configuration
 * 
 * @author Visual Media 
 */

namespace VisualM\ManagementBundle\AdminList\Column;

/**
 * Column Configuration
 *
 * @author Visual Media 
 */
class EnumColumn extends ColumnConfigurationAbstract implements ColumnConfigurationInterface
{
    /**
     * Translations
     * @var array
     */
    protected $Translations;

    /**
     * Constructor
     * 
     * @param string  $field          Field (null for no field binding)
     * @param string  $title          Title
     * @param array   $translations   Translations
     * @param boolean $sortable       Sortable (Sorts on Enum values!)
     * @param string  $itemClass      Item Class
     */
    public function __construct($field, $title, $translations = array(), $sortable = false, $itemClass = '')
    {
        parent::__construct(
            $field,
            $title,
            $sortable,
            'VisualMManagementBundle:AdminList:Column/EnumColumn/listItem.html.twig',
            'VisualMManagementBundle:AdminList:Column/PlainValueColumn/listHeader.html.twig',
            null,
            $itemClass
        );
        $this->Translations = $translations;
    }

    /**
     * Look up translation for Enum value
     * 
     * @param string $value Value
     * 
     * @return string Translation if found, else original value
     */
    public function getEnumTranslation($value) {
        if (isset($this->Translations[$value])) {
            return $this->Translations[$value];
        } else {
            return $value;
        }
    }

}