Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Models / DDC964 / DDC964User.php
1 <?php
2
3 namespace Doctrine\Tests\Models\DDC964;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6
7 /**
8  * @MappedSuperclass
9  */
10 class DDC964User
11 {
12
13     /**
14      * @Id
15      * @GeneratedValue
16      * @Column(type="integer", name="user_id", length=150)
17      */
18     protected $id;
19
20     /**
21      * @Column(name="user_name", nullable=true, unique=false, length=250)
22      */
23     protected $name;
24
25     /**
26      * @var ArrayCollection
27      *
28      * @ManyToMany(targetEntity="DDC964Group", inversedBy="users", cascade={"persist", "merge", "detach"})
29      * @JoinTable(name="ddc964_users_groups",
30      *  joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
31      *  inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
32      * )
33      */
34     protected $groups;
35
36     /**
37      * @var DDC964Address
38      *
39      * @ManyToOne(targetEntity="DDC964Address", cascade={"persist", "merge"})
40      * @JoinColumn(name="address_id", referencedColumnName="id")
41      */
42     protected $address;
43
44     /**
45      * @param string $name
46      */
47     public function __construct($name = null)
48     {
49         $this->name     = $name;
50         $this->groups   = new ArrayCollection;
51     }
52
53     /**
54      * @return integer
55      */
56     public function getId()
57     {
58         return $this->id;
59     }
60
61     /**
62      * @return string
63      */
64     public function getName()
65     {
66         return $this->name;
67     }
68
69     /**
70      * @param string $name
71      */
72     public function setName($name)
73     {
74         $this->name = $name;
75     }
76
77     /**
78      * @param DDC964Group $group
79      */
80     public function addGroup(DDC964Group $group)
81     {
82         $this->groups->add($group);
83         $group->addUser($this);
84     }
85
86     /**
87      * @return ArrayCollection
88      */
89     public function getGroups()
90     {
91         return $this->groups;
92     }
93
94     /**
95      * @return DDC964Address
96      */
97     public function getAddress()
98     {
99         return $this->address;
100     }
101
102     /**
103      * @param DDC964Address $address
104      */
105     public function setAddress(DDC964Address $address)
106     {
107         $this->address = $address;
108     }
109
110     public static function loadMetadata($metadata)
111     {
112         $metadata->mapField(array(
113            'id'         => true,
114            'fieldName'  => 'id',
115            'type'       => 'integer',
116            'columnName' => 'user_id',
117            'length'     => 150,
118         ));
119         $metadata->mapField(array(
120             'fieldName' => 'name',
121             'type'      => 'string',
122             'columnName'=> 'user_name',
123             'nullable'  => true,
124             'unique'    => false,
125             'length'    => 250,
126         ));
127
128         $metadata->mapManyToOne(array(
129            'fieldName'      => 'address',
130            'targetEntity'   => 'DDC964Address',
131            'cascade'        => array('persist','merge'),
132            'joinColumn'     => array('name'=>'address_id', 'referencedColumnMame'=>'id'),
133         ));
134
135         $metadata->mapManyToMany(array(
136            'fieldName'      => 'groups',
137            'targetEntity'   => 'DDC964Group',
138            'inversedBy'     => 'users',
139            'cascade'        => array('persist','merge','detach'),
140            'joinTable'      => array(
141                 'name'          => 'ddc964_users_groups',
142                 'joinColumns'   => array(array(
143                     'name'=>'user_id',
144                     'referencedColumnName'=>'id',
145                 )),
146                 'inverseJoinColumns'=>array(array(
147                     'name'=>'group_id',
148                     'referencedColumnName'=>'id',
149                 ))
150            )
151         ));
152
153         $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadataInfo::GENERATOR_TYPE_AUTO);
154     }
155 }