public function testCreate()
 {
     $dbInstance = \Magento\TestFramework\Helper\Bootstrap::getInstance()->getBootstrap()->getApplication()->getDbInstance();
     $dbConfig = ['host' => $dbInstance->getHost(), 'username' => $dbInstance->getUser(), 'password' => $dbInstance->getPassword(), 'dbname' => $dbInstance->getSchema(), 'active' => true];
     $connection = $this->model->create($dbConfig);
     $this->assertInstanceOf('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', $connection);
 }
Esempio n. 2
0
 public function testFunctional()
 {
     $pdo = $this->factory->getConnection();
     $this->assertInstanceOf('PDO', $pdo);
     $pdo->exec("CREATE TABLE `foo`(`id` int,`name` varchar)");
     $pdo->exec("insert into `foo` VALUES (1,'foo')");
     $repo = new FooRepository($this->factory);
     $entity = $repo->getById(1);
     $expected = new FooEntity();
     $expected->id = 1;
     $expected->name = 'foo';
     $this->assertEquals($expected, $entity);
 }
 public function dispatch()
 {
     $connection = ConnectionFactory::getDataConnection();
     $bookmarks = $connection->getBookmarks();
     $template = new BookmarksTemplate($bookmarks, "Bookmarks");
     $template->showTemplate();
 }
 /**
  * @param int $userId
  * @param Captions $captions
  * @return array
  */
 public function GetUserGrants($userId, Captions $captions)
 {
     $queryBuilder = new SelectCommand($this->connectionFactory->CreateEngCommandImp());
     $queryBuilder->AddField($this->usersTable, $this->users_UserId, FieldType::Number, 'users_user_id');
     $queryBuilder->AddField($this->usersTable, $this->users_UserName, FieldType::String, 'users_user_name');
     $queryBuilder->AddField($this->userPermsTable, $this->userPerms_UserId, FieldType::Number, 'userperms_user_id');
     $queryBuilder->AddField($this->userPermsTable, $this->userPerms_PageName, FieldType::String, 'userperms_pagename');
     $queryBuilder->AddField($this->userPermsTable, $this->userPerms_Grant, FieldType::String, 'userperms_grant');
     $queryBuilder->SetSourceTableName($this->userPermsTable);
     $queryBuilder->AddJoin(JoinKind::LeftOuter, $this->usersTable, 'userperms_user_id', $this->users_UserId);
     $queryBuilder->AddFieldFilter('userperms_user_id', new FieldFilter($userId, '='));
     $dataset = new QueryDataset($this->connectionFactory, $this->connectionOptions, $queryBuilder->GetSQL(), array(), array(), array(), 'user_grants');
     $dataset->AddField(new StringField('userperms_grant'), false);
     $dataset->AddField(new StringField('userperms_pagename'), false);
     $dataset->Open();
     $pages = array();
     $pages[''] = array('name' => '', 'caption' => $captions->GetMessageString('Application'), 'selectGrant' => false, 'updateGrant' => false, 'insertGrant' => false, 'deleteGrant' => false, 'adminGrant' => false);
     foreach ($this->tableCaptions as $name => $caption) {
         $pages[$name] = array('name' => $name, 'caption' => $captions->RenderText($caption), 'selectGrant' => false, 'updateGrant' => false, 'insertGrant' => false, 'deleteGrant' => false, 'adminGrant' => false);
     }
     while ($dataset->Next()) {
         $grant = $dataset->GetFieldValueByName('userperms_grant');
         $pageName = $dataset->GetFieldValueByName('userperms_pagename');
         if (isset($pages[$pageName])) {
             $pages[$pageName]['selectGrant'] = $pages[$pageName]['selectGrant'] || StringUtils::SameText($grant, 'select');
             $pages[$pageName]['updateGrant'] = $pages[$pageName]['updateGrant'] || StringUtils::SameText($grant, 'update');
             $pages[$pageName]['insertGrant'] = $pages[$pageName]['insertGrant'] || StringUtils::SameText($grant, 'insert');
             $pages[$pageName]['deleteGrant'] = $pages[$pageName]['deleteGrant'] || StringUtils::SameText($grant, 'delete');
             $pages[$pageName]['adminGrant'] = $pages[$pageName]['adminGrant'] || StringUtils::SameText($grant, 'admin');
         }
     }
     $dataset->Close();
     return array_values($pages);
 }
Esempio n. 5
0
 public static function getConnection()
 {
     if (is_null(self::$conn)) {
         self::$conn = new PDO(self::$tipo . ':host=' . self::$host . ';dbname=' . self::$db, self::$usuario, self::$senha, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET Names UTF8'));
     }
     return self::$conn;
 }
Esempio n. 6
0
 public function check()
 {
     $this->setView('reclaim/index');
     if (Session::isLoggedIn()) {
         return Error::set('You\'re logged in!');
     }
     $this->view['valid'] = true;
     $this->view['publicKey'] = Config::get('recaptcha:publicKey');
     if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) {
         return Error::set('We could not find the captcha validation fields!');
     }
     $recaptcha = Recaptcha::check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
     if (is_string($recaptcha)) {
         return Error::set(Recaptcha::$errors[$recaptcha]);
     }
     if (empty($_POST['username']) || empty($_POST['password'])) {
         return Error::set('All forms are required.');
     }
     $reclaims = new reclaims(ConnectionFactory::get('mongo'));
     $good = $reclaims->authenticate($_POST['username'], $_POST['password']);
     if (!$good) {
         return Error::set('Invalid username/password.');
     }
     $reclaims->import($_POST['username'], $_POST['password']);
     $users = new users(ConnectionFactory::get('mongo'));
     $users->authenticate($_POST['username'], $_POST['password']);
     header('Location: ' . Url::format('/'));
 }
Esempio n. 7
0
 public static function handler($data = null)
 {
     if (isset($_SESSION['done_autoauth'])) {
         return;
     }
     if (empty($_SERVER['SSL_CLIENT_RAW_CERT'])) {
         return self::done();
     }
     if (Session::isLoggedIn()) {
         return self::done();
     }
     $certs = new certs(ConnectionFactory::get('mongo'), ConnectionFactory::get('redis'));
     $userId = $certs->check($_SERVER['SSL_CLIENT_RAW_CERT']);
     if ($userId == NULL) {
         return self::done();
     }
     $users = new users(ConnectionFactory::get('mongo'));
     $user = $users->get($userId, false);
     if (empty($user)) {
         return;
     }
     if (!in_array('autoauth', $user['auths'])) {
         return self::done();
     }
     if ($user['status'] == users::ACCT_LOCKED) {
         return self::done();
     }
     Session::setBatchVars($user);
     return self::done();
 }
Esempio n. 8
0
 private static function getModel()
 {
     if (empty(self::$missions)) {
         self::$missions = new missions(ConnectionFactory::get('mongo'));
     }
     return self::$missions;
 }
Esempio n. 9
0
 public function basic($arguments)
 {
     $missions = new missions(ConnectionFactory::get('mongo'));
     if (!empty($arguments[0])) {
         // A specific mission has been requested.
         $mission = $missions->get('basic', intval($arguments[0]));
         if (empty($mission)) {
             return Error::set('Mission does not exist.');
         }
         $this->view['valid'] = true;
         $this->view['num'] = $arguments[0];
         $this->view['basic'] = new BasicMissions();
         $this->view['name'] = $mission['name'];
         $this->view['next'] = $arguments[0] != 6;
         $good = call_user_func(array($this->view['basic'], 'validateMission' . $this->view['num']));
         if ($good !== null) {
             // BALANCED.  TERNARY.
             if (!$good) {
                 return Error::set('Wrong!');
             }
             $this->view['valid'] = false;
             $this->view['good'] = true;
         }
     } else {
         // Just show a listing of possible missions.
         $this->view['valid'] = true;
         $this->view['missions'] = $missions->getMissionsByType('basic');
         $this->setView('missions/base');
     }
 }
Esempio n. 10
0
 public function index($arguments)
 {
     $news = new news(ConnectionFactory::get('mongo'));
     $articles = new articles(ConnectionFactory::get('mongo'));
     $notices = new notices(ConnectionFactory::get('redis'));
     $irc = new irc(ConnectionFactory::get('redis'));
     $quotes = new quotes(ConnectionFactory::get('mongo'));
     $forums = new forums(ConnectionFactory::get('redis'));
     // Set all site-wide notices.
     foreach ($notices->getAll() as $notice) {
         Error::set($notice, true);
     }
     // Fetch the easy data.
     $this->view['news'] = $news->getNewPosts();
     $this->view['shortNews'] = $news->getNewPosts(true);
     $this->view['newArticles'] = $articles->getNewPosts('new', 1, 5);
     $this->view['ircOnline'] = $irc->getOnline();
     $this->view['randomQuote'] = $quotes->getRandom();
     $this->view['fPosts'] = $forums->getNew();
     // Get online users.
     $apc = new APCIterator('user', '/' . Cache::PREFIX . 'user_.*/');
     $this->view['onlineUsers'] = array();
     while ($apc->valid()) {
         $current = $apc->current();
         array_push($this->view['onlineUsers'], substr($current['key'], strlen(Cache::PREFIX) + 5));
         $apc->next();
     }
     // Set title.
     Layout::set('title', 'Home');
 }
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new ConnectionFactory();
     }
     return self::$instance;
 }
Esempio n. 12
0
 public function CheckUsernameAndPassword($username, $password, &$errorMessage)
 {
     $this->connectionOptions['username'] = $username;
     $this->connectionOptions['password'] = $password;
     $connection = $this->connectionFactory->CreateConnection($this->connectionOptions);
     $connection->Connect();
     if ($connection->Connected()) {
         $errorMessage = null;
         $connection->Disconnect();
         return true;
     } else {
         $errorMessage = $connection->LastError();
         //'The username/password combination you entered was invalid.';
         return false;
     }
 }
 /**
  * Retrieve favourite sites and fill data in template.
  */
 private function parseFavouriteSites($template)
 {
     try {
         $connection = ConnectionFactory::getDataConnection();
         $favourites = $connection->getWebsiteFavourites();
         foreach ($favourites as $id => $favourite) {
             $name = $favourite->getName();
             $link = SERVER_HOST_AND_PATH . "php/scraper" . $favourite->getLink();
             switch ($favourite->getType()) {
                 case "movie":
                     $template->setFavouriteMovieWebsite(array($name, $link));
                     break;
                 case "serie":
                     $template->setFavouriteSerieWebsite(array($name, $link));
                     break;
                 case "documentary":
                     $template->setFavouriteDocumentaryWebsite(array($name, $link));
                     break;
                 case "anime":
                     $template->setFavouriteAnimeWebsite(array($name, $link));
                     break;
             }
         }
     } catch (Exception $e) {
         //Ignored exception
     }
 }
 /**
  * Searches for the configuration for the connection and creates it. If the configuration is not found then it will
  * return NULL
  *
  * @param string $name
  * @return null|\PDO
  */
 protected function createConnection($name)
 {
     if (!isset($this->config[$name]['pdo'])) {
         return null;
     }
     return ConnectionFactory::factory($this->config[$name]['pdo']);
 }
Esempio n. 15
0
 public static function transactionIdExists($transaction_id)
 {
     $conditions = array();
     $conditions['transaction_id'] = $transaction_id;
     $success = ConnectionFactory::SelectValue("transaction_id", "diamond_purchased_history", $conditions);
     return $success;
 }
Esempio n. 16
0
 public static function getFactory()
 {
     if (!self::$factory) {
         self::$factory = new ConnectionFactory();
     }
     return self::$factory;
 }
 public function queryAllSelect()
 {
     $sql = "SELECT id_area, nome FROM {$this->table}";
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->execute();
     return $stmt->fetchAll();
 }
 /**
  * Retorna um objeto da classe ConnectionFactory
  * @return ConnectionFactory object
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
 /**
  * atualiza um registro da tabela
  *
  * @parametro TematicaMySql tematica
  */
 public function update(Log $log)
 {
     $sql = "UPDATE {$this->table} SET tabela = :tabela, acao = :acao, descricao=:descricao WHERE id_log = :id";
     $id = $log->getIdLog();
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->bindParam(':id_log', $id);
     return $stmt->execute();
 }
 public function queryAllAreaAvaliador($id)
 {
     $sql = "SELECT aa.fk_area as area FROM area a JOIN avaliador_area aa ON a.id_area = aa.fk_area AND fk_avaliador = :id";
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->bindParam(':id', $id, PDO::PARAM_INT);
     $stmt->execute();
     return $stmt->fetch();
 }
 public function getJsonResponse($cidade, $bairro, $rua)
 {
     $this->connection = ConnectionFactory::getInstance()->createConnection(false);
     $locEspecificaBI = new LocEspecificaBI($this->connection);
     $jsonResponse = $locEspecificaBI->getJsonResponse($cidade, $bairro, $rua);
     $locEspecificaBI->releaseConnection($this->connection);
     return $jsonResponse;
 }
 public function getJsonResponse($lat, $long, $distance)
 {
     $this->connection = ConnectionFactory::getInstance()->createConnection(false);
     $posicaoAtualBI = new PosicaoAtualBI($this->connection);
     $jsonResponse = $posicaoAtualBI->createJSONResponse($lat, $long, $distance);
     $posicaoAtualBI->releaseConnection($this->connection);
     return $jsonResponse;
 }
 /**
  * atualiza um registro da tabela
  *
  * @parametro UsuarioPermissaoMySql usuarioPermissao
  */
 public function update(UsuarioPermissao $UsuarioPermissao)
 {
     $sql = "UPDATE {$this->table} SET  WHERE fk_usuario = :id";
     $id = $UsuarioPermissao->getFkUsuario();
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->bindParam(':id', $id);
     return $stmt->execute();
 }
Esempio n. 24
0
 public static function listTasks()
 {
     $db = ConnectionFactory::getDB();
     $tasks = array();
     foreach ($db->tasks() as $task) {
         //vai para o banco de dados dentro da tabela tasks
         $tasks[] = array('id' => $task['id'], 'description' => $task['description'], 'done' => $task['done']);
     }
 }
Esempio n. 25
0
 public static function delete($id)
 {
     $db = ConnectionFactory::getDB();
     $task = $db->tasks[$id];
     if ($task) {
         $task->delete();
         return true;
     }
     return false;
 }
Esempio n. 26
0
 public function index()
 {
     $lectures = new lectures(ConnectionFactory::get('mongo'));
     $this->view['lectures'] = $lectures->getNew();
     if (is_string($this->view['lectures'])) {
         return Error::set($this->view['lectures']);
     }
     $this->view['valid'] = true;
     Layout::set('title', 'Lectures');
 }
 /**
  * atualiza um registro da tabela
  *
  * @parametro CategoriaMySql categoria
  */
 public function update(Categoria $Categoria)
 {
     $sql = "UPDATE {$this->table} SET nome = :nome WHERE id_categoria = :id";
     $id = $Categoria->getIdCategoria();
     $nome = $Categoria->getNome();
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->bindParam(':id', $id);
     $stmt->bindParam(':nome', $nome);
     return $stmt->execute();
 }
 public static function delete($id)
 {
     $db = ConnectionFactory::getDB();
     $cart = $db->carts[$id];
     if ($cart) {
         $cart->delete();
         return true;
     }
     return false;
 }
 /**
  * atualiza um registro da tabela
  *
  * @parametro PermissaoMySql permissao
  */
 public function update(Permissao $Permissao)
 {
     $sql = "UPDATE {$this->table} SET nome_permissao = :nome_permissao WHERE id_permissao = :id";
     $id = $Permissao->getIdPermissao();
     $nomePermissao = $Permissao->getNomePermissao();
     $stmt = ConnectionFactory::prepare($sql);
     $stmt->bindParam(':id', $id);
     $stmt->bindParam(':nomePermissao', $nomePermissao);
     return $stmt->execute();
 }
 public static function delete($id)
 {
     $db = ConnectionFactory::getDB();
     $guest = $db->guests[$id];
     if ($guest) {
         $guest->delete();
         return true;
     }
     return false;
 }