Example #1
0
File: role.php Project: anqh/core
 /**
  * Load role
  *
  * @param  integer|string  $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     if ($id !== null) {
         $this->load(DB::select_array($this->fields())->where(is_numeric($id) ? 'id' : 'name', '=', $id));
     }
 }
Example #2
0
 public function __construct($id = NULL)
 {
     parent::__construct($id);
     if ($this->id) {
         $this->_order_products = $this->find_related('order_products')->as_array();
     }
 }
Example #3
0
File: user.php Project: anqh/anqh
 /**
  * Load user.
  *
  * @param  integer|string  $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     if ($id !== null) {
         if (is_numeric($id)) {
             // Load by id
             $this->load(DB::select_array($this->fields())->where('id', '=', $id));
         } else {
             // Load by username
             $this->load(DB::select_array($this->fields())->where('username_clean', '=', UTF8::strtolower($id)));
         }
     }
 }
Example #4
0
 /**
  * Constructor to load the object by an email address
  * 
  * @param mixed $id the id to load by. A numerical ID or an email address
  * 
  * @return null
  */
 public function __construct($id = NULL)
 {
     if (!is_numeric($id) and NULL != $id) {
         // try and get a row with this ID
         $data = db::select_array(array_keys($this->_data))->from($this->_table_name)->where('email', '=', $id)->execute($this->_db);
         // try and assign the data
         if (count($data) == 1 and $data = $data->current()) {
             foreach ($data as $key => $value) {
                 $this->_data[$key] = $value;
             }
         }
     } else {
         parent::__construct($id);
     }
 }
Example #5
0
File: photo.php Project: vendo/core
 /**
  * Overload __construct to load by a filename
  *
  * @return null
  */
 public function __construct($id = NULL)
 {
     if (!ctype_digit($id)) {
         parent::__construct();
         $id = basename($id);
         // try and get a row with this ID
         $data = db::select('*')->from($this->_table_name)->where('filename', '=', $id)->execute($this->_db);
         // try and assign the data
         if (count($data) == 1 and $data = $data->current()) {
             foreach ($data as $key => $value) {
                 $this->_data[$key] = $value;
             }
         }
     } else {
         parent::__construct($id);
     }
 }
Example #6
0
 /**
  * Load token
  *
  * @param  integer|string  $id
  */
 public function __construct($id = null)
 {
     parent::__construct();
     if ($id !== null) {
         $this->load(DB::select_array($this->fields())->where(is_numeric($id) ? 'id' : 'token', '=', $id));
         // Expired token?
         if ($this->loaded() && $this->expires < time()) {
             $this->delete();
         }
     }
     // Garbace collection
     /*
     if (mt_rand(1, 100) === 1) {
     	self::gc();
     }
     */
 }