user.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * user class - used to store user groups, permissions, and other values
  4. */
  5. class user {
  6. private $database;
  7. public $domain_uuid;
  8. public $domain_name;
  9. private $user_uuid;
  10. private $permissions;
  11. private $groups;
  12. public $username;
  13. public $user_email;
  14. public $contact_uuid;
  15. public function __construct(database $database, $domain_uuid, $user_uuid) {
  16. //set the database variable
  17. $this->database = $database;
  18. //set the domain_uuid
  19. if (isset($domain_uuid) && is_uuid($domain_uuid)) {
  20. $this->domain_uuid = $domain_uuid;
  21. }
  22. //set the user_uuid
  23. if (isset($user_uuid) && is_uuid($user_uuid)) {
  24. $this->user_uuid = $user_uuid;
  25. }
  26. //set the user groups, permission and details
  27. if (isset($domain_uuid) && is_uuid($domain_uuid) && isset($user_uuid) && is_uuid($user_uuid)) {
  28. $this->set_groups();
  29. $this->set_permissions();
  30. $this->set_details();
  31. }
  32. }
  33. /*
  34. * set_details method sets the user assigned details
  35. */
  36. public function set_details() {
  37. $sql = "select d.domain_name, u.username, u.user_email, u.contact_uuid ";
  38. $sql .= "from v_users as u, v_domains as d ";
  39. $sql .= "where u.domain_uuid = :domain_uuid ";
  40. $sql .= "and u.user_uuid = :user_uuid ";
  41. $sql .= "and u.domain_uuid = d.domain_uuid ";
  42. $sql .= "and u.user_setting_enabled = 'true' ";
  43. $parameters['domain_uuid'] = $this->domain_uuid;
  44. $parameters['user_uuid'] = $this->user_uuid;
  45. $row = $this->database->select($sql, $parameters, 'row');
  46. if (is_array($row)) {
  47. $this->domain_name = $row['domain_name'];
  48. $this->username = $row['username'];
  49. $this->user_email = $row['user_email'];
  50. $this->contact_uuid = $row['contact_uuid'];
  51. }
  52. }
  53. /*
  54. * get_user_uuid method gets the user_uuid
  55. */
  56. public function get_user_uuid() {
  57. return $this->user_uuid;
  58. }
  59. /*
  60. * set_permissions method sets the user assigned permissions
  61. */
  62. public function set_permissions() {
  63. $this->permissions = new permissions($this->database, $this->domain_uuid, $this->user_uuid);
  64. }
  65. /*
  66. * get_permissions method gets the user assigned permissions
  67. */
  68. public function get_permissions() {
  69. return $this->permissions->get_permissions();
  70. }
  71. /*
  72. * set_groups method sets the user assigned groups
  73. */
  74. public function set_groups() {
  75. $this->groups = new groups($this->database, $this->domain_uuid, $this->user_uuid);
  76. }
  77. /*
  78. * get_groups method gets the user assigned groups
  79. */
  80. public function get_groups() {
  81. return $this->groups->get_groups();
  82. }
  83. }
  84. ?>