Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
UserConfigurationFormAdapter.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 
42  {
46  public static function makeFormFromUserConfigurationByUser(User $user)
47  {
48  assert('$user instanceOf User && $user->id > 0');
49  $form = new UserConfigurationForm($user);
50  $form->listPageSize = Yii::app()->pagination->getByUserAndType($user, 'listPageSize');
51  $form->subListPageSize = Yii::app()->pagination->getByUserAndType($user, 'subListPageSize');
52  $form->dashboardListPageSize = Yii::app()->pagination->getByUserAndType($user, 'dashboardListPageSize');
53  $form->themeColor = Yii::app()->themeManager->resolveAndGetThemeColorValue($user);
54  $form->backgroundTexture = Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($user);
55  $form->hideWelcomeView = static::resolveAndGetValue($user, 'hideWelcomeView');
56  $form->enableDesktopNotifications = static::resolveAndGetValue($user, 'enableDesktopNotifications');
57  $form->defaultPermissionGroupSetting = static::resolveAndGetValue($user, 'defaultPermissionGroupSetting', false);
58  $form->defaultPermissionSetting = static::resolveAndGetDefaultPermissionSetting($user);
59  $form->visibleAndOrderedTabMenuItems = static::getVisibleAndOrderedTabMenuItemsByUser($user);
60  $form->selectedVisibleAndOrderedTabMenuItems = static::getVisibleAndOrderedTabMenuItemsByUser($user, true);
61  $form->hideFromSelecting = $user->hideFromSelecting;
62  $form->hideFromLeaderboard = $user->hideFromLeaderboard;
63  return $form;
64  }
65 
69  public static function setConfigurationFromForm(UserConfigurationForm $form, User $user)
70  {
71  assert('$user instanceOf User && $user->id > 0');
72  Yii::app()->pagination->setByUserAndType($user, 'listPageSize', (int)$form->listPageSize);
73  Yii::app()->pagination->setByUserAndType($user, 'subListPageSize', (int)$form->subListPageSize);
74  Yii::app()->pagination->setByUserAndType($user, 'dashboardListPageSize', (int)$form->dashboardListPageSize);
75  Yii::app()->themeManager->setThemeColorValue($user, $form->themeColor);
76  Yii::app()->themeManager->setBackgroundTextureValue ($user, $form->backgroundTexture);
77  static::setValue($user, (bool)$form->hideWelcomeView, 'hideWelcomeView');
78  static::setValue($user, (bool)$form->enableDesktopNotifications, 'enableDesktopNotifications');
79  static::setValue($user, (int)$form->defaultPermissionSetting, 'defaultPermissionSetting', false);
80  static::setDefaultPermissionGroupSetting($user, (int)$form->defaultPermissionGroupSetting,
81  (int)$form->defaultPermissionSetting);
82  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', 'VisibleAndOrderedTabMenuItems',
83  serialize($form->selectedVisibleAndOrderedTabMenuItems));
85 
86  $user->hideFromSelecting = $form->hideFromSelecting;
87  $user->hideFromLeaderboard = $form->hideFromLeaderboard;
88  $saved = $user->save();
89  if (!$saved)
90  {
91  throw new FailedToSaveModelException();
92  }
93  }
94 
100  {
101  $user = Yii::app()->user->userModel;
102  static::setConfigurationFromForm($form, $user);
103  Yii::app()->user->setState('listPageSize', (int)$form->listPageSize);
104  Yii::app()->user->setState('subListPageSize', (int)$form->subListPageSize);
105  Yii::app()->user->setState('dashboardListPageSize', (int)$form->dashboardListPageSize);
106  }
107 
114  public static function resolveAndGetValue(User $user, $key, $returnBoolean = true)
115  {
116  assert('$user instanceOf User && $user->id > 0');
117  assert('is_string($key)');
118  assert('is_bool($returnBoolean)');
119  $value = ZurmoConfigurationUtil::getByUserAndModuleName($user, 'ZurmoModule', $key);
120  return ($returnBoolean)? (bool) $value : $value;
121  }
122 
123  public static function setValue(User $user, $value, $key, $saveBoolean = true)
124  {
125  assert('is_bool($saveBoolean)');
126  assert('is_string($key)');
127  $value = ($saveBoolean)? (bool) $value : $value;
128  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', $key, $value);
129  }
130 
135  public static function resolveAndGetDefaultPermissionSetting(User $user)
136  {
137  assert('$user instanceOf User && $user->id > 0');
138  if ( null != $defaultPermission = ZurmoConfigurationUtil::getByUserAndModuleName($user, 'ZurmoModule',
139  'defaultPermissionSetting'))
140  {
141  return $defaultPermission;
142  }
143  else
144  {
145  return UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE;
146  }
147  }
148 
154  public static function setDefaultPermissionGroupSetting(User $user, $value, $defaultPermissionSetting)
155  {
156  assert('$value === null || is_int($value)');
157  assert('$defaultPermissionSetting === null || is_int($defaultPermissionSetting)');
158  if ($defaultPermissionSetting == UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP)
159  {
160  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', 'defaultPermissionGroupSetting',
161  $value);
162  }
163  else
164  {
165  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', 'defaultPermissionGroupSetting',
166  null);
167  }
168  }
169 
175  public static function getVisibleAndOrderedTabMenuItemsByUser($user, $selected = false)
176  {
177  $visibleAndOrderedTabMenuItems = array();
178  $tabMenuItems = MenuUtil::getVisibleAndOrderedTabMenuByUser($user);
179  foreach ($tabMenuItems as $menuItem)
180  {
181  if ($selected === true)
182  {
183  $visibleAndOrderedTabMenuItems[] = $menuItem['moduleId'];
184  }
185  else
186  {
187  $moduleId = $menuItem['moduleId'];
188  $visibleAndOrderedTabMenuItems[$moduleId] = $menuItem['label'];
189  }
190  }
191  return $visibleAndOrderedTabMenuItems;
192  }
193  }
194 ?>
static resolveAndGetDefaultPermissionSetting(User $user)
static forgetCacheEntryForTabMenuByUser($user)
Definition: MenuUtil.php:138
static setConfigurationFromForm(UserConfigurationForm $form, User $user)
static getVisibleAndOrderedTabMenuItemsByUser($user, $selected=false)
Definition: User.php:37
static setByUserAndModuleName($user, $moduleName, $key, $value, $cache=true)
static setDefaultPermissionGroupSetting(User $user, $value, $defaultPermissionSetting)
static getByUserAndModuleName($user, $moduleName, $key, $cache=true)
static getVisibleAndOrderedTabMenuByUser($user)
Definition: MenuUtil.php:160
static makeFormFromUserConfigurationByUser(User $user)
static setConfigurationFromFormForCurrentUser(UserConfigurationForm $form)
static resolveAndGetValue(User $user, $key, $returnBoolean=true)
Generated on Sun Aug 9 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.