All Data Structures Functions Variables Pages
MenuView.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  class MenuView extends View
38  {
39  protected $items;
40 
41  protected $useMinimalDynamicLabelMbMenu;
42 
43  protected $cssClasses;
44 
45  protected $showCount;
46 
47  public function __construct(array $items, $useMinimalDynamicLabelMbMenu = false, $showCount = 6, $cssClasses = array())
48  {
49  assert('is_int($showCount)');
50  assert('is_array($cssClasses)');
51  $this->items = $items;
52  $this->useMinimalDynamicLabelMbMenu = $useMinimalDynamicLabelMbMenu;
53  $this->showCount = $showCount;
54  $this->cssClasses = array_merge($cssClasses, $this->resolveMenuClassForNoHiddenItems());
55  }
56 
62  protected function renderContent()
63  {
64  if (count($this->items) == 0)
65  {
66  return null;
67  }
68  if ($this->useMinimalDynamicLabelMbMenu)
69  {
70  $widgetName = 'MinimalDynamicLabelMbMenu';
71  }
72  else
73  {
74  $widgetName = 'MbMenu';
75  }
76  $widgetPath = 'application.core.widgets.' . $widgetName;
77  $cClipWidget = new CClipWidget();
78  $cClipWidget->beginClip("Tabs");
79  $cClipWidget->widget($widgetPath, array(
80  'items' => static::resolveForHiddenItems($this->items, $this->showCount),
81  'labelPrefix' => 'i'
82  ));
83  $cClipWidget->endClip();
84  $content = $cClipWidget->getController()->clips['Tabs'];
85  $content .= $this->resolveToggleForHiddenItems();
86  return $content;
87  }
88 
89  protected function resolveForHiddenItems($items, $showCount)
90  {
91  assert('is_array($items)');
92  assert('is_int($showCount)');
93  $count = 1;
94  foreach ($this->items as $key => $item)
95  {
96  if (isset($item['moduleId']))
97  {
98  $items[$key]['itemOptions']['class'] = 'type-' . $item['moduleId'];
99  if ($count > $showCount && !ArrayUtil::getArrayValue($item, 'active'))
100  {
101  $items[$key]['itemOptions']['class'] = 'hidden-nav-item type-' . $item['moduleId'];
102  }
103  $count++;
104  }
105  }
106  return $items;
107  }
108 
109  protected function resolveToggleForHiddenItems()
110  {
111  if (count($this->items) > $this->showCount)
112  {
113  return ZurmoHtml::tag('a', array('class' => 'toggle-hidden-nav-items'), '');
114  }
115  }
116 
117  protected function resolveMenuClassForNoHiddenItems()
118  {
119  if ((count($this->items) < $this->showCount) || static::areAllItemsVisible($this->items, $this->showCount))
120  {
121  return array('hasNoHiddenItems');
122  }
123  else
124  {
125  return array();
126  }
127  }
128 
129  protected static function areAllItemsVisible($items, $showCount)
130  {
131  $count = 1;
132  foreach ($items as $item)
133  {
134  if ($count > $showCount && !ArrayUtil::getArrayValue($item, 'active'))
135  {
136  return false;
137  }
138  $count++;
139  }
140  return true;
141  }
142  }
143 ?>
renderContent()
Definition: MenuView.php:62
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
Definition: View.php:43
Generated on Tue Jun 2 2020 07:10:36