app/Plugin/CMBlogPro/Entity/Category.php line 16

Open in your IDE?
  1. <?php
  2. namespace Plugin\CMBlogPro\Entity;
  3. use Doctrine\Common\Collections\Criteria;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. /**
  7.  * Category
  8.  *
  9.  * @ORM\Table(name="plg_blog_category2")
  10.  * @ORM\Entity(repositoryClass="Plugin\CMBlogPro\Repository\CategoryRepository")
  11.  * @UniqueEntity("name")
  12.  */
  13. class Category
  14. {
  15.     /**
  16.      * カテゴリに紐づく商品があるかどうかを調べる.
  17.      *
  18.      * ProductCategoriesはExtra Lazyのため, lengthやcountで評価した際にはCOUNTのSQLが発行されるが,
  19.      * COUNT自体が重いので, LIMIT 1で取得し存在チェックを行う.
  20.      *
  21.      * @see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections
  22.      *
  23.      * @return bool
  24.      */
  25.     public function hasBlogCategories()
  26.     {
  27.         $criteria Criteria::create()
  28.         ->orderBy(['category_id' => Criteria::ASC])
  29.         ->setFirstResult(0)
  30.         ->setMaxResults(1);
  31.         return $this->BlogCategories->matching($criteria)->count() > 0;
  32.     }
  33.     /**
  34.      * @var int
  35.      *
  36.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  37.      * @ORM\Id
  38.      * @ORM\GeneratedValue(strategy="IDENTITY")
  39.      */
  40.     private $id;
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(name="name", type="string", length=100, unique=true)
  45.      */
  46.     private $name;
  47.     /**
  48.      * @var string
  49.      *
  50.      * @ORM\Column(name="class", type="string", length=100, nullable=true)
  51.      */
  52.     private $class;
  53.     /**
  54.      * @var \Doctrine\Common\Collections\Collection
  55.      *
  56.      * @ORM\OneToMany(targetEntity="Plugin\CMBlogPro\Entity\BlogCategory", mappedBy="Category", fetch="EXTRA_LAZY")
  57.      */
  58.     private $BlogCategories;
  59.     /**
  60.      * Get id.
  61.      * 
  62.      * @return int
  63.      */
  64.     public function getId()
  65.     {
  66.         return $this->id;
  67.     }
  68.     /**
  69.      * Get Name
  70.      * 
  71.      * @return int
  72.      */
  73.     public function getName()
  74.     {
  75.         return $this->name;
  76.     }
  77.     /**
  78.      * Set Name
  79.      * 
  80.      * @param string $value
  81.      *
  82.      * @return $this;
  83.      */
  84.     public function setName($value)
  85.     {
  86.         $this->name $value;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Get Class
  91.      * 
  92.      * @return int
  93.      */
  94.     public function getClass()
  95.     {
  96.         return $this->class;
  97.     }
  98.     /**
  99.      * Set Class
  100.      * 
  101.      * @param string $value
  102.      *
  103.      * @return $this;
  104.      */
  105.     public function setClass($value)
  106.     {
  107.         $this->class $value;
  108.         return $this;
  109.     }
  110.     /**
  111.      * Add blogCategory.
  112.      *
  113.      * @param \Plugin\CMBlogPro\Entity\BlogCategory $blogCategory
  114.      *
  115.      * @return Category
  116.      */
  117.     public function addBlogCategory(\Plugin\CMBlogPro\Entity\BlogCategory $blogCategory)
  118.     {
  119.         $this->BlogCategories[] = $blogCategory;
  120.         return $this;
  121.     }
  122.     /**
  123.      * Remove blogCategory.
  124.      *
  125.      * @param \Plugin\CMBlogPro\Entity\BlogCategory $blogCategory
  126.      *
  127.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  128.      */
  129.     public function removeBlogCategory(\Plugin\CMBlogPro\Entity\BlogCategory $blogCategory)
  130.     {
  131.         return $this->BlogCategories->removeElement($blogCategory);
  132.     }
  133.     /**
  134.      * Get blogCategories.
  135.      *
  136.      * @return \Doctrine\Common\Collections\Collection
  137.      */
  138.     public function getBlogCategories()
  139.     {
  140.         return $this->BlogCategories;
  141.     }
  142. }