ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilLearningProgressAccess.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 /*
5  +-----------------------------------------------------------------------------+
6  | ILIAS open source |
7  +-----------------------------------------------------------------------------+
8  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9  | |
10  | This program is free software; you can redistribute it and/or |
11  | modify it under the terms of the GNU General Public License |
12  | as published by the Free Software Foundation; either version 2 |
13  | of the License, or (at your option) any later version. |
14  | |
15  | This program is distributed in the hope that it will be useful, |
16  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18  | GNU General Public License for more details. |
19  | |
20  | You should have received a copy of the GNU General Public License |
21  | along with this program; if not, write to the Free Software |
22  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23  +-----------------------------------------------------------------------------+
24 */
25 
32 {
36  public static function checkPermission(
37  string $a_permission,
38  int $a_ref_id,
39  ?int $a_user_id = null
40  ): bool {
41  global $DIC;
42 
43  if ($a_user_id === null) {
44  $a_user_id = $DIC->user()->getId();
45  }
46 
47  // position access
48  if ($a_permission === 'read_learning_progress') {
49  return $DIC->access()->checkRbacOrPositionPermissionAccess(
52  $a_ref_id
53  );
54  }
55  return $DIC->access()->checkAccessOfUser(
56  $a_user_id,
57  $a_permission,
58  '',
59  $a_ref_id
60  );
61  }
62 
66  public static function checkAccess(
67  int $a_ref_id,
68  bool $a_allow_only_read = true
69  ): bool {
70  global $DIC;
71 
72  if ($DIC->user()->getId() == ANONYMOUS_USER_ID) {
73  return false;
74  }
75 
77  return false;
78  }
79 
81  if (
82  $olp->isActive() && (
83  $DIC->access()->checkAccess(
84  'read_learning_progress',
85  '',
86  $a_ref_id
87  ) ||
88  $DIC->access()->checkRbacOrPositionPermissionAccess(
91  $a_ref_id
92  )
93  )
94  ) {
95  return true;
96  }
97 
98  if (!$DIC->access()->checkAccess('read', '', $a_ref_id)) {
99  return false;
100  }
101  // edit learning progress is sufficient: #0029313
102  if ($DIC->access()->checkAccess(
103  'edit_learning_progress',
104  '',
105  $a_ref_id
106  )) {
107  return true;
108  }
109 
111  return false;
112  }
113 
114  if (!$olp->isActive()) {
115  return false;
116  }
117 
118  if ($a_allow_only_read) {
119  return true;
120  }
121  return false;
122  }
123 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
static checkAccess(int $a_ref_id, bool $a_allow_only_read=true)
check access to learning progress
Learning progress access checks.
static _lookupObjId(int $ref_id)
global $DIC
Definition: shib_login.php:25
static checkPermission(string $a_permission, int $a_ref_id, ?int $a_user_id=null)
wrapper for rbac access checks
static getInstance(int $obj_id)