Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ThemeColorElement.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 ThemeColorElement extends Element
41  {
42  protected $shouldDisableLocked = true;
43 
44  protected $showLocked = true;
45 
50  protected function renderControlEditable()
51  {
52  if (!$this->shouldRenderControlEditable())
53  {
54  return null;
55  }
56  $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, Yii::app()->user->userModel);
57  $content = null;
58  $content .= $this->form->radioButtonList(
59  $this->model,
60  $this->getAttributeForRadioButtonList(),
61  $this->resolveThemeColorNamesAndLabelsForLocking($gameLevel),
62  $this->getEditableHtmlOptions(),
63  array(),
64  $this->resolveDataHtmlOptions($gameLevel)
65  );
66  $this->registerScript();
67  return $content;
68  }
69 
70  protected function getAttributeForRadioButtonList()
71  {
72  return $this->attribute;
73  }
74 
75  protected function shouldRenderControlEditable()
76  {
77  if (Yii::app()->themeManager->forceAllUsersTheme)
78  {
79  return false;
80  }
81  return true;
82  }
83 
84  protected function renderControlNonEditable()
85  {
86  throw new NotImplementedException();
87  }
88 
93  protected function getEditableHtmlOptions()
94  {
95  $htmlOptions = array();
96  $htmlOptions['separator'] = '';
97  $htmlOptions['template'] = '<div class="radio-input color-swatch {value}">{input}{label}</div>';
98  return $htmlOptions;
99  }
100 
101  public function registerScript()
102  {
103  $removeScript = null;
104  foreach (Yii::app()->themeManager->getThemeColorNamesAndLabels() as $value => $notUsed)
105  {
106  $removeScript .= '$(document.body).removeClass("' . $value . '");' . "\n";
107  }
108  $themeName = Yii::app()->theme->name;
109  $themeBaseUrl = Yii::app()->themeManager->baseUrl . '/default/css';
110 
111  $primaryFileName = 'zurmo-custom.css';
112  $secondaryFileName = 'imports-custom.css';
113  if (Yii::app()->themeManager->activeThemeColor != ThemeManager::CUSTOM_NAME)
114  {
115  Yii::app()->themeManager->registerThemeColorCss();
116  }
117  $primaryCustomCssUrl = Yii::app()->assetManager->getPublishedUrl(Yii::app()->lessCompiler->compiledCustomCssPath) . DIRECTORY_SEPARATOR . $primaryFileName;
118  $secondaryCustomCssUrl = Yii::app()->assetManager->getPublishedUrl(Yii::app()->lessCompiler->compiledCustomCssPath) . DIRECTORY_SEPARATOR . $secondaryFileName;
119 
120  // Begin Not Coding Standard
121  $script = "$('input[name=\"" . $this->getEditableInputName($this->getAttributeForRadioButtonList()) . "\"]').live('change', function(){
122  $removeScript
123  $(document.body).addClass(this.value);
124  var themeBaseUrl = '$themeBaseUrl';
125  var primaryCustomCssUrl = '$primaryCustomCssUrl';
126  var secondaryCustomCssUrl = '$secondaryCustomCssUrl';
127  //use zurmo-blue since it is likely that all colors would change at same time. best we can do here for now
128  var baseHashQueryString = '" . ZurmoAssetManager::getCssAndJavascriptHashQueryString("themes/$themeName/" . '/css/zurmo-blue.css') . "';
129  if(this.value === 'custom')
130  {
131  $('head').append('<link rel=\"stylesheet\" href=\"'+primaryCustomCssUrl+'\" type=\"text/css\" />');
132  $('head').append('<link rel=\"stylesheet\" href=\"'+secondaryCustomCssUrl+'\" type=\"text/css\" />');
133  }
134  else
135  {
136  $('head').append('<link rel=\"stylesheet\" href=\"'+themeBaseUrl+'/zurmo-'+this.value+'.css' + baseHashQueryString + '\" type=\"text/css\" />');
137  }
138  });
139  ";
140  // End Not Coding Standard
141  Yii::app()->clientScript->registerScript('changeThemeColor', $script);
142  }
143 
144  protected function resolveThemeColorNamesAndLabelsForLocking(GameLevel $gameLevel)
145  {
146  $namesAndUnlockedAtLevels = Yii::app()->themeManager->getThemeColorNamesAndUnlockedAtLevel();
147  $data = array();
148  foreach (Yii::app()->themeManager->getThemeColorNamesAndLabels() as $name => $label)
149  {
150  $colorArray = Yii::app()->themeManager->themeColorNamesAndColors[$name];
151  $spans = '<span class="theme-color-1" style="background-color:' . $colorArray[1] . '"></span>';
152  $spans .= '<span class="theme-color-2" style="background-color:' . $colorArray[2] . '"></span>';
153  $spans .= '<span class="theme-color-3" style="background-color:' . $colorArray[4] . '"></span>';
154  $label = $spans . $label;
155  $unlockedAtLevel = $namesAndUnlockedAtLevels[$name];
156  if ($unlockedAtLevel > (int)$gameLevel->value && $this->shouldDisableLocked)
157  {
158  $title = Zurmo::t('GamificationModule', 'Unlocked at level {level}', array('{level}' => $unlockedAtLevel));
159  $content = '<span id="theme-color-tooltip-' . $name. '" title="' . $title . '"><i class="icon-lock"></i></span>' . $label; // Not Coding Standard
160  $qtip = new ZurmoTip();
161  $qtip->addQTip("#theme-color-tooltip-" . $name);
162  }
163  else
164  {
165  $content = $label;
166  }
167  if (($unlockedAtLevel <= 1) || $this->showLocked)
168  {
169  $data[$name] = $content;
170  }
171  }
172  return $data;
173  }
174 
175  protected function resolveDataHtmlOptions(GameLevel $gameLevel)
176  {
177  $dataHtmlOptions = array();
178  foreach (Yii::app()->themeManager->getThemeColorNamesAndUnlockedAtLevel() as $name => $unlockedAtLevel)
179  {
180  $dataHtmlOptions[$name] = array();
181  if ($unlockedAtLevel > (int)$gameLevel->value && $this->shouldDisableLocked)
182  {
183  $dataHtmlOptions[$name]['class'] = 'locked';
184  $dataHtmlOptions[$name]['disabled'] = 'disabled';
185  }
186  }
187  return $dataHtmlOptions;
188  }
189  }
190 ?>
static resolveByTypeAndPerson($type, Item $person)
Definition: GameLevel.php:90
getEditableInputName($attributeName=null, $relationAttributeName=null)
Definition: Element.php:303
static getCssAndJavascriptHashQueryString($filePath)
Generated on Sat Aug 15 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.