Advertisement
Guest User

Untitled

a guest
May 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.60 KB | None | 0 0
  1. <?php
  2.  
  3. class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract
  4. {
  5.     protected $_name = 'users';
  6.     private $id;
  7.     private $username;
  8.     private $password;
  9.     private $created;
  10.     private $modified;
  11.     private $last_login;
  12.  
  13.     /**
  14.      *
  15.      * @param array $config calls the parent constructor
  16.      */
  17.     public function  __construct($config = array()) {
  18.         $this->id = null;
  19.         $this->username = null;
  20.         $this->password = null;
  21.         $this->created = null;
  22.         $this->modified = null;
  23.         $this->last_login = null;
  24.        
  25.         parent::__construct($config);
  26.     }
  27.  
  28.     /**
  29.      *
  30.      * @return integer // Returns the id of the current object
  31.      */
  32.     public function getId() {
  33.         return $this->id;
  34.     }
  35.  
  36.     /**
  37.      *
  38.      * @return integer // Returns the username of the current object
  39.      */
  40.     public function getUsername() {
  41.         return $this->username;
  42.     }
  43.  
  44.     /**
  45.      *
  46.      * @return string // Returns the password of the current object
  47.      */
  48.     public function getPassword() {
  49.         return $this->password;
  50.     }
  51.  
  52.     /**
  53.      *
  54.      * @return string // Returns the created date of the current object
  55.      */
  56.     public function getCreated() {
  57.         return $this->created;
  58.     }
  59.  
  60.     /**
  61.      *
  62.      * @return string // Returns the modified date of the current object
  63.      */
  64.     public function getModified() {
  65.         return $this->modified;
  66.     }
  67.  
  68.     /**
  69.      *
  70.      * @return string // Returns the last login date of the current object
  71.      */
  72.     public function getLastLogin() {
  73.         return $this->last_login;
  74.     }
  75.  
  76.     /**
  77.      *
  78.      * @param string $username // Sets the username property
  79.      * @return boolean
  80.      */
  81.     public function setUsername($username = null) {
  82.         if($username != null && is_string($username)) {
  83.             $this->username = $username;
  84.             return true;
  85.         }
  86.         else
  87.         {
  88.             return false;
  89.         }
  90.     }
  91.  
  92.     public function setPassword($password = null) {
  93.         // make sure we are not null, we are a string, and we meet sha1 hash string lenghts
  94.         if($password != null && is_string($password) && strlen($password) == 40) {
  95.             $this->password = $password;
  96.             return true;
  97.         }
  98.         else
  99.         {
  100.             return false;
  101.         }
  102.     }
  103.  
  104.     public function setModified() {
  105.         $this->modified = date('Y-m-d h:i:s');
  106.     }
  107.  
  108.     public function setLastLogin() {
  109.         $this->last_login = date('Y-m-d h:i:s');
  110.     }
  111.  
  112.     /**
  113.      *
  114.      * @param integer $id
  115.      * @return boolean // true on success, false on failure
  116.      */
  117.     public function load($id = null) {
  118.         if($id != null && is_numeric($id))
  119.         {
  120.             // load in the data from the database
  121.             $data = $this->find($id);
  122.             // return a Zend_Db_Table_Rowset object
  123.             if($data->count())
  124.             {
  125.                 $data = $data->toArray();
  126.                 $this->id = $data['id'];
  127.                 $this->username = $data['username'];
  128.                 $this->password = $data['password'];
  129.                 $this->created = $data['created'];
  130.                 $this->modified = $data['modified'];
  131.                 $this->last_login = date('Y-m-d h:i:s');
  132.  
  133.                 return true;
  134.             }
  135.             else
  136.             {
  137.                 return false;
  138.             }
  139.         }
  140.         else
  141.         {
  142.             return false;
  143.         }
  144.     }
  145.  
  146.     /**
  147.      *
  148.      * @return integer // represents the primary key of the new row in the database
  149.      */
  150.     public function saveUser()
  151.     {
  152.         $date = date('Y-m-d h:i:s'); // get the current date for created/modified values
  153.         $data = array(); // we pass an array to $this->save()
  154.         $data['username'] = $this->username; // get the username
  155.         $data['password'] = $this->password; // get the password
  156.         $this->created = $data['created'] = $date; // add the date
  157.         $this->modified = $data['modified'] = $date; // add the date
  158.  
  159.         $this->id = $this->insert($data); // get the id of the newly inserted object
  160.         return $this->id; // return the new id
  161.     }
  162.  
  163.     /**
  164.      *
  165.      * @return integer // the number of rows updated
  166.      */
  167.     public function updateUser()
  168.     {
  169.         $date = date('Y-m-d h:i:s');
  170.         $data = array();
  171.         $data['username'] = $this->username;
  172.         $data['password'] = $this->password;
  173.         $data['modified'] = $date;
  174.         $this->update($data, 'id = ' . $this->id); // call the parent
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement