<?php
/**
 * DateTime Column
 * 
 * Use this column for displaying date/time
 * 
 * @author Visual Media 
 */

namespace VisualM\ManagementBundle\AdminList\Column;

use DateTime;
use VisualM\ManagementBundle\AdminList\Column\ColumnConfigurationAbstract;
use VisualM\ManagementBundle\AdminList\Column\ColumnConfigurationInterface;

/**
 * DateTime Column
 *
 * @author Visual Media 
 */
class DateTimeColumn extends ColumnConfigurationAbstract implements ColumnConfigurationInterface
{
    /**
     * DateTime format
     * @var string
     */
    private $format;

    /**
     * Class to apply for items in the past
     * @var string
     */
    private $classPast;

    /**
     * Class to apply for items in the future
     * @var string
     */
    private $classFuture;

    /**
     * Constructor
     * 
     * @param string  $field       Field (null for no field binding)
     * @param string  $Title       Title
     * @param boolean $sortable    Sortable
     * @param string  $format      Display format
     * @param string  $classPast   Class to apply for items in the past
     * @param string  $classFuture Class to apply for items in the future
     */
    public function __construct($field, $Title, $sortable = true, $format = 'd-m-Y H:i', $classPast = null, $classFuture = null)
    {
        parent::__construct(
            $field,
            $Title, 
            $sortable,
            'VisualMManagementBundle:AdminList:Column/DateTime/listItem.html.twig', 
            'VisualMManagementBundle:AdminList:Column/PlainValueColumn/listHeader.html.twig',
            null
        );
        $this->format = $format;
        $this->classPast = $classPast;
        $this->classFuture = $classFuture;
    }

    /**
     * Get Format
     * 
     * @return string Format
     */
    public function getFormat()
    {
        return $this->format;
    }

    /**
     * Get class
     *
     * @param DateTime $date Date
     *
     * @return string Class
     */
    public function getDateClass(DateTime $date = null)
    {
		if ($date == null) { return null; }
        $class = null;
        $now = new \DateTime;
        if ($date < $now) {
            $class = $this->classPast;
        } else if ($date > $now) {
            $class = $this->classFuture;
        }
        return $class;
    }

    
}