Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 9/26/15
  6. * Time: 11:56 PM
  7. */
  8. require_once('../vendor/autoload.php');
  9. Dotenv::load("..");
  10. class TestPermission
  11. {
  12. private $_pdo;
  13. public function __construct()
  14. {
  15. $dsn = getenv("DB_CONNECTION") . ":dbname=" . getenv("DB_DATABASE") . ";host="
  16. . getenv("DB_HOST") . ";port=" . getenv("DB_PORT");
  17. $this->_pdo = new PDO($dsn, getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
  18. }
  19. protected function printError($query, $message)
  20. {
  21. echo $message . "\n";
  22. var_dump($query->errorInfo());
  23. var_dump($this->_pdo->errorInfo());
  24. return null;
  25. }
  26. public function getPermission($user_id, $name)
  27. {
  28. $req = $this->_pdo->prepare("SELECT * FROM sp_lu_get_user_permission(:user_id, :name)");
  29. if ($req->execute(array(":user_id" => $user_id, ":name" => $name)))
  30. {
  31. return $req->fetchAll()[0][0];
  32. }
  33. else
  34. {
  35. $this->printError($req, "Failed to get permission");
  36. return null;
  37. }
  38. }
  39. }
  40. $test = new TestPermission();
  41. $user_id = 1;
  42. $permissions = array(
  43. "perm_1" => true,
  44. "perm_2" => false,
  45. "perm_3" => true,
  46. "perm_4" => false,
  47. "perm_5" => false,
  48. "perm_6" => true,
  49. "perm_7" => true,
  50. "perm_8" => false
  51. );
  52. foreach ($permissions as $permission => $value)
  53. {
  54. $p = $test->getPermission($user_id, $permission);
  55. if ($p == $value)
  56. {
  57. echo "[ OK ] $permission\n";
  58. }
  59. else if ($p != null)
  60. {
  61. echo "[ERR ] $permission\n";
  62. }
  63. }