/**
  * @param string $hallName
  * @return bool
  */
 private function hallNameExists(string $hallName) : bool
 {
     $query = "SELECT id FROM halls WHERE name = ?";
     $result = $this->db->prepare($query);
     $result->execute([$hallName]);
     return $result->rowCount() > 0;
 }
 /**
  * @param int $id
  * @throws ApplicationException
  */
 public function getById(int $id)
 {
     $query = "SELECT\n          u.id,\n          u.username,\n          u.fullname\n        FROM users AS u\n        WHERE u.id = ?";
     $result = $this->db->prepare($query);
     $result->execute([$id]);
     if ($result->rowCount() < 1) {
         throw new ApplicationException("User not found.");
     }
     return $result->fetch();
 }
 /**
  * @return array
  * @throws \Exception
  */
 public function getAllRoles() : array
 {
     $db = Database::getInstance('app');
     $result = $db->prepare("SELECT id, name FROM roles");
     $result->execute([]);
     return $result->fetchAll();
 }
 /**
  * @param string $conferenceTitle
  * @return bool
  */
 private function conferenceTitleExists(string $conferenceTitle, int $id = -1) : bool
 {
     $query = "SELECT id FROM conferences WHERE title = ? AND id != ?";
     $result = $this->db->prepare($query);
     $result->execute([$conferenceTitle, $id]);
     return $result->rowCount() > 0;
 }
 /**
  * @param AbstractController $controller
  * @return bool
  */
 public static function saveController($controller)
 {
     if (is_a($controller, AbstractController::class)) {
         $vars = get_object_vars($controller->getModel());
         Database::getInstance()->insert($controller->getModel()->getTableName(), $vars);
         return true;
     }
     return false;
 }
예제 #6
0
 public function start()
 {
     try {
         Database::createNonExistingDatabase(DatabaseConfig::DB_NAME);
         Database::setInstance(DatabaseConfig::DB_INSTANCE, DatabaseConfig::DB_DRIVER, DatabaseConfig::DB_USER, DatabaseConfig::DB_PASS, DatabaseConfig::DB_NAME, DatabaseConfig::DB_HOST);
     } catch (\Exception $e) {
         require_once "error.php";
         exit;
     }
     Manager::getInstance()->start();
     HttpContext::getInstance()->getIdentity()->setCurrentUser();
     $this->frontController->dispatch();
 }
예제 #7
0
 public static function verifyCookie()
 {
     if (Cookie::exists(Config::get('cookie', 'name'))) {
         $token = Cookie::get(Config::get('cookie', 'name'));
         $toVerify = hash("sha512", $token . Utils::getClientIP());
         if ($data = Database::getInstance()->get(call_user_func(self::getModelClass() . '::getTableName'), ['token' => $toVerify], ['user_uuid'])) {
             if (array_key_exists(0, $data) && is_array($data[0])) {
                 $data = $data[0];
             }
             if (array_key_exists('user_uuid', $data)) {
                 return $data['user_uuid'];
             }
         }
         Cookie::remove(Config::get('cookie', 'name'));
     }
     return false;
 }
예제 #8
0
 /**
  * @param string $table
  * @return bool
  * @throws \Exception
  */
 private function tableExists(string $table) : bool
 {
     $db = Database::getInstance('app');
     $result = $db->prepare("SHOW TABLES LIKE ?");
     $result->execute([$table]);
     return $result->rowCount() > 0;
 }
예제 #9
0
 public static function index()
 {
     echo "<h1> DEFAULT STATE ALL POSTS </h1>";
     $dbh = \Framework\Database\Database::getInstance();
     //var_dump($dbh);
 }
예제 #10
0
<?php

/**
 *    Copyright 2015 OhYea777
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once '../src/Framework/bootstrap.php';
use Framework\Database\Database;
use Framework\Misc\Config;
Config::registerConfigFile('../config.json');
Database::getInstance();
예제 #11
0
 /**
  * @param int $userId
  * @return UserProfileViewModel
  * @throws \Exception
  */
 public function getUserInfo(int $userId) : UserProfileViewModel
 {
     $db = Database::getInstance('app');
     $result = $db->prepare("SELECT id, username, password, fullname FROM users WHERE id = ?");
     $result->execute([$userId]);
     $userRow = $result->fetch();
     $user = new UserProfileViewModel();
     $user->setId($userRow["id"])->setUsername($userRow["username"])->setFullName($userRow["fullname"]);
     return $user;
 }
예제 #12
0
 public function __destruct()
 {
     \Framework\Database\Database::closeConnection();
 }
예제 #13
0
 public static function getUUIDBy($params)
 {
     return Database::getInstance()->get(call_user_func(self::getModelClass() . '::getTableName'), $params, ['uuid', 'password_hash']);
 }