Role.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Tree\Fixture;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
  8. * @ORM\Table(name="role")
  9. * @ORM\InheritanceType("JOINED")
  10. * @ORM\DiscriminatorColumn(name="discr", type="string")
  11. * @ORM\DiscriminatorMap({"user" = "User", "usergroup" = "UserGroup", "userldap" = "UserLDAP"})
  12. * @Gedmo\Tree(type="nested")
  13. */
  14. abstract class Role {
  15. /**
  16. * @ORM\Column(name="id", type="integer")
  17. * @ORM\Id
  18. * @ORM\GeneratedValue
  19. * @var int
  20. */
  21. private $id;
  22. /**
  23. * @Gedmo\TreeParent
  24. * @ORM\ManyToOne(targetEntity="UserGroup", inversedBy="children")
  25. * @var UserGroup
  26. */
  27. private $parent;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Role", mappedBy="parent")
  30. * @var Doctrine\Common\Collections\ArrayCollection
  31. */
  32. protected $children;
  33. /**
  34. * @Gedmo\TreeLeft
  35. * @ORM\Column(name="lft", type="integer")
  36. */
  37. private $lft;
  38. /**
  39. * @Gedmo\TreeRight
  40. * @ORM\Column(name="rgt", type="integer")
  41. */
  42. private $rgt;
  43. /**
  44. * @Gedmo\TreeLevel
  45. * @ORM\Column(name="lvl", type="integer")
  46. */
  47. private $lvl;
  48. /**
  49. * @ORM\Column(name="role", type="string", length=255, nullable=false)
  50. * @var string
  51. */
  52. private $role;
  53. public function __construct() {
  54. $this->children = new ArrayCollection();
  55. }
  56. /**
  57. * @return UserGroup
  58. */
  59. public function getParent() {
  60. return $this->parent;
  61. }
  62. /**
  63. * @param UserGroup $parent
  64. * @return Role
  65. */
  66. public function setParent(UserGroup $parent) {
  67. $this->parent = $parent;
  68. return $this;
  69. }
  70. public function getRoleId() {
  71. return $this->role;
  72. }
  73. protected function setRoleId($roleId) {
  74. $this->role = (string)$roleId;
  75. return $this;
  76. }
  77. public function __toString() {
  78. return $this->getRoleId();
  79. }
  80. public function getId() {
  81. return $this->id;
  82. }
  83. public function getLeft()
  84. {
  85. return $this->lft;
  86. }
  87. public function getRight()
  88. {
  89. return $this->rgt;
  90. }
  91. public function getLevel()
  92. {
  93. return $this->lvl;
  94. }
  95. }