All Data Structures Functions Variables Pages
MixedModelsSearchResultsDataCollection.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 
42  {
43  private $term;
44  private $user;
45  private $views = array();
46 
53  public function __construct($term, $pageSize, User $user)
54  {
55  assert('is_string($term)');
56  assert('is_int($pageSize)');
57  $this->term = $term;
58  $this->pageSize = $pageSize;
59  $this->user = $user;
60  }
61 
68  public function getListView($moduleName, $forceEmptyResults = false)
69  {
70  assert('is_string($moduleName)');
71  $sourceData = GetUtil::getData();
72  $pageSize = $this->pageSize;
73  $module = Yii::app()->findModule($moduleName);
74  $searchFormClassName = $module::getGlobalSearchFormClassName();
75  $modelClassName = $module::getPrimaryModelName();
76  $model = new $modelClassName(false);
77  $searchForm = new $searchFormClassName($model);
78  $sanitizedSearchAttributes = MixedTermSearchUtil::
80  $metadataAdapter = new SearchDataProviderMetadataAdapter(
81  $searchForm,
82  $this->user->id,
83  $sanitizedSearchAttributes
84  );
85  $listViewClassName = $module::getPluralCamelCasedName() . 'ForMixedModelsSearchListView';
86  $sortAttribute = SearchUtil::resolveSortAttributeFromArray($modelClassName, $sourceData);
87  $sortDescending = SearchUtil::resolveSortDescendingFromArray($modelClassName, $sourceData);
88  if ($forceEmptyResults)
89  {
90  $dataProviderClass = 'EmptyRedBeanModelDataProvider';
91  $emptyText = '';
92  }
93  else
94  {
95  $dataProviderClass = 'RedBeanModelDataProvider';
96  $emptyText = null;
97  }
99  $metadataAdapter->getAdaptedMetadata(false),
100  $modelClassName,
101  $dataProviderClass,
102  $sortAttribute,
103  $sortDescending,
104  $pageSize,
105  $module->getStateMetadataAdapterClassName()
106  );
107  $listView = new $listViewClassName(
108  'default',
109  $module->getId(),
110  $modelClassName,
111  $dataProvider,
113  '-' . $moduleName,
114  array(
115  'route' => '',
116  'class' => 'SimpleListLinkPager',
117  'firstPageLabel' => '<span>first</span>',
118  'prevPageLabel' => '<span>previous</span>',
119  'nextPageLabel' => '<span>next</span>',
120  'lastPageLabel' => '<span>last</span>',
121  )
122  );
123  $listView->setRowsAreSelectable(false);
124  $listView->setEmptyText($emptyText);
125  return $listView;
126  }
127 
132  private function makeViews()
133  {
134  $globalSearchModuleNamesAndLabelsData = GlobalSearchUtil::
136  foreach ($globalSearchModuleNamesAndLabelsData as $moduleName => $label)
137  {
138  $titleView = new TitleBarView($label, null, 1);
139  $iconClassName = Yii::app()->findModule($moduleName)->getSingularCamelCasedName();
140  $titleView->setCssClasses(array($iconClassName));
141  $this->views['titleBar-' . $moduleName] = $titleView;
142  $this->views[$moduleName] = $this->getListView($moduleName, true);
143  }
144  }
145 
146  public function getViews()
147  {
148  $this->makeViews();
149  return $this->views;
150  }
151  }
152 ?>
static resolveSelectedIdsFromGet()
Definition: GetUtil.php:65
static getGlobalSearchAttributeByModuleAndPartialTerm(Module $module, $partialTerm)
Definition: User.php:37
static getGlobalSearchScopingModuleNamesAndLabelsDataByUser(User $user)
static resolveSortAttributeFromArray($getArrayPrefixName, $sourceData)
Definition: SearchUtil.php:173
static makeDataProvider(array $metadata, $listModelClassName, $dataProviderClassName, $sortAttribute, $sortDescending, $pageSize, $stateMetadataAdapterClassName=null)
static resolveSortDescendingFromArray($getArrayPrefixName, $sourceData)
Definition: SearchUtil.php:190
Generated on Fri May 29 2020 07:10:36