Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Models / Company / CompanyPerson.php
1 <?php
2
3 namespace Doctrine\Tests\Models\Company;
4
5 /**
6  * Description of CompanyPerson
7  *
8  * @author robo
9  * @Entity
10  * @Table(name="company_persons")
11  * @InheritanceType("JOINED")
12  * @DiscriminatorColumn(name="discr", type="string")
13  * @DiscriminatorMap({
14  *      "person"    = "CompanyPerson",
15  *      "manager"   = "CompanyManager",
16  *      "employee"  = "CompanyEmployee"
17  * })
18  *
19  * @NamedNativeQueries({
20  *      @NamedNativeQuery(
21  *          name           = "fetchAllWithResultClass",
22  *          resultClass    = "__CLASS__",
23  *          query          = "SELECT id, name, discr FROM company_persons ORDER BY name"
24  *      ),
25  *      @NamedNativeQuery(
26  *          name            = "fetchAllWithSqlResultSetMapping",
27  *          resultSetMapping= "mappingFetchAll",
28  *          query           = "SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name"
29  *      )
30  * })
31  *
32  * @SqlResultSetMappings({
33  *      @SqlResultSetMapping(
34  *          name    = "mappingFetchAll",
35  *          entities= {
36  *              @EntityResult(
37  *                  entityClass         = "__CLASS__",
38  *                  discriminatorColumn = "discriminator",
39  *                  fields              = {
40  *                      @FieldResult("id"),
41  *                      @FieldResult("name"),
42  *                  }
43  *              )
44  *          }
45  *      )
46  * })
47  */
48 class CompanyPerson
49 {
50     /**
51      * @Id
52      * @Column(type="integer")
53      * @GeneratedValue
54      */
55     private $id;
56
57     /**
58      * @Column
59      */
60     private $name;
61
62     /**
63      * @OneToOne(targetEntity="CompanyPerson")
64      * @JoinColumn(name="spouse_id", referencedColumnName="id", onDelete="CASCADE")
65      */
66     private $spouse;
67
68     /**
69      * @ManyToMany(targetEntity="CompanyPerson")
70      * @JoinTable(
71      *     name="company_persons_friends",
72      *     joinColumns={
73      *         @JoinColumn(name="person_id", referencedColumnName="id", onDelete="CASCADE")
74      *     },
75      *     inverseJoinColumns={
76      *         @JoinColumn(name="friend_id", referencedColumnName="id", onDelete="CASCADE")
77      *     }
78      * )
79      */
80     private $friends;
81
82     public function __construct() {
83         $this->friends = new \Doctrine\Common\Collections\ArrayCollection;
84     }
85
86     public function getId() {
87         return  $this->id;
88     }
89
90     public function getName() {
91         return $this->name;
92     }
93
94     public function setName($name) {
95         $this->name = $name;
96     }
97
98     public function getSpouse() {
99         return $this->spouse;
100     }
101
102     public function getFriends() {
103         return $this->friends;
104     }
105
106     public function addFriend(CompanyPerson $friend) {
107         if ( ! $this->friends->contains($friend)) {
108             $this->friends->add($friend);
109             $friend->addFriend($this);
110         }
111     }
112
113     public function setSpouse(CompanyPerson $spouse) {
114         if ($spouse !== $this->spouse) {
115             $this->spouse = $spouse;
116             $this->spouse->setSpouse($this);
117         }
118     }
119
120     public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
121     {
122
123         $metadata->setPrimaryTable(array(
124            'name' => 'company_person',
125         ));
126
127         $metadata->addNamedNativeQuery(array (
128             'name'              => 'fetchAllWithResultClass',
129             'query'             => 'SELECT id, name, discr FROM company_persons ORDER BY name',
130             'resultClass'       => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson',
131         ));
132
133         $metadata->addNamedNativeQuery(array (
134             'name'              => 'fetchAllWithSqlResultSetMapping',
135             'query'             => 'SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name',
136             'resultSetMapping'  => 'mappingFetchAll',
137         ));
138
139         $metadata->addSqlResultSetMapping(array (
140             'name'      => 'mappingFetchAll',
141             'columns'   => array(),
142             'entities'  => array ( array (
143                 'fields' => array (
144                   array (
145                     'name'      => 'id',
146                     'column'    => 'id',
147                   ),
148                   array (
149                     'name'      => 'name',
150                     'column'    => 'name',
151                   ),
152                 ),
153                 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson',
154                 'discriminatorColumn' => 'discriminator',
155               ),
156             ),
157         ));
158     }
159 }
160