169 lines
No EOL
3.5 KiB
PHP
169 lines
No EOL
3.5 KiB
PHP
<?php
|
|
/**
|
|
* User
|
|
*
|
|
*/
|
|
class User extends Fiktiv_Model_Abstract
|
|
{
|
|
protected $_data = array();
|
|
|
|
protected $_default = array(
|
|
'id' => 0,
|
|
'email' => null,
|
|
'firstName' => null,
|
|
'lastName' => null,
|
|
'regDate' => null,
|
|
'isDeleted' => false
|
|
);
|
|
|
|
public function setId($id)
|
|
{
|
|
if (is_numeric($id))
|
|
$this->_data['id'] = $id;
|
|
}
|
|
|
|
/**
|
|
* Set user email
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function setEmail($email)
|
|
{
|
|
$validator = new Zend_Validate_EmailAddress();
|
|
|
|
if ($validator->isValid($email)) {
|
|
$this->_data['email'] = $email;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set user lastname
|
|
*
|
|
* @param string $name
|
|
* @return boolean
|
|
*/
|
|
public function setLastName($name)
|
|
{
|
|
if (is_string($name) && preg_match('/^[A-ö\ \.\-]{0,20}$/', $name)) {
|
|
$this->_data['lastName'] = $name;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set user firstname
|
|
*
|
|
* @param string $name
|
|
* @return boolean
|
|
*/
|
|
public function setFirstName($name)
|
|
{
|
|
$name = trim($name);
|
|
|
|
if (is_string($name) && preg_match('/^[A-ö]{2,8}\-?[A-ö]{2,8}$/', $name)) {
|
|
$this->_data['firstName'] = $name;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set the user registration date
|
|
*
|
|
* @param Zend_Date | string $date
|
|
* @return boolean
|
|
*/
|
|
public function setRegDate($date)
|
|
{
|
|
if (is_string($date) && preg_match('/^(?:(?:19[0-9]{2})|(?:20[0-9]{2}))\-' .
|
|
'(?:(?:0[1-9])|(?:1[012]))\-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/', $date)) {
|
|
|
|
$this->_data['regDate'] = $date;
|
|
} else if ($date instanceof Zend_Date) {
|
|
|
|
$this->_data['regDate'] = $date->toString('yyyy-MM-dd');
|
|
} else {
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function setPassword($password)
|
|
{
|
|
if (!is_string($password))
|
|
throw new Fiktiv_Exception('password must be string');
|
|
|
|
Fiktiv_Data_Service::getInstance()->User->setPassword($this, $password);
|
|
}
|
|
|
|
/**
|
|
* Returns the user registration date
|
|
*
|
|
* @return string $_regDate
|
|
*/
|
|
public function userSince()
|
|
{
|
|
return !empty($_regDate) ? $_regDate : false;
|
|
}
|
|
|
|
/**
|
|
* Returns the current status of the account.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function isActive()
|
|
{
|
|
return !$this->_data['isDeleted'];
|
|
}
|
|
|
|
/**
|
|
* String representation of the object
|
|
* @return string
|
|
*/
|
|
public function __toString()
|
|
{
|
|
return '(' . __CLASS__ . '){' . $this->_data['email'] . ', ' . $this->_data['firstName'] . ' ' . $this->_data['lastName'] . '}';
|
|
}
|
|
|
|
/**
|
|
* Convert object to array
|
|
*/
|
|
public function toArray()
|
|
{
|
|
return $this->_data;
|
|
}
|
|
|
|
/**
|
|
* Load user data from database (restore last saved)
|
|
*/
|
|
public function reload()
|
|
{
|
|
$userData = Fiktiv_Data_Service::getInstance()->User->findById($this->getId());
|
|
|
|
if ($userData instanceof User) {
|
|
|
|
$this->setAttribs($userData->toArray());
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Save User
|
|
*/
|
|
public function save()
|
|
{
|
|
return Fiktiv_Data_Service::getInstance()->User->save($this);
|
|
}
|
|
} |