hasOne('contact', 'Contact'); $this->hasOne('person', 'Person'); $this->hasMany('contacts', 'ContactInfo', 'contact_id', 'User', 'id'); $this->hasMany('prefs', 'UserPreference', 'user_id'); } public static function getInstance(PDO $dbh, Person $p = null, $username, $pass, $nf, $nl, $language_id) { $u = new User($dbh); $u->id = $u->getSequence(); $u->name = $name; $u->pass = sha1("$name$pass"); $u->language_id = $language_id; if (! $p) { $p = Person::getInstance($dbh, null, "$nf $nl", $nf, null, $nl, null, null); } $u->person_id = $p->id; $u->insert(); return $u; } /** * retrieve the User item specified by the given pk. * * @param int $id PK of the User to retrieve * * @throws ObjectNotFoundException if the requested row cannot be found * * @return User[] requested User * */ public static function find($input, PDO $dbh = null) { if (! $dbh) { $dbh = Dao::dbhS(); } if (is_numeric($input)) { return Dao::find($dbh, __CLASS__, $input); } return Dao::findByName($dbh, __CLASS__, $input, 'name'); } /** * retrieve all User items. * * @return User[] requested User * */ public static function findAll(PDO $dbh = null) { if (! $dbh) { $dbh = Dao::dbhS(); } return Dao::findAll($dbh, __CLASS__); } /** * retrieve all User items specified by the given pks. * * @param int[] $list list of PKs of User items to retrieve * * @throws ObjectNotFoundException if all requested rows cannot be found * * @return User[] requested User items * */ public static function findList(array $list) { if (! $dbh) { $dbh = Dao::dbhS(); } return Dao::findList($dbh, __CLASS__, $list); } public static function authenticate($username, $password) { $list = Dao::findWhere(Dao::dbhS(), __CLASS__, array('name' => $username, 'password' => $password)); if (count($list)) { return array_shift($list); } return null; } public function nameFull() { return $this->person()->nameFull(); } /** * Return true if a value for the requested preference exists. * * @param Preference $p * @return boolean true if the pref has a value; false otherwise */ public function hasPref(Preference $p) { foreach ($this->prefs() as $pref) { if ($pref->preference_id == $p->id) { return true; } } return false; } /** * Retrieve a preference value. * * @param Preference $p * @return string value of the requested preference, or null. */ public function pref(Preference $p) { foreach ($this->prefs() as $pref) { if ($pref->preference_id == $p->id) { return $pref->value; } } return null; } }