CmsUser.php 2.82 KB
Newer Older
jwage's avatar
jwage committed
1
<?php
2

3
namespace Doctrine\Tests\Models\CMS;
4

5
use Doctrine\Common\Collections\ArrayCollection;
6

7
/**
8 9
 * @Entity
 * @Table(name="cms_users")
10
 */
11
class CmsUser
jwage's avatar
jwage committed
12
{
13
    /**
14
     * @Id @Column(type="integer")
15
     * @GeneratedValue(strategy="AUTO")
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", "remove", "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"})
40 41
     */
    public $address;
42
    /**
43
     * @ManyToMany(targetEntity="CmsGroup", cascade={"persist"})
44
     * @JoinTable(name="cms_users_groups",
45 46 47
     *      joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
     *      )
48 49
     */
    public $groups;
50 51
    
    public function __construct() {
52 53 54
        $this->phonenumbers = new ArrayCollection;
        $this->articles = new ArrayCollection;
        $this->groups = new ArrayCollection;
55
    }
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    public function getId() {
        return $this->id;
    }

    public function getStatus() {
        return $this->status;
    }

    public function getUsername() {
        return $this->username;
    }

    public function getName() {
        return $this->name;
    }

73 74 75
    /**
     * Adds a phonenumber to the user.
     *
76
     * @param CmsPhonenumber $phone
77 78 79
     */
    public function addPhonenumber(CmsPhonenumber $phone) {
        $this->phonenumbers[] = $phone;
80
        $phone->setUser($this);
81
    }
82

83 84 85 86
    public function getPhonenumbers() {
        return $this->phonenumbers;
    }

87 88
    public function addArticle(CmsArticle $article) {
        $this->articles[] = $article;
89
        $article->setAuthor($this);
90 91 92 93 94 95 96 97 98
    }

    public function addGroup(CmsGroup $group) {
        $this->groups[] = $group;
        $group->addUser($this);
    }

    public function getGroups() {
        return $this->groups;
99 100
    }

101 102 103 104 105 106 107 108 109
    public function removePhonenumber($index) {
        if (isset($this->phonenumbers[$index])) {
            $ph = $this->phonenumbers[$index];
            unset($this->phonenumbers[$index]);
            $ph->user = null;
            return true;
        }
        return false;
    }
110
    
romanb's avatar
romanb committed
111 112
    public function getAddress() { return $this->address; }
    
113 114 115 116 117 118
    public function setAddress(CmsAddress $address) {
        if ($this->address !== $address) {
            $this->address = $address;
            $address->setUser($this);
        }
    }
119
}