All Data Structures Functions Variables Pages
BackgroundTextureElement.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  protected function renderControlEditable()
47  {
48  $gameLevel = GameLevel::resolveByTypeAndPerson(GameLevel::TYPE_GENERAL, Yii::app()->user->userModel);
49  $content = null;
50  $content .= $this->form->radioButtonList(
51  $this->model,
52  $this->attribute,
53  $this->makeData($gameLevel),
54  $this->getEditableHtmlOptions(),
55  array(),
56  $this->resolveDataHtmlOptions($gameLevel)
57  );
58  $this->registerScript();
59  return $content;
60  }
61 
62  protected function renderControlNonEditable()
63  {
64  throw new NotImplementedException();
65  }
66 
71  protected function getEditableHtmlOptions()
72  {
73  $htmlOptions = array();
74  $htmlOptions['separator'] = '';
75  $htmlOptions['template'] = '<div class="radio-input texture-swatch {value}">{input}{label}</div>';
76  return $htmlOptions;
77  }
78 
79  protected function makeData(GameLevel $gameLevel)
80  {
81  $data = array('' => '<span class="background-texture-1"></span>' . Zurmo::t('Core', 'None'));
82  return array_merge($data, $this->resolveBackgroundTextureNamesAndLabelsForLocking($gameLevel));
83  }
84 
85  public function registerScript()
86  {
87  $removeScript = null;
88  foreach (Yii::app()->themeManager->getBackgroundTextureNamesAndLabels() as $value => $notUsed)
89  {
90  $removeScript .= '$(document.documentElement).removeClass("' . $value . '");' . "\n";
91  }
92  // Begin Not Coding Standard
93  $script = "$('input[name=\"" . $this->getEditableInputName() . "\"]').live('change', function(){
94  $removeScript
95  $(document.documentElement).addClass(this.value);
96  });
97  ";
98  // End Not Coding Standard
99  Yii::app()->clientScript->registerScript('changeBackgroundTexture', $script);
100  }
101 
102  protected function resolveBackgroundTextureNamesAndLabelsForLocking(GameLevel $gameLevel)
103  {
104  $namesAndUnlockedAtLevels = Yii::app()->themeManager->getBackgroundTextureNamesAndUnlockedAtLevel();
105  $data = array();
106  foreach (Yii::app()->themeManager->getBackgroundTextureNamesAndLabels() as $name => $label)
107  {
108  $label = '<span class="background-texture-1"></span>' . $label;
109  $unlockedAtLevel = $namesAndUnlockedAtLevels[$name];
110  if ($unlockedAtLevel > (int)$gameLevel->value)
111  {
112  $title = Zurmo::t('GamificationModule', 'Unlocked at level {level}', array('{level}' => $unlockedAtLevel));
113  $content = '<span id="background-texture-tooltip-' . $name. '" title="' . $title . '"><i class="icon-lock"></i></span>' . $label; // Not Coding Standard
114  $qtip = new ZurmoTip();
115  $qtip->addQTip("#background-texture-tooltip-" . $name);
116  }
117  else
118  {
119  $content = $label;
120  }
121  $data[$name] = $content;
122  }
123  return $data;
124  }
125 
126  protected function resolveDataHtmlOptions(GameLevel $gameLevel)
127  {
128  $dataHtmlOptions = array();
129  foreach (Yii::app()->themeManager->getBackgroundTextureNamesAndUnlockedAtLevel() as $name => $unlockedAtLevel)
130  {
131  $dataHtmlOptions[$name] = array();
132  if ($unlockedAtLevel > (int)$gameLevel->value)
133  {
134  $dataHtmlOptions[$name]['class'] = 'locked';
135  $dataHtmlOptions[$name]['disabled'] = 'disabled';
136  }
137  }
138  return $dataHtmlOptions;
139  }
140  }
141 ?>
static resolveByTypeAndPerson($type, Item $person)
Definition: GameLevel.php:90
getEditableInputName($attributeName=null, $relationAttributeName=null)
Definition: Element.php:303
Generated on Sat Feb 22 2020 07:10:33