All Data Structures Functions Variables Pages
ZurmoDefaultViewUtil.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  {
42  protected static $showRecentlyViewed = true;
43 
49  protected static $activeModuleId;
50 
61  public static function makeViewWithBreadcrumbsForCurrentUser(CController $controller,
62  View $containedView,
63  $breadCrumbLinks,
64  $breadcrumbViewClassName,
65  $cssClasses = array())
66  {
67  assert('is_array($breadCrumbLinks)');
68  $gridView = new GridView(2, 1);
69  $gridView->setCssClasses($cssClasses);
70  $gridView->setView(new $breadcrumbViewClassName($controller->getId(),
71  $controller->getModule()->getId(),
72  $breadCrumbLinks), 0, 0);
73  $gridView->setView($containedView, 1, 0);
74  return static::makeStandardViewForCurrentUser($controller, $gridView);
75  }
76 
99  public static function makeTwoViewsWithBreadcrumbsForCurrentUser(CController $controller,
100  View $containedView,
101  View $secondContainedView,
102  $breadCrumbLinks,
103  $breadcrumbViewClassName,
104  $cssClasses = array())
105  {
106  assert('is_array($breadCrumbLinks)');
107  $gridView = new GridView(3, 1);
108  $gridView->setCssClasses($cssClasses);
109  $gridView->setView(new $breadcrumbViewClassName($controller->getId(),
110  $controller->getModule()->getId(),
111  $breadCrumbLinks), 0, 0);
112  $gridView->setView($containedView, 1, 0);
113  $gridView->setView($secondContainedView, 2, 0);
114  return static::makeStandardViewForCurrentUser($controller, $gridView);
115  }
116 
117  public static function makeTwoStandardViewsForCurrentUser(CController $controller,
118  View $containedView,
119  View $secondContainedView,
120  $cssClasses = array())
121  {
122  $gridView = new GridView(2, 1);
123  $gridView->setCssClasses($cssClasses);
124  $gridView->setView($containedView, 0, 0);
125  $gridView->setView($secondContainedView, 1, 0);
126  return static::makeStandardViewForCurrentUser($controller, $gridView);
127  }
128 
136  public static function makeStandardViewForCurrentUser(CController $controller, View $containedView)
137  {
138  if (static::$showRecentlyViewed)
139  {
140  $verticalColumns = 3;
141  }
142  else
143  {
144  $verticalColumns = 2;
145  }
146  $aVerticalGridView = new GridView($verticalColumns, 1, 'nav', false);
147  $aVerticalGridView->setCssClasses( array('AppNavigation')); //navigation left column
148  $aVerticalGridView->setView(static::makeMenuView($controller), 0, 0);
149  if (static::$showRecentlyViewed)
150  {
151  $aVerticalGridView->setView(static::makeRecentlyViewedView(), 1, 0);
152  }
153  $aVerticalGridView->setView(new UserInterfaceChooserView(), ($verticalColumns - 1), 0);
154 
155  $horizontalGridView = new GridView(1, 3, 'section', false);
156  $horizontalGridView->setCssClasses(array('AppContainer', 'container', 'clearfix')); //teh conatiner for the floated items
157  $horizontalGridView->setView($aVerticalGridView, 0, 0);
158 
159  $containedView->setCssClasses(array_merge($containedView->getCssClasses(), array('AppContent'))); //the app itself to the right
160 
161  $horizontalGridView->setView($containedView, 0, 1);
162  $horizontalGridView->setView(static::makeFlashMessageView($controller), 0, 2); //TODO needs to move into $containedView
163 
164  $verticalGridView = new GridView(6, 1, null);
165  $verticalGridView->setView(static::makeHeaderView($controller), 0, 0);
166  $verticalGridView->setView($horizontalGridView, 1, 0);
167  $verticalGridView->setView(static::makeModalContainerView(), 2, 0);
168  $verticalGridView->setView(static::makeModalGameNotificationContainerView(), 3, 0);
169  $verticalGridView->setView(static::makeGameCoinContainerView($controller), 4, 0);
170  $verticalGridView->setView(static::makeFooterView(), 5, 0);
171 
172  return $verticalGridView;
173  }
174 
181  public static function makeAuthorizationViewForCurrentUser(CController $controller, View $containedView)
182  {
183  $horizontalGridView = new GridView(1, 1, 'section', false);
184  $horizontalGridView->setCssClasses(array('AppContainer', 'container', 'clearfix'));
185  $containedView->setCssClasses(array_merge($containedView->getCssClasses(), array('AppContent')));
186  $horizontalGridView->setView($containedView, 0, 0);
187 
188  $verticalGridView = new GridView(3, 1, null);
189  $verticalGridView->setView(static::makeHeaderView($controller), 0, 0);
190  $verticalGridView->setView($horizontalGridView, 1, 0);
191  $verticalGridView->setView(static::makeFooterView(), 2, 0);
192  return $verticalGridView;
193  }
194 
200  public static function makeErrorViewForCurrentUser(CController $controller, View $containedView)
201  {
202  $aVerticalGridView = new GridView(1, 1, 'nav', false);
203  $aVerticalGridView->setCssClasses( array('AppNavigation')); //navigation left column
204  $aVerticalGridView->setView(static::makeMenuView($controller), 0, 0);
205 
206  $horizontalGridView = new GridView(2, 1, 'section', false);
207  $horizontalGridView->setCssClasses(array('AppContainer', 'container', 'clearfix')); //teh conatiner for the floated items
208  $horizontalGridView->setView($aVerticalGridView, 0, 0);
209  $containedView->setCssClasses(array_merge($containedView->getCssClasses(), array('AppContent', 'ErrorView'))); //the app itself to the right
210  $horizontalGridView->setView($containedView, 1, 0);
211 
212  $verticalGridView = new GridView(3, 1, null);
213  $verticalGridView->setView(static::makeHeaderView($controller), 0, 0);
214  $verticalGridView->setView($horizontalGridView, 1, 0);
215  $verticalGridView->setView(static::makeFooterView(), 2, 0);
216  return $verticalGridView;
217  }
218 
219  protected static function makeHeaderView(CController $controller)
220  {
221  $headerView = null;
222  $settingsMenuItems = MenuUtil::getOrderedAccessibleHeaderMenuForCurrentUser();
223  $settingsMenuItems = static::resolveHeaderMenuItemsForMobile($settingsMenuItems);
224  $userMenuItems = static::getAndResolveUserMenuItemsForHeader();
225  $applicationName = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'applicationName');
226  $shortcutsCreateMenuItems = MenuUtil::getAccessibleShortcutsCreateMenuByCurrentUser();
227  $moduleNamesAndLabels = GlobalSearchUtil::
228  getGlobalSearchScopingModuleNamesAndLabelsDataByUser(Yii::app()->user->userModel);
229  $sourceUrl = Yii::app()->createUrl('zurmo/default/globalSearchAutoComplete');
231  $headerView = new HeaderView( $settingsMenuItems,
232  $userMenuItems,
233  $shortcutsCreateMenuItems,
234  $moduleNamesAndLabels,
235  $sourceUrl,
236  $applicationName);
237  $headerView->setCssClasses(array('HeaderView'));
238  return $headerView;
239  }
240 
241  protected static function resolveHeaderMenuItemsForMobile(Array $items)
242  {
243  if (Yii::app()->userInterface->isMobile())
244  {
245  $resolvedItems = array();
246  foreach ($items as $item)
247  {
248  if (!isset($item['mobile']) || $item['mobile'] == true)
249  {
250  $resolvedItems[] = $item;
251  }
252  }
253  }
254  else
255  {
256  $resolvedItems = $items;
257  }
258  return $resolvedItems;
259  }
260 
261  protected static function getAndResolveUserMenuItemsForHeader()
262  {
264  return $userMenuItems;
265  }
266 
267  protected static function makeMenuView($controller = null)
268  {
269  assert('$controller == null || $controller instanceof CController');
270  $items = MenuUtil::resolveByCacheAndGetVisibleAndOrderedTabMenuByCurrentUser();
271  $useMinimalDynamicLabelMbMenu = false;
272  static::resolveForMobileInterface($items, $useMinimalDynamicLabelMbMenu, $controller);
273  static::resolveForActiveMenuItem($items, $controller);
274  return new MenuView($items, $useMinimalDynamicLabelMbMenu);
275  }
276 
277  protected static function resolveForActiveMenuItem(&$items, $controller)
278  {
279  assert('$controller == null || $controller instanceof CController');
280  assert('is_array($items)');
281  foreach ($items as $key => $item)
282  {
283  if ($controller != null && isset($item['moduleId']) &&
284  static::resolveActiveModuleId($controller) == $item['moduleId'])
285  {
286  $items[$key]['active'] = true;
287  if (isset($items[$key]['items']))
288  {
289  try
290  {
291  $url = Yii::app()->urlManager->parseUrl(Yii::app()->request);
292  foreach ($items[$key]['items'] as $subItemKey => $subItem)
293  {
294  $subItemUrl = $subItem['url'];
295  if (stristr($subItemUrl[0], $url) == $url)
296  {
297  if (isset($_GET['moduleClassName']) && isset($subItemUrl['moduleClassName']) && $_GET['moduleClassName'] == $subItemUrl['moduleClassName'])
298  {
299  $items[$key]['items'][$subItemKey]['active'] = true;
300  }
301  elseif (isset($_GET['moduleClassName']) && isset($subItemUrl['moduleClassName']) && $_GET['moduleClassName'] != $subItemUrl['moduleClassName'])
302  {
303  $items[$key]['items'][$subItemKey]['active'] = false;
304  }
305  else
306  {
307  $items[$key]['items'][$subItemKey]['active'] = true;
308  }
309  }
310  }
311  }
312  catch (Exception $exception)
313  {
314  //Do nothing
315  }
316  }
317  }
318  }
319  }
320 
321  protected static function resolveActiveModuleId($controller)
322  {
323  if (static::$activeModuleId != null)
324  {
325  return static::$activeModuleId;
326  }
327  return $controller->resolveAndGetModuleId();
328  }
329 
330  protected static function makeRecentlyViewedView()
331  {
332  $items = AuditEventsRecentlyViewedUtil::getRecentlyViewedItemsByUser(Yii::app()->user->userModel, 10);
333  return new RecentlyViewedView($items);
334  }
335 
336  protected static function makeFlashMessageView(CController $controller)
337  {
338  return new FlashMessageView($controller);
339  }
340 
341  protected static function makeModalContainerView()
342  {
343  return new ModalContainerView();
344  }
345 
346  protected static function makeModalGameNotificationContainerView()
347  {
348  return new ModalGameNotificationContainerView(GameNotification::getAllByUser(Yii::app()->user->userModel));
349  }
350 
351  protected static function makeGameCoinContainerView(CController $controller)
352  {
353  return new GameCoinContainerView($controller);
354  }
355 
356  protected static function makeFooterView()
357  {
358  return new FooterView();
359  }
360 
361  protected static function resolveForMobileInterface(& $items, & $useMinimalDynamicLabelMbMenu, $controller = null)
362  {
363  if (Yii::app()->userInterface->isMobile())
364  {
365  foreach ($items as $key => $item)
366  {
367  if (isset($item['mobile']) && $item['mobile'] == false)
368  {
369  unset($items[$key]);
370  }
371  }
372  }
373  else
374  {
375  return;
376  }
377  }
378 
379  protected static function resolveShortcutsCreateMenuItemsForMobile(& $shortcutsCreateMenuItems)
380  {
381  if (!empty($shortcutsCreateMenuItems['items']))
382  {
383  foreach ($shortcutsCreateMenuItems['items'] as $key => $item)
384  {
385  if (isset($item['mobile']) && $item['mobile'] == false)
386  {
387  unset($shortcutsCreateMenuItems['items'][$key]);
388  }
389  }
390  }
391  }
392 
397  public static function setLockKeyForDetailsAndRelationsView($key, $value)
398  {
399  assert('is_bool($value)');
400  Yii::app()->user->setState($key, $value);
401  }
402 
407  public static function getLockKeyForDetailsAndRelationsView($key)
408  {
409  return Yii::app()->user->getState($key);
410  }
411 
420  public static function renderActionBarLinksForKanbanBoard($controllerId, $moduleId, $modelId, $kanbanIsActive)
421  {
422  assert('is_string($controllerId)');
423  assert('is_string($moduleId)');
424  assert('is_int($modelId)');
425  assert('is_bool($kanbanIsActive)');
426  if ($kanbanIsActive)
427  {
428  $active = DetailsAndRelationsViewTypesToggleLinkActionElement::TYPE_KANBAN_BOARD;
429  }
430  else
431  {
432  $active = DetailsAndRelationsViewTypesToggleLinkActionElement::TYPE_NON_KANBAN_BOARD;
433  }
434  $toggleLinkActionElement = new DetailsAndRelationsViewTypesToggleLinkActionElement(
435  $controllerId, $moduleId, $modelId, array('active' => $active));
436  return $toggleLinkActionElement->render();
437  }
438  }
439 ?>
static setLockKeyForDetailsAndRelationsView($key, $value)
static makeTwoViewsWithBreadcrumbsForCurrentUser(CController $controller, View $containedView, View $secondContainedView, $breadCrumbLinks, $breadcrumbViewClassName, $cssClasses=array())
static makeAuthorizationViewForCurrentUser(CController $controller, View $containedView)
static makeViewWithBreadcrumbsForCurrentUser(CController $controller, View $containedView, $breadCrumbLinks, $breadcrumbViewClassName, $cssClasses=array())
Definition: View.php:43
static getGlobalSearchScopingModuleNamesAndLabelsDataByUser(User $user)
static getRecentlyViewedItemsByUser(User $user, $count)
static makeErrorViewForCurrentUser(CController $controller, View $containedView)
static getAccessibleOrderedUserHeaderMenuForCurrentUser()
Definition: MenuUtil.php:433
static getByModuleName($moduleName, $key, $cache=true)
static getLockKeyForDetailsAndRelationsView($key)
static renderActionBarLinksForKanbanBoard($controllerId, $moduleId, $modelId, $kanbanIsActive)
static getAllByUser(User $user)
static resolveModuleNamesAndLabelsDataWithAllOption(&$moduleNamesAndLabels)
static makeStandardViewForCurrentUser(CController $controller, View $containedView)
static getAccessibleShortcutsCreateMenuByCurrentUser()
Definition: MenuUtil.php:269
Generated on Sat Mar 28 2020 07:10:46