Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/models/User.php
2010-09-11 22:19:06 +02:00

118 lines
No EOL
2.4 KiB
PHP

<?php
/**
* User
*
*/
class User extends Fiktiv_Model_Abstract
{
protected $_id = 0;
protected $_email;
protected $_firstName;
protected $_lastName;
protected $_regDate;
protected $_isDeleted = false;
/**
* Set user email
*
* @return boolean
*/
public function setEmail($email)
{
$validator = new Zend_Validate_EmailAddress();
if ($validator->isValid($email)) {
$this->_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->_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->_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->_regDate = $date;
} else if ($date instanceof Zend_Date) {
$this->_regDate = $date->toString('yyyy-MM-dd');
} else {
return false;
}
return true;
}
/**
* 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->_isDeleted;
}
/**
* String representation of the object
* @return string
*/
public function __toString()
{
return '(' . __CLASS__ . '){' . $this->_email . ' ' . $this->_firstName . ' ' . $this->_lastName . '}';
}
}