/** * @param string $tableName * @return Nette\Database\Table\Selection */ protected function getTable($tableName = NULL) { if ($tableName == NULL) { // table name from class name preg_match('#(\\w+)Repository$#', get_class($this), $m); $tableName = lcfirst($m[1]); } return $this->database->table($tableName); }
/** * Performs an authentication. * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->database->table('user')->where('username', $username)->fetch(); if (!$row) { throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND); } if (!$this->checkPassword($row->password, $password)) { throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL); } $roles = $this->database->table('permission')->where('user_id', $row->id)->fetchPairs('server_id', 'role'); $arr = array('username' => $row->username, 'serverRoles' => $roles); if ($row->role == 'admin') { return new Nette\Security\Identity($row->id, 'admin', $arr); } else { return new Nette\Security\Identity($row->id, 'player', $arr); } }
/** * Log * * @param string $type * @param string $message */ private function log($type, $message = NULL) { $selection = $this->connection->table('logs'); $selection->insert(array('datetime' => date("Y-m-d H:i:s"), 'type' => $type, 'message' => $message)); if ($this->debug) { echo date("Y-m-d H:i:s.") . substr(microtime(TRUE) - time() . "", 2, 4) . " @ " . $type . " # " . $message . "\n"; if (!defined('STDIN')) { //Next code is realy F*****G hack @ob_end_flush(); @ob_flush(); @flush(); @ob_start(); } } }
/** * Vrací celou tabulku z databáze * @return \Nette\Database\Table\Selection */ protected function getTable() { return $this->connection->table($this->tableName); }
/** * Vrací objekt reprezentující databázovou tabulku. * @return Nette\Database\Table\Selection */ protected function getTable() { // název tabulky odvodíme z názvu třídy preg_match('#(\\w+)Repository$#', get_class($this), $m); return $this->context->table(lcfirst($m[1])); }
public function registerUser(array $values) { // todo validate values $this->database->table('users')->insert($values); }