This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGateKeeper.php
71 lines (66 loc) · 1.7 KB
/
GateKeeper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* FlexiPeeHP - WebHook reciever
*
* @author Vítězslav Dvořák <info@vitexsofware.cz>
* @copyright (G) 2017 Vitex Software
*/
namespace FlexiPeeHP\Bricks;
/**
* Description of GateKeeper
*
* @version 0.1
*
* @author vitex
*/
class GateKeeper extends \Ease\Sand
{
/**
* Is document accessible by user ?
*
* @param \FlexiPeeHP\FlexiBeeRO $document FlexiBee documnet
* @param Customer|User|\Ease\Anonym $user Current User
*
* @return boolean
*/
public static function isAccessibleBy($document, $user)
{
$result = null;
switch (Convertor::baseClassName($user)) {
case 'User': //Admin
$result = true;
break;
case 'Customer': //Customer
$result = (self::getDocumentCompany($document) == self::getCustomerCompany($user));
break;
case 'Anonym': //Anonymous
$result = false;
break;
}
return $result;
}
/**
* Get Company code for document
*
* @param \FlexiPeeHP\FlexiBeeRO $document
*
* @return string documnent code
*/
public static function getDocumentCompany($document)
{
return $document->getDataValue('firma') ? \FlexiPeeHP\FlexiBeeRO::uncode(
$document->getDataValue('firma')) : null;
}
/**
* Obtain customer company code
*
* @param Customer $customer
*
* @return int
*/
public static function getCustomerCompany($customer)
{
return $customer->adresar->getDataValue('kod') ? \FlexiPeeHP\FlexiBeeRO::uncode($customer->adresar->getDataValue('kod'))
: null;
}
}