CmsUser.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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)
  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")
  36. */
  37. public $articles;
  38. /**
  39. * @OneToOne(targetEntity="CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
  40. */
  41. public $address;
  42. /**
  43. * @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist", "merge"})
  44. * @JoinTable(name="cms_users_groups",
  45. * joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
  46. * inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
  47. * )
  48. */
  49. public $groups;
  50. public function __construct() {
  51. $this->phonenumbers = new ArrayCollection;
  52. $this->articles = new ArrayCollection;
  53. $this->groups = new ArrayCollection;
  54. }
  55. public function getId() {
  56. return $this->id;
  57. }
  58. public function getStatus() {
  59. return $this->status;
  60. }
  61. public function getUsername() {
  62. return $this->username;
  63. }
  64. public function getName() {
  65. return $this->name;
  66. }
  67. /**
  68. * Adds a phonenumber to the user.
  69. *
  70. * @param CmsPhonenumber $phone
  71. */
  72. public function addPhonenumber(CmsPhonenumber $phone) {
  73. $this->phonenumbers[] = $phone;
  74. $phone->setUser($this);
  75. }
  76. public function getPhonenumbers() {
  77. return $this->phonenumbers;
  78. }
  79. public function addArticle(CmsArticle $article) {
  80. $this->articles[] = $article;
  81. $article->setAuthor($this);
  82. }
  83. public function addGroup(CmsGroup $group) {
  84. $this->groups[] = $group;
  85. $group->addUser($this);
  86. }
  87. public function getGroups() {
  88. return $this->groups;
  89. }
  90. public function removePhonenumber($index) {
  91. if (isset($this->phonenumbers[$index])) {
  92. $ph = $this->phonenumbers[$index];
  93. unset($this->phonenumbers[$index]);
  94. $ph->user = null;
  95. return true;
  96. }
  97. return false;
  98. }
  99. public function getAddress() { return $this->address; }
  100. public function setAddress(CmsAddress $address) {
  101. if ($this->address !== $address) {
  102. $this->address = $address;
  103. $address->setUser($this);
  104. }
  105. }
  106. }