CompanyPerson.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Doctrine\Tests\Models\Company;
  3. /**
  4. * Description of CompanyPerson
  5. *
  6. * @author robo
  7. * @Entity
  8. * @Table(name="company_persons")
  9. * @InheritanceType("JOINED")
  10. * @DiscriminatorColumn(name="discr", type="string")
  11. * @DiscriminatorMap({
  12. * "person" = "CompanyPerson",
  13. * "manager" = "CompanyManager",
  14. * "employee" = "CompanyEmployee"})
  15. */
  16. class CompanyPerson
  17. {
  18. /**
  19. * @Id
  20. * @Column(type="integer")
  21. * @GeneratedValue
  22. */
  23. private $id;
  24. /**
  25. * @Column
  26. */
  27. private $name;
  28. /**
  29. * @OneToOne(targetEntity="CompanyPerson", mappedBy="spouse")
  30. * @JoinColumn(name="spouse_id", referencedColumnName="id")
  31. */
  32. private $spouse;
  33. /**
  34. * @ManyToMany(targetEntity="CompanyPerson")
  35. * @JoinTable(name="company_persons_friends",
  36. joinColumns={@JoinColumn(name="person_id", referencedColumnName="id")},
  37. inverseJoinColumns={@JoinColumn(name="friend_id", referencedColumnName="id")})
  38. */
  39. private $friends;
  40. public function __construct() {
  41. $this->friends = new \Doctrine\Common\Collections\ArrayCollection;
  42. }
  43. public function getId() {
  44. return $this->id;
  45. }
  46. public function getName() {
  47. return $this->name;
  48. }
  49. public function setName($name) {
  50. $this->name = $name;
  51. }
  52. public function getSpouse() {
  53. return $this->spouse;
  54. }
  55. public function getFriends() {
  56. return $this->friends;
  57. }
  58. public function addFriend(CompanyPerson $friend) {
  59. if ( ! $this->friends->contains($friend)) {
  60. $this->friends->add($friend);
  61. $friend->addFriend($this);
  62. }
  63. }
  64. public function setSpouse(CompanyPerson $spouse) {
  65. if ($spouse !== $this->spouse) {
  66. $this->spouse = $spouse;
  67. $this->spouse->setSpouse($this);
  68. }
  69. }
  70. }