/**
  * Populates the object with data
  *
  * Passing in an associative array of data will populate this object without
  * hitting the database.
  *
  * Passing in a scalar will load the data from the database.
  * This will load all fields in the table as properties of this class.
  * You may want to replace this with, or add your own extra, custom loading
  *
  * @param int|string|array $id (ID, email, username)
  */
 public function __construct($id = null)
 {
     if ($id) {
         if (is_array($id)) {
             $this->data = $id;
         } else {
             if (ActiveRecord::isId($id)) {
                 $sql = 'select * from people where id=?';
             } elseif (false !== strpos($id, '@')) {
                 $sql = 'select * from people where email=?';
             } else {
                 $sql = 'select * from people where username=?';
             }
             $rows = parent::doQuery($sql, [$id]);
             if (count($rows)) {
                 $this->data = $rows[0];
             } else {
                 throw new \Exception('people/unknownPerson');
             }
         }
     } else {
         // This is where the code goes to generate a new, empty instance.
         // Set any default values for properties that need it here
         $this->setAuthenticationMethod('local');
     }
 }
Exemplo n.º 2
0
 /**
  * Populates the object with data
  *
  * Passing in an associative array of data will populate this object without
  * hitting the database.
  *
  * Passing in a scalar will load the data from the database.
  * This will load all fields in the table as properties of this class.
  * You may want to replace this with, or add your own extra, custom loading
  *
  * @param int|string|array $id (ID, email, username)
  */
 public function __construct($id = null)
 {
     if ($id) {
         if (is_array($id)) {
             $this->data = $id;
         } else {
             $sql = ActiveRecord::isId($id) ? 'select * from maps where id=?' : 'select * from maps where alias=?';
             $result = parent::doQuery($sql, [$id]);
             if (count($result)) {
                 $this->data = $result[0];
             } else {
                 throw new \Exception('maps/unknown');
             }
         }
     } else {
         // This is where the code goes to generate a new, empty instance.
         // Set any default values for properties that need it here
     }
 }