Merge pull request #24117 from civicrm/5.52
[civicrm-core.git] / CRM / Core / Permission / Standalone.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 *
20 */
21 class CRM_Core_Permission_Standalone extends CRM_Core_Permission_Base {
22
23 /**
24 * permission mapping to stub check() calls
25 * @var array
26 */
27 public $permissions = NULL;
28
29 /**
30 * Given a permission string, check for access requirements
31 *
32 * @param string $str
33 * The permission to check.
34 * @param int $userId
35 *
36 * @return bool
37 * true if yes, else false
38 */
39 public function check($str, $userId = NULL) {
40 if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
41 return FALSE;
42 }
43 if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
44 return TRUE;
45 }
46 // return the stubbed permission (defaulting to true if the array is missing)
47 return isset($this->permissions) && is_array($this->permissions) ? in_array($str, $this->permissions) : TRUE;
48 }
49
50 /**
51 * Get the permissioned where clause for the user.
52 *
53 * @param int $type
54 * The type of permission needed.
55 * @param array $tables
56 * (reference ) add the tables that are needed for the select clause.
57 * @param array $whereTables
58 * (reference ) add the tables that are needed for the where clause.
59 *
60 * @return string
61 * the group where clause for this user
62 */
63 public function whereClause($type, &$tables, &$whereTables) {
64 return '( 1 )';
65 }
66
67 }