]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/views/ImportListView.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Import / views / ImportListView.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
4 /*********************************************************************************
5  * SugarCRM Community Edition is a customer relationship management program developed by
6  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39
40 require_once('include/ListView/ListViewSmarty.php');
41
42
43 class ImportListView
44 {
45     /**
46      * @var array
47      */
48     protected $data = array();
49
50     /**
51      * @var array
52      */
53     protected $headerColumns = array();
54
55     /**
56      * @var Sugar_Smarty
57      */
58     private $ss;
59
60     /**
61      * @var string
62      */
63     private $tableID;
64
65     /**
66      * @var Paginatable
67      */
68     private $dataSource;
69
70     /**
71      * @var int
72      */
73     private $recordsPerPage;
74
75     /**
76      * @var int
77      */
78     private $maxColumns;
79
80     /**
81      * Create a list view object that can display a data source which implements the Paginatable interface.
82      *
83      * @throws Exception
84      * @param  Paginatable $dataSource
85      * @param  array $params
86      * @param string $tableIdentifier
87      */
88     function __construct($dataSource, $params, $tableIdentifier = '')
89     {
90         global $sugar_config;
91
92         $this->ss = new Sugar_Smarty();
93         $this->tableID = $tableIdentifier;
94
95         $this->dataSource = $dataSource;
96         $this->headerColumns = $this->dataSource->getHeaderColumns();
97
98         if( !isset($params['offset']) )
99             throw new Exception("Missing required parameter offset for ImportListView");
100         else
101             $this->dataSource->setCurrentOffset($params['offset']);
102
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();
106     }
107
108     /**
109      * Display the list view like table.
110      *
111      * @param bool $return True if we should return the content rather than echoing.
112      * @return
113      */
114     public function display($return = FALSE)
115     {
116         global $app_strings,$mod_strings;
117
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');
131         if($return)
132             return $contents;
133         else
134             echo $contents;
135     }
136
137     /**
138      * For the data set that was loaded, find the max count of entries per row.
139      *
140      * @return int
141      */
142     protected function getMaxColumnsForDataSet()
143     {
144         $maxColumns = 0;
145         foreach($this->data as $data)
146         {
147             if(count($data) > $maxColumns)
148                 $maxColumns = count($data);
149         }
150         return $maxColumns;
151     }
152
153     /**
154      * Generate the pagination data.
155      *
156      * @return array
157      */
158     protected function generatePaginationData()
159     {
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() );
169
170         $pageData = array('offsets' => $offsets);
171         return $pageData;
172
173     }
174
175
176
177 }