partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

FootprintCategory.php (2846B)


      1 <?php
      2 
      3 namespace PartKeepr\FootprintBundle\Entity;
      4 
      5 use Doctrine\Common\Collections\ArrayCollection;
      6 use Doctrine\ORM\Mapping as ORM;
      7 use Gedmo\Mapping\Annotation as Gedmo;
      8 use PartKeepr\CategoryBundle\Entity\AbstractCategory;
      9 use PartKeepr\CategoryBundle\Entity\CategoryPathInterface;
     10 use PartKeepr\DoctrineReflectionBundle\Annotation\TargetService;
     11 use Symfony\Component\Serializer\Annotation\Groups;
     12 
     13 /**
     14  * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
     15  * @Gedmo\Tree(type="nested")
     16  * @ORM\Table(indexes={@ORM\Index(columns={"lft"}),@ORM\Index(columns={"rgt"})})
     17  * The entity for our footprint categories
     18  * @TargetService(uri="/api/footprint_categories")
     19  */
     20 class FootprintCategory extends AbstractCategory implements CategoryPathInterface
     21 {
     22     /**
     23      * @Gedmo\TreeParent
     24      * @ORM\ManyToOne(targetEntity="FootprintCategory", inversedBy="children")
     25      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
     26      */
     27     protected $parent;
     28 
     29     /**
     30      * @ORM\OneToMany(targetEntity="FootprintCategory", mappedBy="parent")
     31      * @ORM\OrderBy({"lft" = "ASC"})
     32      * @Groups({"tree"})
     33      */
     34     protected $children;
     35 
     36     /**
     37      * @ORM\OneToMany(targetEntity="Footprint", mappedBy="category")
     38      */
     39     protected $footprints;
     40 
     41     /**
     42      * @ORM\Column(type="text",nullable=true)
     43      * @Groups({"default"})
     44      *
     45      * @var string
     46      */
     47     protected $categoryPath;
     48 
     49     /**
     50      * Sets the parent category.
     51      *
     52      * @Groups({"default"})
     53      *
     54      * @param AbstractCategory|null $parent
     55      */
     56     public function setParent(AbstractCategory $parent = null)
     57     {
     58         $this->parent = $parent;
     59     }
     60 
     61     /**
     62      * Returns the parent category.
     63      *
     64      * @return mixed
     65      */
     66     public function getParent()
     67     {
     68         return $this->parent;
     69     }
     70 
     71     /**
     72      * Returns the footprints.
     73      *
     74      * @return ArrayCollection
     75      */
     76     public function getFootprints()
     77     {
     78         return $this->footprints->getValues();
     79     }
     80 
     81     /**
     82      * Returns the children.
     83      *
     84      * @return ArrayCollection
     85      */
     86     public function getChildren()
     87     {
     88         return $this->children->getValues();
     89     }
     90 
     91     /**
     92      * Returns the category path.
     93      *
     94      * @return string
     95      */
     96     public function getCategoryPath()
     97     {
     98         return $this->categoryPath;
     99     }
    100 
    101     /**
    102      * {@inheritdoc}
    103      */
    104     public function setCategoryPath($categoryPath)
    105     {
    106         $this->categoryPath = $categoryPath;
    107     }
    108 
    109     /**
    110      * {@inheritdoc}
    111      */
    112     public function generateCategoryPath($pathSeparator)
    113     {
    114         if ($this->getParent() !== null) {
    115             return $this->getParent()->generateCategoryPath($pathSeparator).$pathSeparator.$this->getName();
    116         } else {
    117             return $this->getName();
    118         }
    119     }
    120 }