2008-02-08 23:20:35 +00:00
< ? php
2008-07-20 20:13:24 +00:00
2009-01-22 19:38:10 +00:00
namespace Doctrine\Tests\Models\CMS ;
2008-07-20 20:13:24 +00:00
2009-07-29 11:57:27 +00:00
use Doctrine\Common\Collections\ArrayCollection ;
2009-07-28 16:36:24 +00:00
2009-01-05 17:25:56 +00:00
/**
2009-05-29 10:23:13 +00:00
* @ Entity
* @ Table ( name = " cms_users " )
2011-03-06 18:45:09 -03:00
* @ NamedQueries ({
* @ NamedQuery ( name = " all " , query = " SELECT u FROM __CLASS__ u " )
* })
2012-02-27 21:16:35 -03:00
*
* @ NamedNativeQueries ({
* @ NamedNativeQuery (
* name = " fetchIdAndUsernameWithResultClass " ,
* resultClass = " CmsUser " ,
* query = " SELECT id, username FROM cms_users WHERE username = ? "
* ),
* @ NamedNativeQuery (
* name = " fetchAllColumnsWithResultClass " ,
* resultClass = " CmsUser " ,
* query = " SELECT * FROM cms_users WHERE username = ? "
* ),
2012-02-27 23:46:27 -03:00
* @ NamedNativeQuery (
* name = " fetchJoinedAddressWithResultSetMapping " ,
* 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 (
* name = " fetchJoinedPhonenumberWithResultSetMapping " ,
* resultSetMapping = " mappingJoinedPhonenumber " ,
* query = " SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ? "
* ),
* })
*
* @ 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 = {
* @ FieldResult ( name = " id " ),
* @ FieldResult ( name = " name " ),
* @ FieldResult ( name = " status " ),
* @ FieldResult ( name = " phonenumbers.phonenumber " , column = " number " ),
* }
* )
* }
* )
2012-02-27 21:16:35 -03:00
* })
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
class CmsUser
2008-02-08 23:20:35 +00:00
{
2009-01-05 17:25:56 +00:00
/**
2009-05-29 10:23:13 +00:00
* @ Id @ Column ( type = " integer " )
2010-02-09 17:13:49 +00:00
* @ GeneratedValue
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $id ;
2009-01-05 17:25:56 +00:00
/**
2011-10-17 18:54:20 +02:00
* @ Column ( type = " string " , length = 50 , nullable = true )
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $status ;
2009-01-05 17:25:56 +00:00
/**
2009-09-08 18:12:01 +00:00
* @ Column ( type = " string " , length = 255 , unique = true )
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $username ;
2009-01-05 17:25:56 +00:00
/**
2009-05-29 10:23:13 +00:00
* @ Column ( type = " string " , length = 255 )
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $name ;
2009-01-05 17:25:56 +00:00
/**
2011-09-06 01:58:16 -03:00
* @ OneToMany ( targetEntity = " CmsPhonenumber " , mappedBy = " user " , cascade = { " persist " , " merge " }, orphanRemoval = true )
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $phonenumbers ;
2009-01-05 17:25:56 +00:00
/**
2011-08-14 16:12:12 +02:00
* @ OneToMany ( targetEntity = " CmsArticle " , mappedBy = " user " , cascade = { " detach " })
2009-01-05 17:25:56 +00:00
*/
2008-12-18 14:08:11 +00:00
public $articles ;
2009-02-02 11:55:50 +00:00
/**
2010-07-08 00:20:54 +02:00
* @ OneToOne ( targetEntity = " CmsAddress " , mappedBy = " user " , cascade = { " persist " }, orphanRemoval = true )
2009-02-02 11:55:50 +00:00
*/
public $address ;
2011-09-07 13:12:02 -03:00
/**
* @ OneToOne ( targetEntity = " CmsEmail " , inversedBy = " user " , cascade = { " persist " }, orphanRemoval = true )
* @ JoinColumn ( referencedColumnName = " id " , nullable = true )
*/
public $email ;
2009-02-04 16:35:36 +00:00
/**
2011-08-14 16:12:12 +02:00
* @ ManyToMany ( targetEntity = " CmsGroup " , inversedBy = " users " , cascade = { " persist " , " merge " , " detach " })
2009-05-29 10:23:13 +00:00
* @ JoinTable ( name = " cms_users_groups " ,
2009-07-28 16:36:24 +00:00
* joinColumns = { @ JoinColumn ( name = " user_id " , referencedColumnName = " id " )},
* inverseJoinColumns = { @ JoinColumn ( name = " group_id " , referencedColumnName = " id " )}
* )
2009-02-04 16:35:36 +00:00
*/
public $groups ;
2011-12-19 22:56:19 +01:00
2011-11-02 12:34:28 +01:00
public $nonPersistedProperty ;
public $nonPersistedPropertyObject ;
2009-07-28 16:36:24 +00:00
public function __construct () {
2009-07-29 11:57:27 +00:00
$this -> phonenumbers = new ArrayCollection ;
$this -> articles = new ArrayCollection ;
$this -> groups = new ArrayCollection ;
2009-07-28 16:36:24 +00:00
}
2009-01-09 16:25:06 +00:00
2009-05-11 10:43:27 +00: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 16:25:06 +00:00
/**
* Adds a phonenumber to the user .
*
2009-02-02 11:55:50 +00:00
* @ param CmsPhonenumber $phone
2009-01-09 16:25:06 +00:00
*/
public function addPhonenumber ( CmsPhonenumber $phone ) {
$this -> phonenumbers [] = $phone ;
2009-07-02 11:48:44 +00:00
$phone -> setUser ( $this );
2009-01-09 16:25:06 +00:00
}
2009-01-29 17:00:44 +00:00
2009-05-11 10:43:27 +00:00
public function getPhonenumbers () {
return $this -> phonenumbers ;
}
2009-04-09 18:12:48 +00:00
public function addArticle ( CmsArticle $article ) {
$this -> articles [] = $article ;
2009-07-02 11:48:44 +00:00
$article -> setAuthor ( $this );
2009-05-07 13:54:01 +00:00
}
public function addGroup ( CmsGroup $group ) {
$this -> groups [] = $group ;
$group -> addUser ( $this );
}
public function getGroups () {
return $this -> groups ;
2009-04-09 18:12:48 +00:00
}
2009-01-29 17:00:44 +00: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-19 22:56:19 +01:00
2009-10-07 12:39:46 +00:00
public function getAddress () { return $this -> address ; }
2011-12-19 22:56:19 +01:00
2009-10-01 12:00:14 +00:00
public function setAddress ( CmsAddress $address ) {
if ( $this -> address !== $address ) {
$this -> address = $address ;
$address -> setUser ( $this );
}
}
2011-12-19 22:56:19 +01:00
2011-09-07 13:12:02 -03:00
public function getEmail () { return $this -> email ; }
2011-12-19 22:56:19 +01:00
2011-09-07 13:12:02 -03:00
public function setEmail ( CmsEmail $email = null ) {
if ( $this -> email !== $email ) {
$this -> email = $email ;
2011-12-19 22:56:19 +01:00
2011-09-07 13:12:02 -03:00
if ( $email ) {
$email -> setUser ( $this );
}
}
}
2008-02-15 00:57:34 +00:00
}