Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ThemeManager.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 
40  class ThemeManager extends CThemeManager
41  {
42  const DEFAULT_THEME_COLOR = 'blue';
43 
44  const CUSTOM_NAME = 'custom';
45 
46  protected $useCustomTheme = true;
47 
48  public function resolveAndGetThemeColorValue(User $user)
49  {
50  assert('$user instanceOf User && $user->id > 0');
51  if ($this->forceAllUsersTheme)
52  {
53  return $this->globalThemeColor;
54  }
55  if ( null != $themeColor = ZurmoConfigurationUtil::getByUserAndModuleName($user, 'ZurmoModule', 'themeColor'))
56  {
57  return $themeColor;
58  }
59  else
60  {
61  return $this->getDefaultThemeColor();
62  }
63  }
64 
65  public function resolveAndGetBackgroundTextureValue(User $user)
66  {
67  assert('$user instanceOf User && $user->id > 0');
68  if ( null != $themeColor = ZurmoConfigurationUtil::getByUserAndModuleName($user, 'ZurmoModule', 'backgroundTexture'))
69  {
70  return $themeColor;
71  }
72  else
73  {
74  return null;
75  }
76  }
77 
78  public function getActiveThemeColor()
79  {
80  if (Yii::app()->user->userModel == null)
81  {
82  return $this->getDefaultThemeColor();
83  }
84  else
85  {
86  return $this->resolveAndGetThemeColorValue(Yii::app()->user->userModel);
87  }
88  }
89 
90  public function getActiveBackgroundTexture()
91  {
92  if (Yii::app()->user->userModel == null)
93  {
94  return null;
95  }
96  else
97  {
98  return $this->resolveAndGetBackgroundTextureValue(Yii::app()->user->userModel);
99  }
100  }
101 
102  public function setThemeColorValue(User $user, $value)
103  {
104  assert('is_string($value)');
105  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', 'themeColor', $value);
106  }
107 
108  public function setBackgroundTextureValue(User $user, $value)
109  {
110  assert('is_string($value) || $value == null');
111  ZurmoConfigurationUtil::setByUserAndModuleName($user, 'ZurmoModule', 'backgroundTexture', $value);
112  }
113 
114  public function setCustomThemeColorsArray($colorsArray)
115  {
116  assert('is_array($colorsArray)');
117  ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'customThemeColorsArray', $colorsArray);
118  }
119 
120  public function getCustomThemeColorsArray()
121  {
122  if ( null != $customThemeColorsArray = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'customThemeColorsArray'))
123  {
124  return $customThemeColorsArray;
125  }
126  else
127  {
128  return array('#282A76', '#7CB830', '#464646');
129  }
130  }
131 
132  public function setForceAllUsersTheme($value)
133  {
134  $value = (bool) $value;
135  ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'forceAllUsersTheme', $value);
136  }
137 
138  public function getForceAllUsersTheme()
139  {
140  return ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'forceAllUsersTheme');
141  }
142 
143  public function setGlobalThemeColor($value)
144  {
145  assert('is_string($value)');
146  ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'globalThemeColor', $value);
147  }
148 
149  public function getGlobalThemeColor()
150  {
151  if (null != $globalThemeColor = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'globalThemeColor'))
152  {
153  return $globalThemeColor;
154  }
155  else
156  {
157  return $this->getDefaultThemeColor();;
158  }
159  }
160 
161  public function getDefaultThemeColor()
162  {
163  return self::DEFAULT_THEME_COLOR;
164  }
165 
166  public function getThemeColorNamesAndLabels()
167  {
168  $data = array('blue' => Zurmo::t('Core', 'Blue'),
169  'brown' => Zurmo::t('Core', 'Brown'),
170  'cherry' => Zurmo::t('Core', 'Cherry'),
171  'honey' => Zurmo::t('Core', 'Honey'),
172  'lime' => Zurmo::t('Core', 'Lime'),
173  'turquoise' => Zurmo::t('Core', 'Turquoise'),
174  'violet' => Zurmo::t('Core', 'Violet'),
175  'sunrise' => Zurmo::t('Core', 'Sunrise'),
176  'marble' => Zurmo::t('Core', 'Marble'),
177  'purple-haze' => Zurmo::t('Core', 'Purple Haze'),
178  'flat-cement' => Zurmo::t('Core', 'Flat Cement'),
179  'amazon' => Zurmo::t('Core', 'Amazon'),
180  'sweden' => Zurmo::t('Core', 'Sweden'),
181  'pink' => Zurmo::t('Core', 'Pink'));
182  if ($this->useCustomTheme)
183  {
184  $customArray = array(static::CUSTOM_NAME => Zurmo::t('Core', 'Custom'));
185  $data = array_merge($customArray, $data);
186  }
187  return $data;
188  }
189 
190  public function getBackgroundTextureNamesAndLabels()
191  {
192  $data = array('exclusive-paper' => Zurmo::t('Core', 'Exclusive Paper'),
193  'french-stucco' => Zurmo::t('Core', 'French Stucco'),
194  'light-noise-diagonal' => Zurmo::t('Core', 'Light Noise'),
195  'light-toast' => Zurmo::t('Core', 'Light Toast'),
196  'diagonal-noise' => Zurmo::t('Core', 'Noise'),
197  'paper' => Zurmo::t('Core', 'Paper'),
198  'circles' => Zurmo::t('Core', 'Circle'),
199  'whitey' => Zurmo::t('Core', 'White Fabric'),
200  'fabric-plaid' => Zurmo::t('Core', 'Fabric Plaid'),
201  'cartographer-light' => Zurmo::t('Core', 'Cartographer Light'),
202  'wood' => Zurmo::t('Core', 'Wood'),
203  'black-linen-2' => Zurmo::t('Core', 'Black Linen'),
204  'carbon-fibre' => Zurmo::t('Core', 'Carbon Fibre'),
205  'cartographer' => Zurmo::t('Core', 'Cartographer'),
206  'concrete-wall' => Zurmo::t('Core', 'Concrete Wall'),
207  'denim' => Zurmo::t('Core', 'Denim'),
208  'low-contrast-linen' => Zurmo::t('Core', 'Low Contrast Linen'));
209  return $data;
210  }
211 
212  public function getThemeColorNamesAndUnlockedAtLevel()
213  {
214  $data = array('blue' => 1,
215  'brown' => 1,
216  'cherry' => 1,
217  'honey' => 1,
218  'lime' => 1,
219  'turquoise' => 1,
220  'violet' => 1,
221  'sunrise' => 2,
222  'marble' => 3,
223  'purple-haze' => 4,
224  'flat-cement' => 5,
225  'amazon' => 6,
226  'sweden' => 7,
227  'pink' => 8);
228  if ($this->useCustomTheme)
229  {
230  $data[static::CUSTOM_NAME] = 1;
231  }
232  return $data;
233  }
234 
235  public function getBackgroundTextureNamesAndUnlockedAtLevel()
236  {
237  $data = array('exclusive-paper' => 1,
238  'french-stucco' => 1,
239  'light-noise-diagonal' => 1,
240  'light-toast' => 1,
241  'diagonal-noise' => 1,
242  'paper' => 1,
243  'circles' => 4,
244  'whitey' => 5,
245  'fabric-plaid' => 6,
246  'cartographer-light' => 7,
247  'wood' => 8,
248  'black-linen-2' => 9,
249  'carbon-fibre' => 10,
250  'carbon-fibre-big' => 11,
251  'cartographer' => 12,
252  'concrete-wall' => 13,
253  'denim' => 14,
254  'low-contrast-linen' => 15);
255  return $data;
256  }
257 
258  public function getThemeColorNamesAndColors()
259  {
260  $data = array('blue' => array('#545454', '#282A76', '#7CB830', '#97c43d', '#464646'),
261  'brown' => array('#545454', '#547980', '#B88F30', '#45ADA8', '#594F4F'),
262  'cherry' => array('#545454', '#6C8092', '#933140', '#933140', '#464646'),
263  'honey' => array('#545454', '#46201C', '#ABBC42', '#6C7C16', '#A15C31'),
264  'lime' => array('#545454', '#2B434F', '#BCC98E', '#638270', '#464646'),
265  'turquoise' => array('#545454', '#447799', '#44BBCC', '#44BBCC', '#464646'),
266  'violet' => array('#545454', '#4A3970', '#91A1DC', '#91A1DC', '#464646'),
267  'sunrise' => array('#545454', '#34495e', '#c0392b', '#97c43d', '#2c3e50'),
268  'marble' => array('#545454', '#7f7f7f', '#333333', '#97c43d', '#323232'),
269  'purple-haze' => array('#545454', '#713b8a', '#854f9e', '#97c43d', '#34495e'),
270  'flat-cement' => array('#545454', '#2c3e50', '#2c3e50', '#97c43d', '#95a5a6'),
271  'amazon' => array('#545454', '#26354A', '#257282', '#97c43d', '#2F9E66'),
272  'sweden' => array('#545454', '#034C8C', '#024873', '#97c43d', '#f2ec5c'),
273  'pink' => array('#545454', '#323232', '#565656', '#97c43d', '#ff4f84')
274  );
275  $data = array_merge($data, $this->getCustomThemeColorNameAndColors());
276  return $data;
277  }
278 
279  public function getCustomThemeColorNameAndColors()
280  {
281  $data = array();
282  if ($this->useCustomTheme)
283  {
284  $customThemeColorsArray = $this->getCustomThemeColorsArray();
285  $data[static::CUSTOM_NAME] = array('#545454',
286  $customThemeColorsArray[0],
287  $customThemeColorsArray[1],
288  '#97c43d',
289  $customThemeColorsArray[2]);
290  }
291  return $data;
292  }
293 
294  public function registerThemeColorCss()
295  {
296  $cs = Yii::app()->getClientScript();
297  $themeName = Yii::app()->theme->name;
298  $themeBaseUrl = $this->baseUrl . '/' . $themeName;
299  if ($this->activeThemeColor != static::CUSTOM_NAME)
300  {
301  $cs->registerCssFile($themeBaseUrl . '/css/zurmo-' . $this->activeThemeColor . '.css' .
302  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/" . '/css/zurmo-' . $this->activeThemeColor . '.css'));
303  $cs->registerCssFile($themeBaseUrl . '/css/imports-' . $this->activeThemeColor . '.css' .
304  ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/" . '/css/imports-' . $this->activeThemeColor . '.css'));
305  }
306  else
307  {
308  $this->registerCustomThemeColorCss();
309  }
310  }
311 
312  public function registerCustomThemeColorCss()
313  {
314  $primaryFileName = 'zurmo-custom.css';
315  $secondaryFileName = 'imports-custom.css';
316  if (!is_file(Yii::app()->lessCompiler->compiledCustomCssPath . DIRECTORY_SEPARATOR . $primaryFileName) ||
317  !is_file(Yii::app()->lessCompiler->compiledCustomCssPath . DIRECTORY_SEPARATOR . $secondaryFileName))
318  {
319  Yii::app()->lessCompiler->compileColorDependentLessFile(static::CUSTOM_NAME);
320  }
321  $cs = Yii::app()->getClientScript();
322  $baseUrl = Yii::app()->getAssetManager()->publish(Yii::app()->lessCompiler->compiledCustomCssPath);
323  $cs->registerCssFile($baseUrl . DIRECTORY_SEPARATOR . $primaryFileName);
324  $cs->registerCssFile($baseUrl . DIRECTORY_SEPARATOR . $secondaryFileName);
325  }
326  }
327 ?>
Definition: User.php:37
static setByUserAndModuleName($user, $moduleName, $key, $value, $cache=true)
static getByUserAndModuleName($user, $moduleName, $key, $cache=true)
static getCssAndJavascriptHashQueryString($filePath)
static getByModuleName($moduleName, $key, $cache=true)
static setByModuleName($moduleName, $key, $value, $cache=true)
Generated on Thu Jul 9 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.