Created
October 15, 2010 07:45
-
-
Save immutef/627791 to your computer and use it in GitHub Desktop.
Reflect the latest changes of Symfony2 and Doctrine2's Annotations (http://bit.ly/cGZbjw)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\MyBundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* @orm:Entity(repositoryClass="Application\MyBundle\Entity\UserRepository") | |
* @orm:Table(name="user", | |
* uniqueConstraints={ | |
* @orm:UniqueConstraint(name="username_idx", columns={"username"}), | |
* @orm:UniqueConstraint(name="email_idx", columns={"email"}) | |
* } | |
* ) | |
* @orm:HasLifecycleCallbacks | |
*/ | |
class User | |
{ | |
/** | |
* @orm:Column(name="id", type="integer") | |
* @orm:Id | |
* @orm:GeneratedValue(strategy="AUTO") | |
* @var integer | |
*/ | |
protected $id; | |
/** | |
* @orm:Column(name="username", type="string", length="32") | |
* @validation:Min(3) | |
* @validation:Max(32) | |
* @validation:NotBlank | |
* @var string | |
*/ | |
protected $username; | |
/** | |
* @orm:Column(name="email", type="string", length="256") | |
* @validation:Email | |
* @validation:NotBlank | |
* @var string | |
*/ | |
protected $email; | |
/** | |
* @orm:Column(name="password", type="string", length="32") | |
* @validation:NotBlank | |
* @var string | |
*/ | |
protected $password; | |
/** | |
* @orm:Column(name="activation_key", type="string", length="32") | |
* @var \DateTime | |
*/ | |
protected $activationKey; | |
/** | |
* @orm:Column(name="activation", type="datetime", nullable="true") | |
* @var \DateTime | |
*/ | |
protected $activation; | |
/** | |
* @orm:Column(name="last_login", type="datetime", nullable="true") | |
* @var \DateTime | |
*/ | |
protected $lastLogin; | |
/** | |
* @orm:Column(type="datetime") | |
* @validation:NotBlank | |
* @var \DateTime | |
*/ | |
protected $created; | |
/** | |
* @orm:Column(type="datetime") | |
* @validation:NotBlank | |
* @var \DateTime | |
*/ | |
protected $updated; | |
/** | |
* Constructor. | |
*/ | |
public function __construct() | |
{ | |
$this->created = $this->updated = new \DateTime('now'); | |
} | |
/** | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return string | |
*/ | |
public function __toString() | |
{ | |
return $this->getUsername(); | |
} | |
/** | |
* @return string | |
*/ | |
public function getUsername() | |
{ | |
return $this->username; | |
} | |
/** | |
* @param string $username | |
*/ | |
public function setUsername($username) | |
{ | |
$this->username = $username; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEmail() | |
{ | |
return $this->email; | |
} | |
/** | |
* @param string $email | |
*/ | |
public function setEmail($email) | |
{ | |
$this->email = $email; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
/** | |
* @param string $password | |
*/ | |
public function setPassword($password) | |
{ | |
$this->password = md5($password); | |
} | |
/** | |
* @param string $password | |
* @return boolean | |
*/ | |
public function checkPassword($password) | |
{ | |
return md5($password) == $this->password; | |
} | |
/** | |
* @return string | |
*/ | |
public function getActivationKey() | |
{ | |
return $this->activationKey; | |
} | |
/** | |
* @param string $activationKey | |
*/ | |
public function setActivationKey($activationKey) | |
{ | |
$this->activationKey = $activationKey; | |
} | |
/** | |
* @return string | |
*/ | |
public function generateActivationKey() | |
{ | |
return md5(sprintf('%s_%d_%s_%f', | |
$this->getUsername(), | |
rand(0, 99999), | |
$this->getEmail(), | |
microtime(true) | |
)); | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getActivation() | |
{ | |
return $this->activation; | |
} | |
/** | |
* @param \DateTime $activation | |
*/ | |
public function setActivation(\DateTime $activation) | |
{ | |
$this->activation = $activation; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function isActivated() | |
{ | |
return (boolean) $this->activation; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getLastLogin() | |
{ | |
return $this->lastLogin; | |
} | |
/** | |
* @param \DateTime $lastLogin | |
*/ | |
public function setLastLogin(\DateTime $lastLogin) | |
{ | |
$this->lastLogin = $lastLogin; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getLast_login() | |
{ | |
return $this->lastLogin; | |
} | |
/** | |
* @param \DateTime $last_login | |
*/ | |
public function setLast_login(\DateTime $last_login) | |
{ | |
$this->lastLogin = $last_login; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getCreated() | |
{ | |
return $this->created; | |
} | |
/** | |
* @param \DateTime $created | |
*/ | |
public function setCreated(\DateTime $created) | |
{ | |
$this->created = $created; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getUpdated() | |
{ | |
return $this->updated; | |
} | |
/** | |
* @param \DateTime $updated | |
*/ | |
public function setUpdated(\DateTime $updated) | |
{ | |
$this->updated = $updated; | |
} | |
/** | |
* @orm:PreUpdate | |
*/ | |
public function update() | |
{ | |
$this->updated = new \DateTime('now'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment