/**
  * @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();
 }
 /**
  * @return HallsRepository
  */
 public static function getInstance() : HallsRepository
 {
     if (self::$inst == null) {
         self::$inst = new HallsRepository(Database::getInstance('app'));
     }
     return self::$inst;
 }
 /**
  * @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;
 }
 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;
 }
 /**
  * @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;
 }
Beispiel #6
0
 public static function index()
 {
     echo "<h1> DEFAULT STATE ALL POSTS </h1>";
     $dbh = \Framework\Database\Database::getInstance();
     //var_dump($dbh);
 }
Beispiel #7
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();
 /**
  * @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;
 }
 public static function getUUIDBy($params)
 {
     return Database::getInstance()->get(call_user_func(self::getModelClass() . '::getTableName'), $params, ['uuid', 'password_hash']);
 }