Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / Models / CMS / CmsAddress.php
1 <?php
2
3 namespace Doctrine\Tests\Models\CMS;
4
5 /**
6  * CmsAddress
7  *
8  * @author Roman S. Borschel
9  * @Entity
10  * @Table(name="cms_addresses")
11  *
12  * @NamedNativeQueries({
13  *      @NamedNativeQuery(
14  *          name                = "find-all",
15  *          resultSetMapping    = "mapping-find-all",
16  *          query               = "SELECT id, country, city FROM cms_addresses"
17  *      ),
18  *      @NamedNativeQuery(
19  *          name           = "find-by-id",
20  *          resultClass    = "CmsAddress",
21  *          query          = "SELECT * FROM cms_addresses WHERE id = ?"
22  *      ),
23  *      @NamedNativeQuery(
24  *          name            = "count",
25  *          resultSetMapping= "mapping-count",
26  *          query           = "SELECT COUNT(*) AS count FROM cms_addresses"
27  *      )
28  * })
29  *
30  * @SqlResultSetMappings({
31  *      @SqlResultSetMapping(
32  *          name    = "mapping-find-all",
33  *          entities= {
34  *              @EntityResult(
35  *                  entityClass = "CmsAddress",
36  *                  fields      = {
37  *                      @FieldResult(name = "id",       column="id"),
38  *                      @FieldResult(name = "city",     column="city"),
39  *                      @FieldResult(name = "country",  column="country")
40  *                  }
41  *              )
42  *          }
43  *      ),
44  *      @SqlResultSetMapping(
45  *          name    = "mapping-without-fields",
46  *          entities= {
47  *              @EntityResult(
48  *                  entityClass = "__CLASS__"
49  *              )
50  *          }
51  *      ),
52  *      @SqlResultSetMapping(
53  *          name    = "mapping-count",
54  *          columns = {
55  *              @ColumnResult(
56  *                  name = "count"
57  *              )
58  *          }
59  *      )
60  * })
61  *
62  */
63 class CmsAddress
64 {
65     /**
66      * @Column(type="integer")
67      * @Id @GeneratedValue
68      */
69     public $id;
70
71     /**
72      * @Column(length=50)
73      */
74     public $country;
75
76     /**
77      * @Column(length=50)
78      */
79     public $zip;
80
81     /**
82      * @Column(length=50)
83      */
84     public $city;
85
86     /**
87      * Testfield for Schema Updating Tests.
88      */
89     public $street;
90
91     /**
92      * @OneToOne(targetEntity="CmsUser", inversedBy="address")
93      * @JoinColumn(referencedColumnName="id")
94      */
95     public $user;
96
97     public function getId() {
98         return $this->id;
99     }
100
101     public function getUser() {
102         return $this->user;
103     }
104
105     public function getCountry() {
106         return $this->country;
107     }
108
109     public function getZipCode() {
110         return $this->zip;
111     }
112
113     public function getCity() {
114         return $this->city;
115     }
116
117     public function setUser(CmsUser $user) {
118         if ($this->user !== $user) {
119             $this->user = $user;
120             $user->setAddress($this);
121         }
122     }
123
124     public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
125     {
126         $metadata->setPrimaryTable(array(
127            'name' => 'company_person',
128         ));
129
130         $metadata->addNamedNativeQuery(array (
131             'name'              => 'find-all',
132             'query'             => 'SELECT id, country, city FROM cms_addresses',
133             'resultSetMapping'  => 'mapping-find-all',
134         ));
135
136         $metadata->addNamedNativeQuery(array (
137             'name'              => 'find-by-id',
138             'query'             => 'SELECT * FROM cms_addresses WHERE id = ?',
139             'resultClass'       => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress',
140         ));
141
142         $metadata->addNamedNativeQuery(array (
143             'name'              => 'count',
144             'query'             => 'SELECT COUNT(*) AS count FROM cms_addresses',
145             'resultSetMapping'  => 'mapping-count',
146         ));
147
148
149         $metadata->addSqlResultSetMapping(array (
150             'name'      => 'mapping-find-all',
151             'columns'   => array(),
152             'entities'  => array ( array (
153                 'fields' => array (
154                   array (
155                     'name'      => 'id',
156                     'column'    => 'id',
157                   ),
158                   array (
159                     'name'      => 'city',
160                     'column'    => 'city',
161                   ),
162                   array (
163                     'name'      => 'country',
164                     'column'    => 'country',
165                   ),
166                 ),
167                 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress',
168               ),
169             ),
170         ));
171
172         $metadata->addSqlResultSetMapping(array (
173             'name'      => 'mapping-without-fields',
174             'columns'   => array(),
175             'entities'  => array(array (
176                 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress',
177                 'fields' => array()
178               )
179             )
180         ));
181
182         $metadata->addSqlResultSetMapping(array (
183             'name' => 'mapping-count',
184             'columns' =>array (
185                 array (
186                     'name' => 'count',
187                 ),
188             )
189         ));
190     }
191 }