Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ZurmoConfigurationUtil.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 
41  {
46  public static function getForCurrentUserByModuleName($moduleName, $key, $cache = true)
47  {
48  assert('is_string($moduleName)');
49  assert('is_string($key)');
50  assert('Yii::app()->user->userModel == null || Yii::app()->user->userModel->id > 0');
51  if (!Yii::app()->user->userModel instanceof User)
52  {
53  return null;
54  }
55  return static::getByUserAndModuleName(Yii::app()->user->userModel, $moduleName, $key, $cache);
56  }
57 
62  public static function getByModuleName($moduleName, $key, $cache = true)
63  {
64  assert('is_string($moduleName)');
65  assert('is_string($key)');
67  {
68  return null;
69  }
70  $value = static::getCachedValue($moduleName, $key, null, $cache);
71  if ($value === null)
72  {
73  $metadata = $moduleName::getMetadata();
74  if (isset($metadata['global']) && isset($metadata['global'][$key]))
75  {
76  $value = $metadata['global'][$key];
77  static::cacheValue($moduleName, $key, $value, null, $cache);
78  }
79  }
80  return $value;
81  }
82 
87  public static function getByUserAndModuleName($user, $moduleName, $key, $cache = true)
88  {
89  assert('$user instanceof User && $user->id > 0');
90  assert('is_string($moduleName)');
91  assert('is_string($key)');
92  $value = static::getCachedValue($moduleName, $key, $user->id, $cache);
93  if ($value === null)
94  {
95  $metadata = $moduleName::getMetadata($user);
96  if (isset($metadata['perUser']) && isset($metadata['perUser'][$key]))
97  {
98  $value = $metadata['perUser'][$key];
99  }
100  elseif (isset($metadata['global']) && isset($metadata['global'][$key]))
101  {
102  $value = $metadata['global'][$key];
103  }
104  static::cacheValue($moduleName, $key, $value, $user->id, $cache);
105  }
106  return $value;
107  }
108 
112  public static function setForCurrentUserByModuleName($moduleName, $key, $value, $cache = true)
113  {
114  assert('is_string($moduleName)');
115  assert('is_string($key)');
116  assert('Yii::app()->user->userModel == null || Yii::app()->user->userModel->id > 0');
117  if (!Yii::app()->user->userModel instanceof User)
118  {
119  return null;
120  }
121  static::setByUserAndModuleName(Yii::app()->user->userModel, $moduleName, $key, $value, $cache);
122  }
123 
127  public static function setByModuleName($moduleName, $key, $value, $cache = true)
128  {
129  assert('is_string($moduleName)');
130  assert('is_string($key)');
132  {
133  return null;
134  }
135  $metadata = $moduleName::getMetadata();
136  $metadata['global'][$key] = $value;
137  static::cacheValue($moduleName, $key, $value, null, $cache);
138  $moduleName::setMetadata($metadata);
139  }
140 
144  public static function setByUserAndModuleName($user, $moduleName, $key, $value, $cache = true)
145  {
146  assert('$user instanceof User && $user->id > 0');
147  assert('is_string($moduleName)');
148  assert('is_string($key)');
149  $metadata = $moduleName::getMetadata($user);
150  $metadata['perUser'][$key] = $value;
151  static::cacheValue($moduleName, $key, $value, $user->id, $cache);
152  $moduleName::setMetadata($metadata, $user);
153  }
154 
155  protected static function getCacheKey($moduleName, $configKey, $userId = null)
156  {
157  $cacheKey = "${moduleName}.{$configKey}";
158  $prefix = 'global.';
159  if ($userId !== null)
160  {
161  $prefix = 'perUser_' . $userId . '.';
162  }
163  $cacheKey = get_called_class() . '.' . $prefix . $cacheKey;
164  return $cacheKey;
165  }
166 
167  protected static function getCachedValue($moduleName, $configKey, $userId = null, $cache = true)
168  {
169  if ($cache === false)
170  {
171  return null;
172  }
173  $cacheKey = static::getCacheKey($moduleName, $configKey, $userId);
174  $value = null;
175  try
176  {
177  $value = GeneralCache::getEntry($cacheKey);
178  }
179  catch (NotFoundException $e)
180  {
181  }
182  return $value;
183  }
184 
185  protected static function cacheValue($moduleName, $configKey, $value, $userId = null, $cache = true)
186  {
187  if ($cache === false)
188  {
189  return;
190  }
191  $cacheKey = static::getCacheKey($moduleName, $configKey, $userId);
192  GeneralCache::cacheEntry($cacheKey, $value);
193  }
194  }
195 ?>
Definition: User.php:37
static setByUserAndModuleName($user, $moduleName, $key, $value, $cache=true)
static getByUserAndModuleName($user, $moduleName, $key, $cache=true)
static setForCurrentUserByModuleName($moduleName, $key, $value, $cache=true)
static getForCurrentUserByModuleName($moduleName, $key, $cache=true)
static getByModuleName($moduleName, $key, $cache=true)
static setByModuleName($moduleName, $key, $value, $cache=true)
Generated on Thu Sep 24 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.