All Data Structures Functions Variables Pages
StickySearchUtil.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  {
49  public static function resolveFinalOffsetForStickyList($stickyOffset, $pageSize, $totalCount)
50  {
51  assert('is_int($stickyOffset)');
52  assert('is_int($pageSize)');
53  assert('is_int($totalCount)');
54  if ($stickyOffset == 0)
55  {
56  $finalOffset = 0;
57  }
58  elseif ($pageSize >= $totalCount)
59  {
60  $finalOffset = 0;
61  }
62  else
63  {
64  //lower boundry of half the page size from stickyOffset
65  $lowerBoundryOffset = $stickyOffset - round($pageSize / 2);
66  //upper boundry of half the page size from stickyOffset
67  $upperBoundryOffset = $stickyOffset + round($pageSize / 2);
68  if ($lowerBoundryOffset < 0)
69  {
70  $finalOffset = 0;
71  }
72  elseif ($upperBoundryOffset > ($totalCount -1))
73  {
74  $finalOffset = $lowerBoundryOffset - ($upperBoundryOffset - ($totalCount- 1));
75  }
76  else
77  {
78  $finalOffset = $lowerBoundryOffset;
79  }
80  }
81  return (int)$finalOffset;
82  }
83 
90  public static function resolveBreadCrumbViewForDetailsControllerAction(CController $controller, $stickySearchKey,
91  RedBeanModel $model)
92  {
93  assert('is_string($stickySearchKey)');
94  if (ArrayUtil::getArrayValue(GetUtil::getData(), 'stickyOffset') !== null &&
95  StickySearchUtil::getDataByKey($stickySearchKey) != null)
96  {
97  $stickyLoadUrl = Yii::app()->createUrl($controller->getModule()->getId() . '/' . $controller->getId() . '/renderStickyListBreadCrumbContent',
98  array('stickyKey' => $stickySearchKey,
99  'stickyOffset' => ArrayUtil::getArrayValue(GetUtil::getData(), 'stickyOffset'),
100  'stickyModelId' => $model->id));
101  }
102  else
103  {
104  $stickyLoadUrl = null;
105  }
106  $className = static::resolveStickyDetailsAndRelationsBreadCrumbViewClassName();
107  return new $className($controller->getId(), $controller->getModule()->getId(),
108  static::resolveBreadcrumbLinks($model),
109  static::getHomeLinkLabel($controller),
110  $stickyLoadUrl,
111  static::getHomeUrl());
112  }
113 
114  protected static function resolveStickyDetailsAndRelationsBreadCrumbViewClassName()
115  {
116  return 'StickyDetailsAndRelationsBreadCrumbView';
117  }
118 
119  protected static function resolveBreadcrumbLinks(RedBeanModel $model)
120  {
121  return array(strval($model));
122  }
123 
124  protected static function getHomeLinkLabel($controller)
125  {
126  return $controller->getModule()->getModuleLabelByTypeAndLanguage('Plural');
127  }
128 
129  protected static function getHomeUrl()
130  {
131  return null;
132  }
133  }
134 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static resolveFinalOffsetForStickyList($stickyOffset, $pageSize, $totalCount)
static resolveBreadCrumbViewForDetailsControllerAction(CController $controller, $stickySearchKey, RedBeanModel $model)
Generated on Thu May 28 2020 07:10:36