]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/sources/ExternalSourceEAPMAdapter.php
Release 6.3.0
[Github/sugarcrm.git] / modules / Import / sources / ExternalSourceEAPMAdapter.php
1 <?php
2
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 require_once('modules/Import/sources/ImportDataSource.php');
40
41
42 class ExternalSourceEAPMAdapter extends ImportDataSource
43 {
44
45     /**
46      * @var string The name of the EAPM object.
47      */
48     private $_eapmName = 'Google';
49
50     /**
51      * @var int Total record count of rows that will be imported
52      */
53     private $_totalRecordCount = -1;
54
55     /**
56      * @var The record set loaded from the external source
57      */
58     private $_recordSet = array();
59
60     protected $_localeSettings = array('importlocale_charset' => 'UTF-8',
61                                        'importlocale_dateformat' => 'Y-m-d',
62                                        'importlocale_timeformat' => 'H:i',
63                                        'importlocale_timezone' => '',
64                                        'importlocale_currency' => '',
65                                        'importlocale_default_currency_significant_digits' => '',
66                                        'importlocale_num_grp_sep' => '',
67                                        'importlocale_dec_sep' => '',
68                                        'importlocale_default_locale_name_format' => '');
69
70
71     public function __construct()
72     {
73         global $current_user, $locale;
74
75         $this->_localeSettings['importlocale_num_grp_sep'] = $current_user->getPreference('num_grp_sep');
76         $this->_localeSettings['importlocale_dec_sep'] = $current_user->getPreference('dec_sep');
77         $this->_localeSettings['importlocale_default_currency_significant_digits'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
78         $this->_localeSettings['importlocale_default_locale_name_format'] = $locale->getLocaleFormatMacro($current_user);
79         $this->_localeSettings['importlocale_currency'] = $locale->getPrecedentPreference('currency', $current_user);
80         $this->_localeSettings['importlocale_timezone'] = $current_user->getPreference('timezone');
81
82         $this->setSourceName();
83     }
84     /**
85      * Return a feed of google contacts using the EAPM and Connectors farmework.
86      *
87      * @throws Exception
88      * @param  $maxResults
89      * @return array
90      */
91     public function loadDataSet($maxResults = 0)
92     {
93          if ( !$eapmBean = EAPM::getLoginInfo($this->_eapmName,true) )
94          {
95             throw new Exception('Authentication error with Google Contacts EAPM.');
96          }
97
98         $api = ExternalAPIFactory::loadAPI($this->_eapmName);
99         $api->loadEAPM($eapmBean);
100         $conn = $api->getConnector();
101
102         $feed = $conn->getList(array('maxResults' => $maxResults, 'startIndex' => $this->_offset));
103         if($feed !== FALSE)
104         {
105             $this->_totalRecordCount = $feed['totalResults'];
106             $this->_recordSet = $feed['records'];
107         }
108         else
109         {
110             throw new Exception("Unable to retrieve {$this->_eapmName} feed.");
111         }
112     }
113
114     public function getHeaderColumns()
115     {
116         return '';
117     }
118     
119     public function getTotalRecordCount()
120     {
121         return $this->_totalRecordCount;
122     }
123
124     public function setSourceName($sourceName = '')
125     {
126         $this->_sourcename = $this->_eapmName;
127     }
128
129     //Begin Implementation for SPL's Iterator interface
130     public function current()
131     {
132         $this->_currentRow =  current($this->_recordSet);
133         return $this->_currentRow;
134     }
135
136     public function key()
137     {
138         return key($this->_recordSet);
139     }
140     
141     public function rewind()
142     {
143         reset($this->_recordSet);
144     }
145
146     public function next()
147     {
148         $this->_rowsCount++;
149         next($this->_recordSet);
150     }
151
152     public function valid()
153     {
154         return (current($this->_recordSet) !== FALSE);
155     }
156 }
157