2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
40 require_once('include/ListView/ListViewSmarty.php');
48 protected $data = array();
53 protected $headerColumns = array();
73 private $recordsPerPage;
81 * Create a list view object that can display a data source which implements the Paginatable interface.
84 * @param Paginatable $dataSource
85 * @param array $params
86 * @param string $tableIdentifier
88 function __construct($dataSource, $params, $tableIdentifier = '')
92 $this->ss = new Sugar_Smarty();
93 $this->tableID = $tableIdentifier;
95 $this->dataSource = $dataSource;
96 $this->headerColumns = $this->dataSource->getHeaderColumns();
98 if( !isset($params['offset']) )
99 throw new Exception("Missing required parameter offset for ImportListView");
101 $this->dataSource->setCurrentOffset($params['offset']);
103 $this->recordsPerPage = isset($params['totalRecords']) ? $params['totalRecords'] : ($sugar_config['list_max_entries_per_page'] + 0);
104 $this->data = $this->dataSource->loadDataSet($this->recordsPerPage)->getDataSet();
105 $this->maxColumns = $this->getMaxColumnsForDataSet();
109 * Display the list view like table.
111 * @param bool $return True if we should return the content rather than echoing.
114 public function display($return = FALSE)
116 global $app_strings,$mod_strings;
118 $navStrings = array('next' => $app_strings['LNK_LIST_NEXT'],'previous' => $app_strings['LNK_LIST_PREVIOUS'],'end' => $app_strings['LNK_LIST_END'],
119 'start' => $app_strings['LNK_LIST_START'],'of' => $app_strings['LBL_LIST_OF']);
120 $this->ss->assign('navStrings', $navStrings);
121 $this->ss->assign('pageData', $this->generatePaginationData() );
122 $this->ss->assign('tableID', $this->tableID);
123 $this->ss->assign('colCount', count($this->headerColumns));
124 $this->ss->assign('APP',$app_strings);
125 $this->ss->assign('rowColor', array('oddListRow', 'evenListRow'));
126 $this->ss->assign('displayColumns',$this->headerColumns);
127 $this->ss->assign('data', $this->data);
128 $this->ss->assign('maxColumns', $this->maxColumns);
129 $this->ss->assign('MOD', $mod_strings);
130 $contents = $this->ss->fetch('modules/Import/tpls/listview.tpl');
138 * For the data set that was loaded, find the max count of entries per row.
142 protected function getMaxColumnsForDataSet()
145 foreach($this->data as $data)
147 if(count($data) > $maxColumns)
148 $maxColumns = count($data);
154 * Generate the pagination data.
158 protected function generatePaginationData()
160 $currentOffset = $this->dataSource->getCurrentOffset();
161 $totalRecordsCount = $this->dataSource->getTotalRecordCount();
162 $nextOffset = $currentOffset+ $this->recordsPerPage;
163 $nextOffset = $nextOffset > $totalRecordsCount ? 0 : $nextOffset;
164 $lastOffset = floor($totalRecordsCount / $this->recordsPerPage) * $this->recordsPerPage;
165 $previousOffset = $currentOffset - $this->recordsPerPage;
166 $offsets = array('totalCounted'=> true, 'total' => $totalRecordsCount, 'next' => $nextOffset,
167 'last' => $lastOffset, 'previous' => $previousOffset,
168 'current' => $currentOffset, 'lastOffsetOnPage' => count($this->data) + $this->dataSource->getCurrentOffset() );
170 $pageData = array('offsets' => $offsets);