CmsUser.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Doctrine\Tests\Models\CMS;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. /**
  5. * @Entity
  6. * @Table(name="cms_users")
  7. * @NamedQueries({
  8. * @NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")
  9. * })
  10. */
  11. class CmsUser
  12. {
  13. /**
  14. * @Id @Column(type="integer")
  15. * @GeneratedValue
  16. */
  17. public $id;
  18. /**
  19. * @Column(type="string", length=50, nullable=true)
  20. */
  21. public $status;
  22. /**
  23. * @Column(type="string", length=255, unique=true)
  24. */
  25. public $username;
  26. /**
  27. * @Column(type="string", length=255)
  28. */
  29. public $name;
  30. /**
  31. * @OneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true)
  32. */
  33. public $phonenumbers;
  34. /**
  35. * @OneToMany(targetEntity="CmsArticle", mappedBy="user", cascade={"detach"})
  36. */
  37. public $articles;
  38. /**
  39. * @OneToOne(targetEntity="CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
  40. */
  41. public $address;
  42. /**
  43. * @OneToOne(targetEntity="CmsEmail", inversedBy="user", cascade={"persist"}, orphanRemoval=true)
  44. * @JoinColumn(referencedColumnName="id", nullable=true)
  45. */
  46. public $email;
  47. /**
  48. * @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist", "merge", "detach"})
  49. * @JoinTable(name="cms_users_groups",
  50. * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
  51. * inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
  52. * )
  53. */
  54. public $groups;
  55. public function __construct() {
  56. $this->phonenumbers = new ArrayCollection;
  57. $this->articles = new ArrayCollection;
  58. $this->groups = new ArrayCollection;
  59. }
  60. public function getId() {
  61. return $this->id;
  62. }
  63. public function getStatus() {
  64. return $this->status;
  65. }
  66. public function getUsername() {
  67. return $this->username;
  68. }
  69. public function getName() {
  70. return $this->name;
  71. }
  72. /**
  73. * Adds a phonenumber to the user.
  74. *
  75. * @param CmsPhonenumber $phone
  76. */
  77. public function addPhonenumber(CmsPhonenumber $phone) {
  78. $this->phonenumbers[] = $phone;
  79. $phone->setUser($this);
  80. }
  81. public function getPhonenumbers() {
  82. return $this->phonenumbers;
  83. }
  84. public function addArticle(CmsArticle $article) {
  85. $this->articles[] = $article;
  86. $article->setAuthor($this);
  87. }
  88. public function addGroup(CmsGroup $group) {
  89. $this->groups[] = $group;
  90. $group->addUser($this);
  91. }
  92. public function getGroups() {
  93. return $this->groups;
  94. }
  95. public function removePhonenumber($index) {
  96. if (isset($this->phonenumbers[$index])) {
  97. $ph = $this->phonenumbers[$index];
  98. unset($this->phonenumbers[$index]);
  99. $ph->user = null;
  100. return true;
  101. }
  102. return false;
  103. }
  104. public function getAddress() { return $this->address; }
  105. public function setAddress(CmsAddress $address) {
  106. if ($this->address !== $address) {
  107. $this->address = $address;
  108. $address->setUser($this);
  109. }
  110. }
  111. public function getEmail() { return $this->email; }
  112. public function setEmail(CmsEmail $email = null) {
  113. if ($this->email !== $email) {
  114. $this->email = $email;
  115. if ($email) {
  116. $email->setUser($this);
  117. }
  118. }
  119. }
  120. }