1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/tests/Doctrine/Tests/Models/CMS/CmsUser.php

140 lines
3.5 KiB
PHP
Raw Normal View History

2008-02-09 02:20:35 +03:00
<?php
namespace Doctrine\Tests\Models\CMS;
use Doctrine\Common\Collections\ArrayCollection;
2009-07-28 20:36:24 +04:00
/**
* @Entity
* @Table(name="cms_users")
* @NamedQueries({
* @NamedQuery(name="all", query="SELECT u FROM __CLASS__ u")
* })
*/
class CmsUser
2008-02-09 02:20:35 +03:00
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column(type="string", length=50, nullable=true)
*/
public $status;
/**
* @Column(type="string", length=255, unique=true)
*/
public $username;
/**
* @Column(type="string", length=255)
*/
public $name;
/**
* @OneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"persist", "merge"}, orphanRemoval=true)
*/
public $phonenumbers;
/**
* @OneToMany(targetEntity="CmsArticle", mappedBy="user", cascade={"detach"})
*/
public $articles;
/**
* @OneToOne(targetEntity="CmsAddress", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
public $address;
/**
* @OneToOne(targetEntity="CmsEmail", inversedBy="user", cascade={"persist"}, orphanRemoval=true)
* @JoinColumn(referencedColumnName="id", nullable=true)
*/
public $email;
/**
* @ManyToMany(targetEntity="CmsGroup", inversedBy="users", cascade={"persist", "merge", "detach"})
* @JoinTable(name="cms_users_groups",
2009-07-28 20:36:24 +04:00
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
public $groups;
2009-07-28 20:36:24 +04:00
public function __construct() {
$this->phonenumbers = new ArrayCollection;
$this->articles = new ArrayCollection;
$this->groups = new ArrayCollection;
2009-07-28 20:36:24 +04:00
}
public function getId() {
return $this->id;
}
public function getStatus() {
return $this->status;
}
public function getUsername() {
return $this->username;
}
public function getName() {
return $this->name;
}
/**
* Adds a phonenumber to the user.
*
* @param CmsPhonenumber $phone
*/
public function addPhonenumber(CmsPhonenumber $phone) {
$this->phonenumbers[] = $phone;
$phone->setUser($this);
}
2009-01-29 20:00:44 +03:00
public function getPhonenumbers() {
return $this->phonenumbers;
}
public function addArticle(CmsArticle $article) {
$this->articles[] = $article;
$article->setAuthor($this);
}
public function addGroup(CmsGroup $group) {
$this->groups[] = $group;
$group->addUser($this);
}
public function getGroups() {
return $this->groups;
}
2009-01-29 20:00:44 +03:00
public function removePhonenumber($index) {
if (isset($this->phonenumbers[$index])) {
$ph = $this->phonenumbers[$index];
unset($this->phonenumbers[$index]);
$ph->user = null;
return true;
}
return false;
}
2009-10-07 16:39:46 +04:00
public function getAddress() { return $this->address; }
public function setAddress(CmsAddress $address) {
if ($this->address !== $address) {
$this->address = $address;
$address->setUser($this);
}
}
public function getEmail() { return $this->email; }
public function setEmail(CmsEmail $email = null) {
if ($this->email !== $email) {
$this->email = $email;
if ($email) {
$email->setUser($this);
}
}
}
}