<?php

namespace RxConnexionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="RxConnexionBundle\Repository\ItemTypeRepository")
 * @ORM\Table(name="item_type", indexes={@ORM\Index(name="IDX_SEARCH_000", columns={"description"})})
 * @ORM\HasLifecycleCallbacks()
 */
 
class ItemTypeEntity
{
    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
	protected $id;

    /**
     * @ORM\Column(name="code", type="string", nullable=true)
     */
	protected $code;
	
    /**
     * @ORM\Column(name="description", type="string")
     */
	protected $description;
	
    /**
     * @ORM\Column(name="created_by", type="string", length=50)
     */
	protected $createdBy;
	
    /**
     * @ORM\Column(name="created_at", type="datetime")
     */
	protected $createdAt;
	
    /**
     * @ORM\Column(name="updated_by", type="string", length=50)
     */
	protected $updatedBy;
	
    /**
     * @ORM\Column(name="updated_at", type="datetime")
     */
	protected $updatedAt;

    /**
     * @ORM\OneToMany(targetEntity="ItemEntity", mappedBy="itemType")
     */
    protected $items;
  
    /** 
     * Set createdAt 
     * 
     * @ORM\PrePersist 
     */      
    public function setCreatedAtValue()  
    {
    	$this->createdBy = isSet($_COOKIE['username']) ? $_COOKIE['username'] : 'System';
        $this->createdAt = new \DateTime();
    	$this->updatedBy = isSet($_COOKIE['username']) ? $_COOKIE['username'] : 'System';
        $this->updatedAt = new \DateTime();
    }
  
    /**
     * Set updatedAt
     * 
     * @ORM\PreUpdate 
     */  
    public function setUpdatedAtValue()  
    {  
    	$this->updatedBy = $_COOKIE['username'];
        $this->updatedAt = new \DateTime();
    }

    public function __construct($data=null)
    {
    	if(!is_null($data)) {
    		$this->id = $data->getId();
	    	$this->code = $data->getCode();
            $this->description = $data->getDescription();
    	}

        $this->items = new ArrayCollection();
    }

	/*--------------------------------------------------------------------------------------------------------*/
	/*					User Defined Setters and Getters													  */
	/*--------------------------------------------------------------------------------------------------------*/
    
	/*--------------------------------------------------------------------------------------------------------*/
	/*					Setters and Getters																	  */
	/*--------------------------------------------------------------------------------------------------------*/


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set code
     *
     * @param string $code
     * @return ItemTypeEntity
     */
    public function setCode($code)
    {
        $this->code = $code;
    
        return $this;
    }

    /**
     * Get code
     *
     * @return string 
     */
    public function getCode()
    {
        return $this->code;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return ItemTypeEntity
     */
    public function setDescription($description)
    {
        $this->description = $description;
    
        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set createdBy
     *
     * @param string $createdBy
     * @return ItemTypeEntity
     */
    public function setCreatedBy($createdBy)
    {
        $this->createdBy = $createdBy;
    
        return $this;
    }

    /**
     * Get createdBy
     *
     * @return string 
     */
    public function getCreatedBy()
    {
        return $this->createdBy;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return ItemTypeEntity
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;
    
        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedBy
     *
     * @param string $updatedBy
     * @return ItemTypeEntity
     */
    public function setUpdatedBy($updatedBy)
    {
        $this->updatedBy = $updatedBy;
    
        return $this;
    }

    /**
     * Get updatedBy
     *
     * @return string 
     */
    public function getUpdatedBy()
    {
        return $this->updatedBy;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return ItemTypeEntity
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;
    
        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Add items
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $items
     * @return ItemTypeEntity
     */
    public function addItem(\RxConnexionBundle\Entity\ItemEntity $items)
    {
        $this->items[] = $items;
    
        return $this;
    }

    /**
     * Remove items
     *
     * @param \RxConnexionBundle\Entity\ItemEntity $items
     */
    public function removeItem(\RxConnexionBundle\Entity\ItemEntity $items)
    {
        $this->items->removeElement($items);
    }

    /**
     * Get items
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getItems()
    {
        return $this->items;
    }
}
