index.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. include_once './Connections.class.php';
  3. include_once './DBInstance.php';
  4. include_once './Entity.class.php';
  5. class Estado extends Entity {
  6. protected $table_name = 'basico_geografico_estados';
  7. protected $classname = 'Estado';
  8. function municipios() {
  9. return $this->has_many(Municipio::class, 'estado_id');
  10. }
  11. }
  12. class Municipio extends Entity {
  13. protected $table_name = 'basico_geografico_municipios';
  14. protected $classname = 'Municipio';
  15. function estado() {
  16. return $this->belongs_to(Estado::class, 'estado_id');
  17. }
  18. }
  19. class User extends Entity {
  20. protected $timestamps = true;
  21. protected $softdelete = true;
  22. protected $table_name = 'basico_auth_users';
  23. protected $classname = 'User';
  24. public function existencia() {
  25. $this->has_one(Existencia::class, 'user_id');
  26. }
  27. public function contatos() {
  28. $this->has_many('contatos', 'user_id');
  29. }
  30. public function permissions() {
  31. return $this->belongs_to_many_extended(Permission::class, 'basico_auth_permission_user', 'user_id', 'permission_id');
  32. }
  33. public function roles() {
  34. return $this->belongs_to_many( Role::class, 'basico_auth_role_user', 'user_id', 'role_id');
  35. }
  36. }
  37. class Role extends Entity{
  38. protected $table_name = "basico_auth_roles";
  39. protected $classname = "Role";
  40. function permissions(){
  41. return $this->belongs_to_many(Permission::class, 'basico_auth_role_permission', 'role_id', 'permission_id');
  42. }
  43. }
  44. class Permission extends Entity{
  45. protected $table_name = "basico_auth_permissions";
  46. protected $classname = "Permission";
  47. }
  48. Connections::add_connection(new PDO("pgsql:dbname=urfat; user=urfat; password=urfat;host=127.0.0.1;port=5432"));
  49. $a = new User();
  50. $a->load(1);
  51. var_dump( $a->permissions() );
  52. //$a = new Estado();
  53. //$a->load(23);
  54. //foreach ($a->municipios() as $municipio) {
  55. // echo "$municipio->nome \n";
  56. //}
  57. //$a = new Municipio();
  58. //$a->load(1);
  59. //$a->estado();