Person.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Tree\Fixture\Genealogy;
  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="genealogy")
  9. * @ORM\InheritanceType("SINGLE_TABLE")
  10. * @ORM\DiscriminatorColumn(name="discr", type="string")
  11. * @ORM\DiscriminatorMap({"man" = "Man", "woman" = "Woman"})
  12. * @Gedmo\Tree(type="nested")
  13. */
  14. abstract class Person {
  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="Person", inversedBy="children")
  25. * @var Person
  26. */
  27. private $parent;
  28. /**
  29. * @ORM\OneToMany(targetEntity="Person", 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="name", type="string", length=255, nullable=false)
  50. * @var string
  51. */
  52. private $name;
  53. /**
  54. * @param string $name
  55. */
  56. public function __construct($name) {
  57. $this->name = $name;
  58. $this->children = new ArrayCollection();
  59. }
  60. /**
  61. * @param Person $parent
  62. * @return Person
  63. */
  64. public function setParent(Person $parent) {
  65. $this->parent = $parent;
  66. return $this;
  67. }
  68. public function getName() {
  69. return $this->name;
  70. }
  71. public function getLeft()
  72. {
  73. return $this->lft;
  74. }
  75. public function getRight()
  76. {
  77. return $this->rgt;
  78. }
  79. public function getLevel()
  80. {
  81. return $this->lvl;
  82. }
  83. }