All Data Structures Functions Variables Pages
SecurableModule.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  abstract class SecurableModule extends Module
38  {
39  protected static $policyDefaults = array();
40 
44  public static function getRightsNames()
45  {
46  $rightNames = array();
47  $reflectionClass = new ReflectionClass(get_called_class());
48  foreach ($reflectionClass->getConstants() as $key => $value)
49  {
50  if (self::filterRight($key))
51  {
52  $rightNames[] = $value;
53  }
54  }
55  return $rightNames;
56  }
57 
58  public static function getTranslatedRightsLabels()
59  {
60  return array();
61  }
62 
66  public static function getPolicyNames()
67  {
68  $policyNames = array();
69  $reflectionClass = new ReflectionClass(get_called_class());
70  foreach ($reflectionClass->getConstants() as $key => $value)
71  {
72  if (self::filterPolicy($key))
73  {
74  $policyNames[] = $value;
75  }
76  }
77  return $policyNames;
78  }
79 
80  public static function getTranslatedPolicyLabels()
81  {
82  return array();
83  }
84 
85  public static function getAuditEventNames()
86  {
87  $auditEventNames = array();
88  $reflectionClass = new ReflectionClass(get_called_class());
89  foreach ($reflectionClass->getConstants() as $key => $value)
90  {
91  if (self::filterAuditEvent($key))
92  {
93  $auditEventNames[] = $value;
94  }
95  }
96  return $auditEventNames;
97  }
98 
99  public static function stringifyAuditEvent(AuditEvent $auditEvent, $format = 'long')
100  {
101  assert('$format == "long" || $format == "short"');
102  return strval($auditEvent);
103  }
104 
105  private static function filterRight($s)
106  {
107  return substr($s, 0, 6) == 'RIGHT_';
108  }
109 
110  private static function filterPolicy($s)
111  {
112  return substr($s, 0, 7) == 'POLICY_';
113  }
114 
115  private static function filterAuditEvent($s)
116  {
117  return substr($s, 0, 6) == 'AUDIT_EVENT_';
118  }
119 
123  public static function getPolicyRulesTypes()
124  {
125  return array();
126  }
127 
128  public static function getPolicyDefault($policyName)
129  {
130  assert('is_string($policyName) && $policyName != ""');
131  $className = get_called_class();
132  $policyDefaults = $className::$policyDefaults;
133  if (array_key_exists($policyName, $policyDefaults))
134  {
135  return $policyDefaults[$policyName];
136  }
137  return null;
138  }
139 
140  public static function isPolicyYesNo($value)
141  {
142  return in_array($value, array(Policy::NO, Policy::YES));
143  }
144 
151  public static function getAccessRight()
152  {
153  return null;
154  }
155 
161  public static function getCreateRight()
162  {
163  return null;
164  }
165 
171  public static function getDeleteRight()
172  {
173  return null;
174  }
175 
176  public static function getSecurableModuleDisplayName()
177  {
178  return static::getModuleLabelByTypeAndLanguage('Plural');
179  }
180 
184  public static function hasPermissions()
185  {
186  return false;
187  }
188  }
189 ?>
static getRightsNames()
static getPolicyNames()
static getPolicyRulesTypes()
Generated on Thu Apr 2 2020 07:10:46