/** * Get or create a token for this person_id for this app * @return array */ public function getOAuthToken() { $person_id = $this->person_id(); if (!$person_id) { static::error('User not specified.'); } if (!\person::exists($person_id)) { static::error('Invalid user.'); } $clause = array('person_id' => $person_id); if (!$this->app_key()) { $app_id = null; } else { $api_app = static::getApiAppByKey($this->app_key()); if (!$api_app) { static::error('Invalid app_key.'); } $app_id = $api_app->getID(); } $clause[static::getApiAppModelName() . '_id'] = $app_id; if (!$clause) { static::error('Unknown Identity.'); } $m = static::getOauthModelName(); $oauth = $m::getOne($clause); if (!$oauth || !$oauth->token) { $oauth = $m::insert($clause); } return array('oauth_token' => $oauth->token, 'issued' => $oauth->getTimeIssued(), 'now' => strtotime(\aql::now()), 'expires' => $oauth->getTimeExpires()); }
function save() { // Error-checking should already be complete if (person::exists($this->id)) { // UPDATE an existing database entry $query = "UPDATE people set " . "firstname = " . $this->firstname . ", " . "lastname = " . $this->lastname . ", " . "address_home_street_1 = " . $this->address_home_street_1 . ", " . "address_home_street_2 = " . $this->address_home_street_2 . ", " . "address_home_city = " . $this->address_home_city . ", " . "address_home_state = " . $this->address_home_state . ", " . "address_home_zip = " . $this->address_home_zip . ", " . "address_work_street_1 = " . $this->address_work_street_1 . ", " . "address_work_street_2 = " . $this->address_work_street_2 . ", " . "address_work_city = " . $this->address_work_city . ", " . "address_work_state = " . $this->address_work_state . ", " . "address_work_zip = " . $this->address_work_zip . ", " . "email = " . $this->email . ", " . "phone_personal_cell = " . $this->phone_personal_cell . ", " . "phone_work = " . $this->phone_work . ", " . "phone_work_cell = " . $this->phone_work_cell . ", " . "phone_home = " . $this->phone_home . ", " . "fax = " . $this->fax . ", " . "gender = " . $this->gender . ", " . "birthdate = " . $this->birthdate . ", " . "facebook_username = "******", " . "username = "******", " . "headshot_filename = " . $this->headshot_filename . " WHERE id = " . $this->id; $result = mydb::cxn()->query($query); if (mydb::cxn()->error != '') { throw new Exception('There was a problem updating ' . $this->firstname . ' ' . $this->lastname . '\'s database entry.'); } } else { // INSERT a new database entry $query = "INSERT INTO people (" . "firstname, " . "lastname, " . "address_home_street_1, " . "address_home_street_2, " . "address_home_city, " . "address_home_state, " . "address_home_zip, " . "address_work_street_1, " . "address_work_street_2, " . "address_work_city, " . "address_work_state, " . "address_work_zip, " . "email, " . "phone_personal_cell, " . "phone_home, " . "phone_work, " . "phone_work_cell, " . "fax, " . "gender, " . "birthdate, " . "facebook_username, " . "username, " . "headshot_filename) " . "VALUES (" . "'" . $this->firstname . "', " . "'" . $this->lastname . "', " . "'" . $this->address_home_ . "', " . "'" . $this->address_home_ . "', " . "'" . $this->address_home_ . "', " . "'" . $this->address_home_ . "', " . "'" . $this->address_home_ . "', " . "'" . $this->address_work_ . "', " . "'" . $this->address_work_ . "', " . "'" . $this->address_work_ . "', " . "'" . $this->address_work_ . "', " . "'" . $this->address_work_ . "', " . "'" . $this->email . "', " . "'" . $this->phone_personal_cell . "', " . "'" . $this->phone_home . "', " . "'" . $this->phone_work . "', " . "'" . $this->phone_work_cell . "', " . "'" . $this->fax . "', " . "'" . $this->gender . "', " . "'" . $this->birthdate->format('Y-m-d') . "', " . "'" . $this->facebook_username . "', " . "'" . $this->username . "', " . "'" . $this->headshot_filename . "')"; $result = mydb::cxn()->query($query); if (mydb::cxn()->error != '') { throw new Exception('There was a problem inserting ' . $this->firstname . ' ' . $this->lastname . '\'s database entry.'); } } }