Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MbMenu.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 
37  Yii::import('zii.widgets.CMenu');
38 
46  class MbMenu extends CMenu
47  {
48  private $baseUrl;
49 
50  protected $themeUrl;
51 
52  protected $theme;
53 
54  protected $cssFile;
55 
56  protected $cssIeStylesFile = null;
57 
58  private $nljs;
59 
60  public $activateParents = true;
61 
62  public $navContainerClass = 'nav-container';
63 
64  public $navBarClass = 'nav-bar';
65 
66  public $labelPrefix = null;
67 
68  public $labelPrefixOptions = array();
69 
70  public $linkPrefix = null;
71 
75  protected function createJsCode()
76  {
77  $js = '';
78  $js .= ' $(".nav li").hover(' . $this->nljs;
79  $js .= ' function () {' . $this->nljs; // Not Coding Standard
80  $js .= ' if ($(this).hasClass("parent")) {' . $this->nljs; // Not Coding Standard
81  $js .= ' $(this).addClass("over");' . $this->nljs;
82  $js .= ' }' . $this->nljs;
83  $js .= ' },' . $this->nljs; // Not Coding Standard
84  $js .= ' function () {' . $this->nljs; // Not Coding Standard
85  $js .= ' $(this).removeClass("over");' . $this->nljs;
86  $js .= ' }' . $this->nljs;
87  $js .= ' );' . $this->nljs;
88  return $js;
89  }
90 
94  protected function cssLastItems($items)
95  {
96  $i = max(array_keys($items));
97  $item = $items[$i];
98  if (isset($item['itemOptions']['class']))
99  {
100  $items[$i]['itemOptions']['class'] .= ' last';
101  }
102  else
103  {
104  $items[$i]['itemOptions']['class'] = 'last';
105  }
106  foreach ($items as $i => $item)
107  {
108  if (isset($item['items']))
109  {
110  $items[$i]['items'] = $this->cssLastItems($item['items']);
111  }
112  }
113  return array_values($items);
114  }
115 
119  protected function cssParentItems($items)
120  {
121  foreach ($items as $i => $item)
122  {
123  if (isset($item['items']))
124  {
125  if (isset($item['itemOptions']['class']))
126  {
127  $items[$i]['itemOptions']['class'] .= ' parent';
128  }
129  else
130  {
131  $items[$i]['itemOptions']['class'] = 'parent';
132  }
133  $items[$i]['items'] = $this->cssParentItems($item['items']);
134  }
135  }
136  return array_values($items);
137  }
138 
142  public function init()
143  {
144  if (!$this->getId(false))
145  {
146  $this->setId('nav');
147  }
148  $this->themeUrl = Yii::app()->themeManager->baseUrl;
149  $this->theme = Yii::app()->theme->name;
150  $this->nljs = "\n";
151  $this->items = $this->cssParentItems($this->items);
152  $this->items = $this->cssLastItems($this->items);
153  $route = $this->getController()->getRoute();
154  $hasActiveChild = null;
155  $this->items = $this->normalizeItems(
156  $this->items,
157  $this->getController()->getRoute(),
158  $hasActiveChild
159  );
160  $this->resolveNavigationClass();
161  }
162 
166  public function registerClientScripts()
167  {
168  // add the script
169  $cs = Yii::app()->getClientScript();
170  $cs->registerCoreScript('jquery');
171  $js = $this->createJsCode();
172  $cs->registerScript('mbmenu_' . $this->getId(), $js, CClientScript::POS_READY);
173  }
174 
175  public function registerCssFile()
176  {
177  $cs = Yii::app()->getClientScript();
178  if ($this->cssFile != null)
179  {
180  $cs->registerCssFile($this->themeUrl . '/' . $this->theme . '/' . $this->cssFile, 'screen');
181  }
182  if (Yii::app()->browser->getName() == 'msie' && Yii::app()->browser->getVersion() < 8 && $this->cssIeStylesFile != null)
183  {
184  $cs->registerCssFile($this->themeUrl . '/' . $this->theme . '/' . $this->cssIeStylesFile, 'screen');
185  }
186  }
187 
188  protected function renderMenuRecursive($items)
189  {
190  foreach ($items as $item)
191  {
192  $liCloseTag = null;
193  if ($this->doRenderMenuHeader($item))
194  {
195  $liOptions = $this->resolveItemOptions($item);
196  $liOpenTag = ZurmoHtml::openTag('li', $liOptions);
197  $menuItem = $this->renderMenuItem($item);
198  $liCloseTag = ZurmoHtml::closeTag('li') . "\n";
199  echo $liOpenTag;
200  echo $menuItem;
201  }
202  if ($this->doRenderSubMenu($item))
203  {
204  $this->renderSubMenu($item);
205  }
206  echo $liCloseTag;
207  }
208  }
209 
210  protected function resolveItemOptions(array $item)
211  {
212  $liOptions = array();
213  if (isset($item['itemOptions']))
214  {
215  $liOptions = $item['itemOptions'];
216  }
217  return $liOptions;
218  }
219 
220  protected function resolveHtmlOptions(array $item)
221  {
222  $htmlOptions = array();
223  if (isset($item['linkOptions']))
224  {
225  $htmlOptions = $item['linkOptions'];
226  }
227  return $htmlOptions;
228  }
229 
230  protected function resolveLabelContent(array $item)
231  {
232  $label = $item['label'];
233  if (isset($item['labelSpanHtmlOptions']))
234  {
235  $labelSpanHtmlOptions = $item['labelSpanHtmlOptions'];
236  }
237  else
238  {
239  $labelSpanHtmlOptions = array();
240  }
241  $content = $this->renderLabelPrefix() . ZurmoHtml::tag('span', $labelSpanHtmlOptions, $label);
242  return $content . $this->resolveAndGetSpanAndDynamicLabelContent($item);
243  }
244 
245  protected function renderMenuItem($item)
246  {
247  $htmlOptions = $this->resolveHtmlOptions($item);
248  $resolvedLabelContent = $this->resolveLabelContent($item);
249  if ((isset($item['ajaxLinkOptions'])))
250  {
251  return ZurmoHtml::ajaxLink($resolvedLabelContent, $item['url'], $item['ajaxLinkOptions'], $htmlOptions);
252  }
253  elseif (isset($item['url']))
254  {
255  return ZurmoHtml::link($this->renderLinkPrefix() . $resolvedLabelContent, $item['url'], $htmlOptions);
256  }
257  else
258  {
259  return $this->renderMenuItemWithNoURLSpecified($resolvedLabelContent, $htmlOptions, $item);
260  }
261  }
262 
263  protected function renderMenuItemWithNoURLSpecified($resolvedLabelContent, array $htmlOptions, array $item)
264  {
265  return ZurmoHtml::link($resolvedLabelContent, "javascript:void(0);", $htmlOptions);
266  }
267 
268  protected function renderSubMenu(array $item)
269  {
270  $nestedUlOpen = null;
271  $nestedUlClose = null;
272  if ($this->doRenderMenuHeader($item))
273  {
274  // only nest it if we rendered the header, no point in nesting it if we didn't.
275  $nestedUlOpen = "\n" . ZurmoHtml::openTag('ul', $this->submenuHtmlOptions) . "\n";
276  $nestedUlClose = ZurmoHtml::closeTag('ul') . "\n";
277  }
278  echo $nestedUlOpen;
279  $this->renderMenuRecursive($item['items']);
280  echo $nestedUlClose;
281  }
282 
283  protected function resolveAndGetSpanAndDynamicLabelContent(array $item)
284  {
285  if (isset($item['dynamicLabelContent']))
286  {
287  return $item['dynamicLabelContent'];
288  }
289  }
290 
291  protected function resolveNavigationClass()
292  {
293  if (isset($this->htmlOptions['class']))
294  {
295  $this->htmlOptions['class'] .= ' nav';
296  }
297  else
298  {
299  $this->htmlOptions['class'] = 'nav';
300  }
301  }
302 
303  protected function normalizeItems($items, $route, &$active, $ischild = 0)
304  {
305  foreach ($items as $i => $item)
306  {
307  if (isset($item['visible']) && !$item['visible'])
308  {
309  unset($items[$i]);
310  continue;
311  }
312  if ($this->encodeLabel)
313  {
314  $items[$i]['label'] = Yii::app()->format->text($item['label']);
315  }
316  $hasActiveChild = false;
317  if (isset($item['items']))
318  {
319  $items[$i]['items'] = $this->normalizeItems($item['items'], $route, $hasActiveChild, 1);
320  if (empty($items[$i]['items']) && $this->hideEmptyItems)
321  {
322  unset($items[$i]['items']);
323  }
324  }
325  if (!isset($item['active']))
326  {
327  if (($this->activateParents && $hasActiveChild) || $this->isItemActive($item, $route))
328  {
329  $active = $items[$i]['active'] = true;
330  }
331  else
332  {
333  $items[$i]['active'] = false;
334  }
335  }
336  elseif ($item['active'])
337  {
338  $active = true;
339  }
340  if ($items[$i]['active'] && $this->activeCssClass != '')
341  {
342  if (isset($item['itemOptions']['class']))
343  {
344  $items[$i]['itemOptions']['class'] .= ' ' . $this->activeCssClass;
345  }
346  else
347  {
348  $items[$i]['itemOptions']['class'] = $this->activeCssClass;
349  }
350  }
351  }
352  return array_values($items);
353  }
354 
355  protected function renderLabelPrefix()
356  {
357  if ($this->labelPrefix)
358  {
359  return ZurmoHtml::tag($this->labelPrefix, $this->labelPrefixOptions, '');
360  }
361  }
362 
363  protected function renderLinkPrefix()
364  {
365  if ($this->linkPrefix)
366  {
367  return ZurmoHtml::tag($this->linkPrefix, array(), '');
368  }
369  }
370 
371  protected function doRenderMenuHeader(array $item)
372  {
373  return true;
374  }
375 
376  protected function doRenderSubMenu(array $item)
377  {
378  return (isset($item['items']) && count($item['items']));
379  }
380 
384  public function run()
385  {
386  $this->registerClientScripts();
387  $this->registerCssFile();
388  parent::run();
389  }
390  }
391 ?>
static ajaxLink($text, $url, $ajaxOptions=array(), $htmlOptions=array())
Definition: ZurmoHtml.php:328
cssParentItems($items)
Definition: MbMenu.php:119
createJsCode()
Definition: MbMenu.php:75
init()
Definition: MbMenu.php:142
registerClientScripts()
Definition: MbMenu.php:166
cssLastItems($items)
Definition: MbMenu.php:94
run()
Definition: MbMenu.php:384
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.