ILIAS  trunk Revision v11.0_alpha-1871-gde1fee8db3d
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
UploadPolicyResolver Class Reference
+ Collaboration diagram for UploadPolicyResolver:

Public Member Functions

 __construct (protected ilRbacReview $rbac_review, protected ilObjUser $current_user, protected array $upload_policies,)
 
 getUserUploadSizeLimitInBytes ()
 Returns the upload-size limit of the current user if customized by any upload policy. More...
 

Protected Member Functions

 isPolicyActiveAndValid (UploadPolicy $policy)
 

Protected Attributes

const MB_TO_BYTES = 1_000 * 1_000
 Multiply for MB to Bytes, divide for Bytes to MB. More...
 

Detailed Description

Author
Thibeau Fuhrer thibe.nosp@m.au@s.nosp@m.r.sol.nosp@m.utio.nosp@m.ns

Definition at line 24 of file UploadPolicyResolver.php.

Constructor & Destructor Documentation

◆ __construct()

UploadPolicyResolver::__construct ( protected ilRbacReview  $rbac_review,
protected ilObjUser  $current_user,
protected array  $upload_policies 
)
Parameters
UploadPolicy[]$upload_policies

Definition at line 34 of file UploadPolicyResolver.php.

38  {
39  }

Member Function Documentation

◆ getUserUploadSizeLimitInBytes()

UploadPolicyResolver::getUserUploadSizeLimitInBytes ( )

Returns the upload-size limit of the current user if customized by any upload policy.

If multiple policies apply, the largest limit will be returned.

Definition at line 45 of file UploadPolicyResolver.php.

References UploadPolicy\AUDIENCE_TYPE_ALL_USERS, UploadPolicy\AUDIENCE_TYPE_GLOBAL_ROLE, isPolicyActiveAndValid(), and null.

45  : ?int
46  {
47  $largest_limit_in_bytes = null;
48  foreach ($this->upload_policies as $policy) {
49  if (!$this->isPolicyActiveAndValid($policy)) {
50  continue;
51  }
52 
53  $policy_limit_in_bytes = ($policy->getUploadLimitInMB() * self::MB_TO_BYTES);
54 
55  if (UploadPolicy::AUDIENCE_TYPE_ALL_USERS === $policy->getAudienceType() &&
56  (null === $largest_limit_in_bytes || $policy_limit_in_bytes > $largest_limit_in_bytes)
57  ) {
58  $largest_limit_in_bytes = $policy_limit_in_bytes;
59  continue;
60  }
61 
62  if (UploadPolicy::AUDIENCE_TYPE_GLOBAL_ROLE === $policy->getAudienceType() &&
63  $this->rbac_review->isAssignedToAtLeastOneGivenRole(
64  $this->current_user->getId(),
65  array_map(
66  'intval',
67  array_merge(
68  $policy->getAudience()['global_roles'] ?? [],
69  $policy->getAudience()['local_roles'] ?? []
70  )
71  )
72  ) &&
73  (null === $largest_limit_in_bytes || $policy_limit_in_bytes > $largest_limit_in_bytes)
74  ) {
75  $largest_limit_in_bytes = $policy_limit_in_bytes;
76  }
77  }
78 
79  return $largest_limit_in_bytes;
80  }
const AUDIENCE_TYPE_GLOBAL_ROLE
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isPolicyActiveAndValid(UploadPolicy $policy)
const AUDIENCE_TYPE_ALL_USERS
+ Here is the call graph for this function:

◆ isPolicyActiveAndValid()

UploadPolicyResolver::isPolicyActiveAndValid ( UploadPolicy  $policy)
protected

Definition at line 82 of file UploadPolicyResolver.php.

References UploadPolicy\getValidFrom(), UploadPolicy\getValidUntil(), UploadPolicy\isActive(), and null.

Referenced by getUserUploadSizeLimitInBytes().

82  : bool
83  {
84  $valid_from = $policy->getValidFrom();
85  $valid_until = $policy->getValidUntil();
86 
87  if (null === $valid_from && null === $valid_until) {
88  return $policy->isActive();
89  }
90 
91  $today = new \DateTimeImmutable('today midnight');
92 
93  if (null !== $valid_from && null !== $valid_until) {
94  return $policy->isActive() && $valid_from >= $today && $today < $valid_until;
95  }
96 
97  if (null !== $valid_until && null === $valid_from) {
98  return $policy->isActive() && $today <= $valid_until;
99  }
100 
101  if (null !== $valid_from && null === $valid_until) {
102  return $policy->isActive() && $today >= $valid_from;
103  }
104 
105  return false;
106  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ MB_TO_BYTES

const UploadPolicyResolver::MB_TO_BYTES = 1_000 * 1_000
protected

Multiply for MB to Bytes, divide for Bytes to MB.

Definition at line 29 of file UploadPolicyResolver.php.


The documentation for this class was generated from the following file: