partkeepr

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

AbstractCategory.php (4385B)


      1 <?php
      2 
      3 namespace PartKeepr\CategoryBundle\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\CoreBundle\Entity\BaseEntity;
      9 use Symfony\Component\Serializer\Annotation\Groups;
     10 
     11 /**
     12  * @ORM\MappedSuperclass()
     13  * @ORM\Table(indexes={@ORM\Index(columns={"lft"}),@ORM\Index(columns={"rgt"})})
     14  *
     15  * Represents an abstract category. This class isn't directly usable; you need to inherit it to take advantage of
     16  * the AbstractCategoryManager.
     17  *
     18  * If you are interested on how NestedSets work, please read http://en.wikipedia.org/wiki/Nested_set_model
     19  */
     20 abstract class AbstractCategory extends BaseEntity
     21 {
     22     /**
     23      * The parent category. This needs to be re-defined in the class with the proper relations.
     24      *
     25      * @var
     26      */
     27     protected $parent;
     28 
     29     /**
     30      * The "left" property of the nested set.
     31      *
     32      * @ORM\Column(type="integer")
     33      *
     34      * @Gedmo\TreeLeft
     35      *
     36      * @var int
     37      */
     38     private $lft;
     39 
     40     /**
     41      * The "right" property of the nested set.
     42      *
     43      * @ORM\Column(type="integer")
     44      *
     45      * @Gedmo\TreeRight
     46      *
     47      * @var int
     48      */
     49     private $rgt;
     50 
     51     /**
     52      * @Gedmo\TreeLevel
     53      * @ORM\Column(name="lvl", type="integer")
     54      *
     55      * @var int
     56      */
     57     private $lvl;
     58 
     59     /**
     60      * @Gedmo\TreeRoot
     61      * @ORM\Column(name="root", type="integer", nullable=true)
     62      */
     63     private $root;
     64 
     65     /**
     66      * The name of the category.
     67      *
     68      * @ORM\Column(length=128)
     69      * @Groups({"default"})
     70      *
     71      * @var string
     72      */
     73     private $name;
     74 
     75     /**
     76      * The description of the category.
     77      *
     78      * @ORM\Column(type="text",nullable=true)
     79      * @Groups({"default"})
     80      *
     81      * @var string
     82      */
     83     private $description;
     84 
     85     /**
     86      * @Groups({"default"})
     87      *
     88      * @var bool
     89      */
     90     public $expanded = true;
     91 
     92     public function __construct()
     93     {
     94         $this->children = new ArrayCollection();
     95     }
     96 
     97     /**
     98      * Sets the name of this category.
     99      *
    100      * @param string $name The name to set
    101      */
    102     public function setName($name)
    103     {
    104         $this->name = $name;
    105     }
    106 
    107     /**
    108      * Returns the name of this category.
    109      *
    110      * @return string The category name
    111      */
    112     public function getName()
    113     {
    114         return $this->name;
    115     }
    116 
    117     /**
    118      * Returns the level of this category.
    119      *
    120      * @return int
    121      */
    122     public function getLevel()
    123     {
    124         return $this->lvl;
    125     }
    126 
    127     /**
    128      * Sets the description for this category.
    129      *
    130      * @param string $description The description of this category
    131      */
    132     public function setDescription($description)
    133     {
    134         $this->description = $description;
    135     }
    136 
    137     /**
    138      * Returns the description of this category.
    139      *
    140      * @return string The description
    141      */
    142     public function getDescription()
    143     {
    144         return $this->description;
    145     }
    146 
    147     /**
    148      * Returns the "left" value of the nested set.
    149      *
    150      * @return int The left value
    151      *
    152      * (non-PHPdoc)
    153      *
    154      * @see DoctrineExtensions\NestedSet.Node::getLeftValue()
    155      */
    156     public function getLeftValue()
    157     {
    158         return $this->lft;
    159     }
    160 
    161     /**
    162      * Sets the "left" value.
    163      *
    164      * @param $lft integer The left value
    165      *             (non-PHPdoc)
    166      *
    167      * @see DoctrineExtensions\NestedSet.Node::setLeftValue()
    168      */
    169     public function setLeftValue($lft)
    170     {
    171         $this->lft = $lft;
    172     }
    173 
    174     /**
    175      * Returns the "right" value of the nested set.
    176      *
    177      * @return int The right value
    178      *
    179      * (non-PHPdoc)
    180      *
    181      * @see DoctrineExtensions\NestedSet.Node::getRightValue()
    182      */
    183     public function getRightValue()
    184     {
    185         return $this->rgt;
    186     }
    187 
    188     /**
    189      * Sets the "right" value of the nested set.
    190      *
    191      * @param $rgt int The right value
    192      *
    193      * (non-PHPdoc)
    194      *
    195      * @see DoctrineExtensions\NestedSet.Node::setRightValue()
    196      */
    197     public function setRightValue($rgt)
    198     {
    199         $this->rgt = $rgt;
    200     }
    201 
    202     /**
    203      * Sets the root of the tree.
    204      *
    205      * @param $root
    206      */
    207     public function setRoot($root)
    208     {
    209         $this->root = $root;
    210     }
    211 
    212     /**
    213      * Returns the root of the tree.
    214      *
    215      * @return mixed
    216      */
    217     public function getRoot()
    218     {
    219         return $this->root;
    220     }
    221 }