1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 9/26/15
- * Time: 11:56 PM
- */
-
-
- require_once('../vendor/autoload.php');
-
- Dotenv::load("..");
-
- class TestPermission
- {
- private $_pdo;
-
- public function __construct()
- {
- $dsn = getenv("DB_CONNECTION") . ":dbname=" . getenv("DB_DATABASE") . ";host="
- . getenv("DB_HOST") . ";port=" . getenv("DB_PORT");
- $this->_pdo = new PDO($dsn, getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
- }
-
- protected function printError($query, $message)
- {
- echo $message . "\n";
- var_dump($query->errorInfo());
- var_dump($this->_pdo->errorInfo());
- return null;
- }
-
- public function getPermission($user_id, $name)
- {
- $req = $this->_pdo->prepare("SELECT * FROM sp_lu_get_user_permission(:user_id, :name)");
- if ($req->execute(array(":user_id" => $user_id, ":name" => $name)))
- {
- return $req->fetchAll()[0][0];
- }
- else
- {
- $this->printError($req, "Failed to get permission");
- return null;
- }
- }
- }
-
- $test = new TestPermission();
-
- $user_id = 1;
- $permissions = array(
- "perm_1" => true,
- "perm_2" => false,
- "perm_3" => true,
- "perm_4" => false,
- "perm_5" => false,
- "perm_6" => true,
- "perm_7" => true,
- "perm_8" => false
- );
-
- foreach ($permissions as $permission => $value)
- {
- $p = $test->getPermission($user_id, $permission);
- if ($p == $value)
- {
- echo "[ OK ] $permission\n";
- }
- else if ($p != null)
- {
- echo "[ERR ] $permission\n";
- }
- }
|