| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_App_Acl |
| 3 |
{ |
| 4 |
public $appQuery, $auth, $permission; |
| 5 |
|
| 6 |
public function __construct( |
| 7 |
HC3_Hooks $hooks, |
| 8 |
|
| 9 |
SH4_App_Query $appQuery, |
| 10 |
|
| 11 |
HC3_Auth $auth, |
| 12 |
HC3_IPermission $permission |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->appQuery = $hooks->wrap( $appQuery ); |
| 16 |
$this->auth = $hooks->wrap( $auth ); |
| 17 |
$this->permission = $hooks->wrap( $permission ); |
| 18 |
} |
| 19 |
|
| 20 |
public function checkUserProfile() |
| 21 |
{ |
| 22 |
$haveRoles = false; |
| 23 |
|
| 24 |
$user = $this->auth->getCurrentUser(); |
| 25 |
|
| 26 |
// admin? |
| 27 |
if( ! $haveRoles ){ |
| 28 |
if( $this->permission->isAdmin($user) ){ |
| 29 |
$haveRoles = true; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// manager? |
| 34 |
if( ! $haveRoles ){ |
| 35 |
$calendars = $this->appQuery->findCalendarsManagedByUser( $user ); |
| 36 |
if( $calendars ){ |
| 37 |
$haveRoles = true; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
// viewer? |
| 42 |
if( ! $haveRoles ){ |
| 43 |
$calendars = $this->appQuery->findCalendarsViewedByUser( $user ); |
| 44 |
if( $calendars ){ |
| 45 |
$haveRoles = true; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// employee? |
| 50 |
if( ! $haveRoles ){ |
| 51 |
$employee = $this->appQuery->findEmployeeByUser( $user ); |
| 52 |
if( $employee ){ |
| 53 |
$haveRoles = true; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
$ret = $haveRoles ? true : false; |
| 58 |
return $ret; |
| 59 |
} |
| 60 |
|
| 61 |
public function checkUser() |
| 62 |
{ |
| 63 |
$return = FALSE; |
| 64 |
|
| 65 |
$currentUser = $this->auth->getCurrentUser(); |
| 66 |
$currentUserId = $currentUser->getId(); |
| 67 |
if( ! $currentUserId ){ |
| 68 |
return $return; |
| 69 |
} |
| 70 |
|
| 71 |
$return = TRUE; |
| 72 |
return $return; |
| 73 |
} |
| 74 |
|
| 75 |
public function checkAdmin() |
| 76 |
{ |
| 77 |
$return = FALSE; |
| 78 |
|
| 79 |
$currentUser = $this->auth->getCurrentUser(); |
| 80 |
$currentUserId = $currentUser->getId(); |
| 81 |
|
| 82 |
if( ! $currentUserId ){ |
| 83 |
return $return; |
| 84 |
} |
| 85 |
|
| 86 |
if( $this->permission->isAdmin($currentUser) ){ |
| 87 |
$return = TRUE; |
| 88 |
} |
| 89 |
|
| 90 |
return $return; |
| 91 |
} |
| 92 |
|
| 93 |
public function checkManager() |
| 94 |
{ |
| 95 |
$return = FALSE; |
| 96 |
|
| 97 |
$currentUser = $this->auth->getCurrentUser(); |
| 98 |
$currentUserId = $currentUser->getId(); |
| 99 |
if( ! $currentUserId ){ |
| 100 |
return $return; |
| 101 |
} |
| 102 |
|
| 103 |
$calendars = $this->appQuery->findCalendarsManagedByUser( $currentUser ); |
| 104 |
if( ! $calendars ){ |
| 105 |
return $return; |
| 106 |
} |
| 107 |
|
| 108 |
$return = TRUE; |
| 109 |
|
| 110 |
return $return; |
| 111 |
} |
| 112 |
|
| 113 |
public function checkEmployee() |
| 114 |
{ |
| 115 |
$return = FALSE; |
| 116 |
|
| 117 |
$currentUser = $this->auth->getCurrentUser(); |
| 118 |
$currentUserId = $currentUser->getId(); |
| 119 |
if( ! $currentUserId ){ |
| 120 |
return $return; |
| 121 |
} |
| 122 |
|
| 123 |
$employee = $this->appQuery->findEmployeeByUser( $currentUser ); |
| 124 |
if( ! $employee ){ |
| 125 |
return $return; |
| 126 |
} |
| 127 |
|
| 128 |
$return = TRUE; |
| 129 |
|
| 130 |
return $return; |
| 131 |
} |
| 132 |
} |