UserGroup.php 927 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class UserGroup extends DBObject {
  3. public $Permissions=array();
  4. public function __construct($id) {
  5. parent::__construct("user_groups", "group_id", $id);
  6. $permissions=explode(",", $this->GroupPermissions);
  7. foreach ($permissions as $p)
  8. $this->Permissions[]=new Permission($p);
  9. // Hack for MySQL on Linux
  10. if ($this->GroupIsAdmin!='1' && $this->GroupIsAdmin!='0')
  11. $this->GroupIsAdmin=ord($this->GroupIsAdmin);
  12. }
  13. public function Save() {
  14. $permissions=array();
  15. foreach ($this->Permissions as $p)
  16. $permissions[]=$p->PermissionId;
  17. $this->GroupPermissions=implode(",", $permissions);
  18. parent::Save();
  19. }
  20. public function HasPermission($permission) {
  21. // /$arr=print_r($this,true);
  22. if ($this->GroupIsAdmin==1)
  23. return true;
  24. foreach ($this->Permissions as $p)
  25. if ($p->PermissionValue==$permission)
  26. return true;
  27. return false;
  28. }
  29. }