/** * 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->exchangeArray($id); } else { if (ActiveRecord::isId($id)) { $sql = 'select * from people where id=?'; } elseif (false !== strpos($id, '@')) { $sql = "select p.* from people p\n\t\t\t\t\t\t\tleft join peopleEmails e on p.id=e.person_id\n\t\t\t\t\t\t\twhere email=?"; } else { $sql = 'select * from people where username=?'; } $zend_db = Database::getConnection(); $result = $zend_db->createStatement($sql)->execute([$id]); if (count($result)) { $this->exchangeArray($result->current()); } 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'); } }
/** * 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'); } }
/** * 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|array $id */ public function __construct($id = null) { if ($id) { if (is_array($id)) { $this->exchangeArray($id); } else { $zend_db = Database::getConnection(); if (ActiveRecord::isId($id)) { $sql = 'select * from media where id=?'; } else { // Media internalFilenames include the original file extensions // However, the filename being requested may be for a generated thumbnail // We need to chop off the extension and do a wildcard search $filename = preg_replace('/[^.]+$/', '', $id); $id = "{$filename}%"; $sql = 'select * from media where internalFilename like ?'; } $result = $zend_db->createStatement($sql)->execute([$id]); if (count($result)) { $this->exchangeArray($result->current()); } else { throw new \Exception('media/unknownMedia'); } } } else { // This is where the code goes to generate a new, empty instance. // Set any default values for properties that need it here $this->setUploaded('now'); if (isset($_SESSION['USER'])) { $this->setPerson($_SESSION['USER']); } } }
/** * 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 } }
/** * 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|array $id */ public function __construct($id = null) { if ($id) { if (is_array($id)) { $this->exchangeArray($id); } else { $sql = ActiveRecord::isId($id) ? 'select * from categories where id=?' : 'select * from categories where name=?'; $zend_db = Database::getConnection(); $result = $zend_db->createStatement($sql)->execute([$id]); if (count($result)) { $this->exchangeArray($result->current()); } else { throw new \Exception('categories/unknownCategory'); } } } else { // This is where the code goes to generate a new, empty instance. // Set any default values for properties that need it here } }