lib/EigyoBundle/src/Entity/UtilItem.php line 14

Open in your IDE?
  1. <?php
  2. namespace Times\EigyoBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Mapping\ClassMetadata;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Kzl\ToolBundle\Util as KzlUtil;
  7. /**
  8.  * UtilItem 汎用項目マスタ
  9.  * @author tokumine  2019/03/25 add
  10.  */
  11. class UtilItem
  12. {
  13.     /**
  14.      * @var int 種類
  15.      */
  16.     const TYPE_MEDIA 1// 媒体
  17.     /**
  18.      * @var int 表示順
  19.      */
  20.     const NEXT_POSITION 10// 表示順増加係数
  21.     /**
  22.      * 種類の選択肢.
  23.      *
  24.      * @var array
  25.      */
  26.     private static $utilItemTypeList = array(
  27.         self::TYPE_MEDIA => '媒体',
  28.     );
  29.     /**
  30.      * @var integer
  31.      */
  32.     private $id;
  33.     /**
  34.      * @var integer
  35.      */
  36.     private $type;
  37.     /**
  38.      * @var integer
  39.      */
  40.     private $position;
  41.     /**
  42.      * @var string
  43.      */
  44.     private $name;
  45.     /**
  46.      * @var string
  47.      */
  48.     private $shortName;
  49.     
  50.     /**
  51.      * @var boolean
  52.      */
  53.     private $enabled '1';
  54.     
  55.     /**
  56.      * @var \DateTime
  57.      */
  58.     private $createdAt;
  59.     /**
  60.      * @var \DateTime
  61.      */
  62.     private $updatedAt;
  63.     /**
  64.      * Get id
  65.      *
  66.      * @return integer
  67.      */
  68.     public function getId()
  69.     {
  70.         return $this->id;
  71.     }
  72.     /**
  73.      * Set type
  74.      *
  75.      * @param integer $type
  76.      *
  77.      * @return UtilItem
  78.      */
  79.     public function setType($type)
  80.     {
  81.         $this->type $type;
  82.         return $this;
  83.     }
  84.     /**
  85.      * Get type
  86.      *
  87.      * @return integer
  88.      */
  89.     public function getType()
  90.     {
  91.         return $this->type;
  92.     }
  93.     /**
  94.      * Set position
  95.      *
  96.      * @param integer $position
  97.      *
  98.      * @return UtilItem
  99.      */
  100.     public function setPosition($position)
  101.     {
  102.         $this->position $position;
  103.         return $this;
  104.     }
  105.     /**
  106.      * Get position
  107.      *
  108.      * @return integer
  109.      */
  110.     public function getPosition()
  111.     {
  112.         return $this->position;
  113.     }
  114.     /**
  115.      * Set name
  116.      *
  117.      * @param string $name
  118.      *
  119.      * @return UtilItem
  120.      */
  121.     public function setName($name)
  122.     {
  123.         $this->name $name;
  124.         return $this;
  125.     }
  126.     /**
  127.      * Get name
  128.      *
  129.      * @return string
  130.      */
  131.     public function getName()
  132.     {
  133.         return $this->name;
  134.     }
  135.     /**
  136.      * Set shortName
  137.      *
  138.      * @param string $shortName
  139.      *
  140.      * @return UtilItem
  141.      */
  142.     public function setShortName($shortName)
  143.     {
  144.         $this->shortName $shortName;
  145.         return $this;
  146.     }
  147.     /**
  148.      * Get shortName
  149.      *
  150.      * @return string
  151.      */
  152.     public function getShortName()
  153.     {
  154.         return $this->shortName;
  155.     }
  156.     /**
  157.      * @ORM\PostLoad
  158.      */
  159.     public function doPostLoad()
  160.     {
  161.         // Add your code here
  162.     }
  163.     /**
  164.      * @ORM\PrePersist
  165.      * @ORM\PreUpdate
  166.      */
  167.     public function doPreUpdate()
  168.     {
  169.         $now = new \Datetime();
  170.         // Add your code here
  171.         if ($this->getCreatedAt() == null) {
  172.             $this->setCreatedAt($now);
  173.         }
  174.         $this->setUpdatedAt($now);
  175.     }
  176.     /**
  177.      * @ORM\PostUpdate
  178.      */
  179.     public function doPostUpdate()
  180.     {
  181.         // Add your code here
  182.     }
  183.     /**
  184.      * Set enabled
  185.      *
  186.      * @param boolean $enabled
  187.      *
  188.      * @return UtilItem
  189.      */
  190.     public function setEnabled($enabled)
  191.     {
  192.         $this->enabled $enabled;
  193.         return $this;
  194.     }
  195.     /**
  196.      * Get enabled
  197.      *
  198.      * @return boolean
  199.      */
  200.     public function getEnabled()
  201.     {
  202.         return $this->enabled;
  203.     }
  204.     /**
  205.      * Set createdAt
  206.      *
  207.      * @param \DateTime $createdAt
  208.      *
  209.      * @return UtilItem
  210.      */
  211.     public function setCreatedAt($createdAt)
  212.     {
  213.         $this->createdAt $createdAt;
  214.         return $this;
  215.     }
  216.     /**
  217.      * Get createdAt
  218.      *
  219.      * @return \DateTime
  220.      */
  221.     public function getCreatedAt()
  222.     {
  223.         return $this->createdAt;
  224.     }
  225.     /**
  226.      * Set updatedAt
  227.      *
  228.      * @param \DateTime $updatedAt
  229.      *
  230.      * @return UtilItem
  231.      */
  232.     public function setUpdatedAt($updatedAt)
  233.     {
  234.         $this->updatedAt $updatedAt;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get updatedAt
  239.      *
  240.      * @return \DateTime
  241.      */
  242.     public function getUpdatedAt()
  243.     {
  244.         return $this->updatedAt;
  245.     }
  246.     /**
  247.      * 種類の名称を取得.
  248.      *
  249.      * @param int $type
  250.      *
  251.      * @var string
  252.      */
  253.     public static function getTypeNameByType($type)
  254.     {
  255.         if (!$type) {
  256.             return '';
  257.         }
  258.         return KzlUtil\Iterator::getArrayValueByKey(self::$utilItemTypeList$type'');
  259.     }
  260.     // --------------------  以下 追加処理 ---------------------------------------------
  261.     /**
  262.      * バリデーションチェックを行う
  263.      * @param ClassMetadata $metadata
  264.      */
  265.     public static function loadValidatorMetadata(ClassMetadata $metadata)
  266.     {
  267.         // 表示順:空白チェック
  268.         $metadata->addPropertyConstraint('position', new Assert\NotBlank());
  269.         // 表示順:桁数チェック
  270.         $metadata->addPropertyConstraint('position', new Assert\Range(array(
  271.             'min'        => 1,
  272.             'max'        => 999999,
  273.         )));
  274.         // 表示順:小数値
  275.         $metadata->addPropertyConstraint('position', new Assert\Regex(array(
  276.             'pattern' => '/^[0-9]*$/',
  277.         )));
  278.         
  279.         // 名前 空白チェック
  280.         $metadata->addPropertyConstraint('name', new Assert\NotBlank());
  281.         // 名前 文字数
  282.         $metadata->addPropertyConstraint('name', new Assert\Length(array(
  283.             'max' => 255,
  284.         )));
  285.     }
  286. }