public function sendInvitation() { // fetch the newly invited user $users = new Table('users'); $user = $users->findFirst('id DESC')->where(array('role' => 'invited')); // have we actually retrieved the user? if (!Fari_Filter::isInt($user->id)) { throw new UserNotFoundException(); } // form the email $this->mailer->addTo($user->email)->addFrom('*****@*****.**', 'Clubhouse'); $this->mailer->setSubject('You\'re invited to join Clubhouse'); $this->mailer->setBody("Hi {$user->first},\nYou're invited to join Clubhouse, our group chat system.\n\n" . "Click this link to get started:\n" . url('account/invitation/' . $user->invitation . '/', FALSE, TRUE) . "\n\nThanks"); //$this->mailer->send(); }
/** * Validates uniqueness of a column value in a table. * @param Table $table object * @throws Fari_DbTableValidatorException */ private function validateUniquenessOf(Table &$table) { assert('is_array($table->validatesUniquenessOf); // needs to be an array'); foreach ($table->validatesUniquenessOf as $column) { // exists? if (!array_key_exists($column, $table->data)) { throw new TableException("'{$column}' column does not exist"); } else { // need to construct a new Table not to overwrite anything in the object we are validating $test = new Table($table->table); // query for first occurence of the same column value $result = $test->findFirst()->where(array($column => $table->data[$column])); unset($test); if (!empty($result)) { // we better have primary key defined assert('!empty($table->primaryKey); // primary key has to be defined'); // we might be editing 'us' thus check for ID... not perfect all! if (array_key_exists($table->primaryKey, $table->where)) { if ($table->where[$table->primaryKey] != $result[$table->primaryKey]) { throw new TableException("'{$column}' value is not unique"); } } } } } }
/** * Match SESSION with a resource of users. * @param string */ public function matchSessionCredentials($credentialsString) { $result = $this->table->findFirst()->where(array($this->credentialsColumn => $credentialsString)); return isset($result[$this->credentialsColumn]); }