Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract
- {
- protected $_name = 'users';
- private $id;
- private $username;
- private $password;
- private $created;
- private $modified;
- private $last_login;
- /**
- *
- * @param array $config calls the parent constructor
- */
- public function __construct($config = array()) {
- $this->id = null;
- $this->username = null;
- $this->password = null;
- $this->created = null;
- $this->modified = null;
- $this->last_login = null;
- parent::__construct($config);
- }
- /**
- *
- * @return integer // Returns the id of the current object
- */
- public function getId() {
- return $this->id;
- }
- /**
- *
- * @return integer // Returns the username of the current object
- */
- public function getUsername() {
- return $this->username;
- }
- /**
- *
- * @return string // Returns the password of the current object
- */
- public function getPassword() {
- return $this->password;
- }
- /**
- *
- * @return string // Returns the created date of the current object
- */
- public function getCreated() {
- return $this->created;
- }
- /**
- *
- * @return string // Returns the modified date of the current object
- */
- public function getModified() {
- return $this->modified;
- }
- /**
- *
- * @return string // Returns the last login date of the current object
- */
- public function getLastLogin() {
- return $this->last_login;
- }
- /**
- *
- * @param string $username // Sets the username property
- * @return boolean
- */
- public function setUsername($username = null) {
- if($username != null && is_string($username)) {
- $this->username = $username;
- return true;
- }
- else
- {
- return false;
- }
- }
- public function setPassword($password = null) {
- // make sure we are not null, we are a string, and we meet sha1 hash string lenghts
- if($password != null && is_string($password) && strlen($password) == 40) {
- $this->password = $password;
- return true;
- }
- else
- {
- return false;
- }
- }
- public function setModified() {
- $this->modified = date('Y-m-d h:i:s');
- }
- public function setLastLogin() {
- $this->last_login = date('Y-m-d h:i:s');
- }
- /**
- *
- * @param integer $id
- * @return boolean // true on success, false on failure
- */
- public function load($id = null) {
- if($id != null && is_numeric($id))
- {
- // load in the data from the database
- $data = $this->find($id);
- // return a Zend_Db_Table_Rowset object
- if($data->count())
- {
- $data = $data->toArray();
- $this->id = $data['id'];
- $this->username = $data['username'];
- $this->password = $data['password'];
- $this->created = $data['created'];
- $this->modified = $data['modified'];
- $this->last_login = date('Y-m-d h:i:s');
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- /**
- *
- * @return integer // represents the primary key of the new row in the database
- */
- public function saveUser()
- {
- $date = date('Y-m-d h:i:s'); // get the current date for created/modified values
- $data = array(); // we pass an array to $this->save()
- $data['username'] = $this->username; // get the username
- $data['password'] = $this->password; // get the password
- $this->created = $data['created'] = $date; // add the date
- $this->modified = $data['modified'] = $date; // add the date
- $this->id = $this->insert($data); // get the id of the newly inserted object
- return $this->id; // return the new id
- }
- /**
- *
- * @return integer // the number of rows updated
- */
- public function updateUser()
- {
- $date = date('Y-m-d h:i:s');
- $data = array();
- $data['username'] = $this->username;
- $data['password'] = $this->password;
- $data['modified'] = $date;
- $this->update($data, 'id = ' . $this->id); // call the parent
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement