2008-02-09 02:20:35 +03:00
< ? php
2008-07-21 00:13:24 +04:00
2009-01-22 22:38:10 +03:00
namespace Doctrine\Tests\Models\CMS ;
2008-07-21 00:13:24 +04:00
2009-07-29 15:57:27 +04:00
use Doctrine\Common\Collections\ArrayCollection ;
2009-07-28 20:36:24 +04:00
2009-01-05 20:25:56 +03:00
/**
2009-05-29 14:23:13 +04:00
* @ Entity
* @ Table ( name = " cms_users " )
2011-03-07 00:45:09 +03:00
* @ NamedQueries ({
* @ NamedQuery ( name = " all " , query = " SELECT u FROM __CLASS__ u " )
* })
2012-02-28 04:16:35 +04:00
*
* @ NamedNativeQueries ({
* @ NamedNativeQuery (
* name = " fetchIdAndUsernameWithResultClass " ,
* resultClass = " CmsUser " ,
* query = " SELECT id, username FROM cms_users WHERE username = ? "
* ),
* @ NamedNativeQuery (
2012-02-29 05:18:25 +04:00
* name = " fetchAllColumns " ,
2012-02-28 04:16:35 +04:00
* resultClass = " CmsUser " ,
* query = " SELECT * FROM cms_users WHERE username = ? "
* ),
2012-02-28 06:46:27 +04:00
* @ NamedNativeQuery (
2012-02-29 05:18:25 +04:00
* name = " fetchJoinedAddress " ,
2012-02-28 06:46:27 +04:00
* resultSetMapping = " mappingJoinedAddress " ,
* query = " SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ? "
* ),
* @ NamedNativeQuery (
2012-02-29 05:18:25 +04:00
* name = " fetchJoinedPhonenumber " ,
2012-02-28 06:46:27 +04:00
* resultSetMapping = " mappingJoinedPhonenumber " ,
* query = " SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ? "
* ),
2012-02-29 05:18:25 +04:00
* @ NamedNativeQuery (
* name = " fetchUserPhonenumberCount " ,
* resultSetMapping = " mappingUserPhonenumberCount " ,
2012-02-29 06:46:28 +04:00
* query = " SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username "
2012-02-29 05:18:25 +04:00
* ),
2012-03-11 19:10:15 +04:00
* @ NamedNativeQuery (
* name = " fetchMultipleJoinsEntityResults " ,
* resultSetMapping = " mappingMultipleJoinsEntityResults " ,
* query = " SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username "
* ),
2012-02-28 06:46:27 +04:00
* })
*
* @ SqlResultSetMappings ({
* @ SqlResultSetMapping (
* name = " mappingJoinedAddress " ,
* entities = {
* @ EntityResult (
* entityClass = " __CLASS__ " ,
* fields = {
* @ FieldResult ( name = " id " ),
* @ FieldResult ( name = " name " ),
* @ FieldResult ( name = " status " ),
* @ FieldResult ( name = " address.zip " ),
* @ FieldResult ( name = " address.city " ),
* @ FieldResult ( name = " address.country " ),
* @ FieldResult ( name = " address.id " , column = " a_id " ),
* }
* )
* }
* ),
* @ SqlResultSetMapping (
* name = " mappingJoinedPhonenumber " ,
* entities = {
* @ EntityResult (
* entityClass = " CmsUser " ,
* fields = {
2012-02-29 05:18:25 +04:00
* @ FieldResult ( " id " ),
* @ FieldResult ( " name " ),
* @ FieldResult ( " status " ),
* @ FieldResult ( " phonenumbers.phonenumber " , column = " number " ),
* }
* )
* }
* ),
* @ SqlResultSetMapping (
* name = " mappingUserPhonenumberCount " ,
* entities = {
* @ EntityResult (
* entityClass = " CmsUser " ,
* fields = {
2012-02-28 06:46:27 +04:00
* @ FieldResult ( name = " id " ),
* @ FieldResult ( name = " name " ),
* @ FieldResult ( name = " status " ),
* }
* )
2012-02-29 05:18:25 +04:00
* },
* columns = {
2012-02-29 06:46:28 +04:00
* @ ColumnResult ( " numphones " )
2012-02-28 06:46:27 +04:00
* }
2012-03-11 19:10:15 +04:00
* ),
* @ SqlResultSetMapping (
* name = " mappingMultipleJoinsEntityResults " ,
* entities = {
* @ EntityResult (
* entityClass = " __CLASS__ " ,
* fields = {
* @ FieldResult ( name = " id " , column = " u_id " ),
* @ FieldResult ( name = " name " , column = " u_name " ),
* @ FieldResult ( name = " status " , column = " u_status " ),
* }
* ),
* @ EntityResult (
* entityClass = " CmsAddress " ,
* fields = {
* @ FieldResult ( name = " id " , column = " a_id " ),
* @ FieldResult ( name = " zip " , column = " a_zip " ),
* @ FieldResult ( name = " country " , column = " a_country " ),
* }
* )
* },
* columns = {
* @ ColumnResult ( " numphones " )
* }
2012-02-28 06:46:27 +04:00
* )
2012-02-28 04:16:35 +04:00
* })
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
class CmsUser
2008-02-09 02:20:35 +03:00
{
2009-01-05 20:25:56 +03:00
/**
2009-05-29 14:23:13 +04:00
* @ Id @ Column ( type = " integer " )
2010-02-09 20:13:49 +03:00
* @ GeneratedValue
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $id ;
2009-01-05 20:25:56 +03:00
/**
2011-10-17 20:54:20 +04:00
* @ Column ( type = " string " , length = 50 , nullable = true )
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $status ;
2009-01-05 20:25:56 +03:00
/**
2009-09-08 22:12:01 +04:00
* @ Column ( type = " string " , length = 255 , unique = true )
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $username ;
2009-01-05 20:25:56 +03:00
/**
2009-05-29 14:23:13 +04:00
* @ Column ( type = " string " , length = 255 )
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $name ;
2009-01-05 20:25:56 +03:00
/**
2011-09-06 08:58:16 +04:00
* @ OneToMany ( targetEntity = " CmsPhonenumber " , mappedBy = " user " , cascade = { " persist " , " merge " }, orphanRemoval = true )
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $phonenumbers ;
2009-01-05 20:25:56 +03:00
/**
2011-08-14 18:12:12 +04:00
* @ OneToMany ( targetEntity = " CmsArticle " , mappedBy = " user " , cascade = { " detach " })
2009-01-05 20:25:56 +03:00
*/
2008-12-18 17:08:11 +03:00
public $articles ;
2009-02-02 14:55:50 +03:00
/**
2010-07-08 02:20:54 +04:00
* @ OneToOne ( targetEntity = " CmsAddress " , mappedBy = " user " , cascade = { " persist " }, orphanRemoval = true )
2009-02-02 14:55:50 +03:00
*/
public $address ;
2011-09-07 20:12:02 +04:00
/**
* @ OneToOne ( targetEntity = " CmsEmail " , inversedBy = " user " , cascade = { " persist " }, orphanRemoval = true )
* @ JoinColumn ( referencedColumnName = " id " , nullable = true )
*/
public $email ;
2009-02-04 19:35:36 +03:00
/**
2011-08-14 18:12:12 +04:00
* @ ManyToMany ( targetEntity = " CmsGroup " , inversedBy = " users " , cascade = { " persist " , " merge " , " detach " })
2009-05-29 14:23:13 +04:00
* @ 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 " )}
* )
2009-02-04 19:35:36 +03:00
*/
public $groups ;
2011-12-20 01:56:19 +04:00
2011-11-02 15:34:28 +04:00
public $nonPersistedProperty ;
public $nonPersistedPropertyObject ;
2009-07-28 20:36:24 +04:00
public function __construct () {
2009-07-29 15:57:27 +04:00
$this -> phonenumbers = new ArrayCollection ;
$this -> articles = new ArrayCollection ;
$this -> groups = new ArrayCollection ;
2009-07-28 20:36:24 +04:00
}
2009-01-09 19:25:06 +03:00
2009-05-11 14:43:27 +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 ;
}
2009-01-09 19:25:06 +03:00
/**
* Adds a phonenumber to the user .
*
2009-02-02 14:55:50 +03:00
* @ param CmsPhonenumber $phone
2009-01-09 19:25:06 +03:00
*/
public function addPhonenumber ( CmsPhonenumber $phone ) {
$this -> phonenumbers [] = $phone ;
2009-07-02 15:48:44 +04:00
$phone -> setUser ( $this );
2009-01-09 19:25:06 +03:00
}
2009-01-29 20:00:44 +03:00
2009-05-11 14:43:27 +04:00
public function getPhonenumbers () {
return $this -> phonenumbers ;
}
2009-04-09 22:12:48 +04:00
public function addArticle ( CmsArticle $article ) {
$this -> articles [] = $article ;
2009-07-02 15:48:44 +04:00
$article -> setAuthor ( $this );
2009-05-07 17:54:01 +04:00
}
public function addGroup ( CmsGroup $group ) {
$this -> groups [] = $group ;
$group -> addUser ( $this );
}
public function getGroups () {
return $this -> groups ;
2009-04-09 22:12:48 +04:00
}
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 ;
}
2011-12-20 01:56:19 +04:00
2009-10-07 16:39:46 +04:00
public function getAddress () { return $this -> address ; }
2011-12-20 01:56:19 +04:00
2009-10-01 16:00:14 +04:00
public function setAddress ( CmsAddress $address ) {
if ( $this -> address !== $address ) {
$this -> address = $address ;
$address -> setUser ( $this );
}
}
2011-12-20 01:56:19 +04:00
2011-09-07 20:12:02 +04:00
public function getEmail () { return $this -> email ; }
2011-12-20 01:56:19 +04:00
2011-09-07 20:12:02 +04:00
public function setEmail ( CmsEmail $email = null ) {
if ( $this -> email !== $email ) {
$this -> email = $email ;
2011-12-20 01:56:19 +04:00
2011-09-07 20:12:02 +04:00
if ( $email ) {
$email -> setUser ( $this );
}
}
}
2012-03-10 07:04:46 +04:00
public static function loadMetadata ( \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata )
{
$metadata -> setPrimaryTable ( array (
'name' => 'cms_users' ,
));
$metadata -> addNamedNativeQuery ( array (
'name' => 'fetchIdAndUsernameWithResultClass' ,
'query' => 'SELECT id, username FROM cms_users WHERE username = ?' ,
'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser' ,
));
$metadata -> addNamedNativeQuery ( array (
'name' => 'fetchAllColumns' ,
'query' => 'SELECT * FROM cms_users WHERE username = ?' ,
'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser' ,
));
$metadata -> addNamedNativeQuery ( array (
'name' => 'fetchJoinedAddress' ,
'query' => 'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?' ,
'resultSetMapping' => 'mappingJoinedAddress' ,
));
$metadata -> addNamedNativeQuery ( array (
'name' => 'fetchJoinedPhonenumber' ,
'query' => 'SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?' ,
'resultSetMapping' => 'mappingJoinedPhonenumber' ,
));
$metadata -> addNamedNativeQuery ( array (
'name' => 'fetchUserPhonenumberCount' ,
'query' => 'SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username' ,
'resultSetMapping' => 'mappingUserPhonenumberCount' ,
));
2012-03-11 19:10:15 +04:00
$metadata -> addNamedNativeQuery ( array (
" name " => " fetchMultipleJoinsEntityResults " ,
" resultSetMapping " => " mappingMultipleJoinsEntityResults " ,
" query " => " SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id INNER JOIN cms_phonenumbers p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username "
));
2012-03-10 07:04:46 +04:00
$metadata -> addSqlResultSetMapping ( array (
'name' => 'mappingJoinedAddress' ,
'columns' => array (),
'entities' => array ( array (
'fields' => array (
array (
'name' => 'id' ,
'column' => 'id' ,
),
array (
'name' => 'name' ,
'column' => 'name' ,
),
array (
'name' => 'status' ,
'column' => 'status' ,
),
array (
'name' => 'address.zip' ,
'column' => 'zip' ,
),
array (
'name' => 'address.city' ,
'column' => 'city' ,
),
array (
'name' => 'address.country' ,
'column' => 'country' ,
),
array (
'name' => 'address.id' ,
'column' => 'a_id' ,
),
),
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser' ,
'discriminatorColumn' => null
),
),
));
$metadata -> addSqlResultSetMapping ( array (
'name' => 'mappingJoinedPhonenumber' ,
'columns' => array (),
'entities' => array ( array (
'fields' => array (
array (
'name' => 'id' ,
'column' => 'id' ,
),
array (
'name' => 'name' ,
'column' => 'name' ,
),
array (
'name' => 'status' ,
'column' => 'status' ,
),
array (
'name' => 'phonenumbers.phonenumber' ,
'column' => 'number' ,
),
),
'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser' ,
'discriminatorColumn' => null
),
),
));
$metadata -> addSqlResultSetMapping ( array (
'name' => 'mappingUserPhonenumberCount' ,
'columns' => array (),
'entities' => array (
array (
'fields' => array (
array (
'name' => 'id' ,
'column' => 'id' ,
),
array (
'name' => 'name' ,
'column' => 'name' ,
),
array (
'name' => 'status' ,
'column' => 'status' ,
)
),
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser' ,
'discriminatorColumn' => null
)
),
'columns' => array (
array (
'name' => 'numphones' ,
)
)
));
2012-03-11 19:10:15 +04:00
$metadata -> addSqlResultSetMapping ( array (
'name' => 'mappingMultipleJoinsEntityResults' ,
'entities' => array ( array (
'fields' => array (
array (
'name' => 'id' ,
'column' => 'u_id' ,
),
array (
'name' => 'name' ,
'column' => 'u_name' ,
),
array (
'name' => 'status' ,
'column' => 'u_status' ,
)
),
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser' ,
'discriminatorColumn' => null ,
),
array (
'fields' => array (
array (
'name' => 'id' ,
'column' => 'a_id' ,
),
array (
'name' => 'zip' ,
'column' => 'a_zip' ,
),
array (
'name' => 'country' ,
'column' => 'a_country' ,
),
),
'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress' ,
'discriminatorColumn' => null ,
),
),
'columns' => array ( array (
'name' => 'numphones' ,
)
)
));
2012-03-10 07:04:46 +04:00
}
2008-02-15 03:57:34 +03:00
}