]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Import/sources/ExternalSourceEAPMAdapter.php
Release 6.4.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($eapmName)
72     {
73         global $current_user, $locale;
74         $this->_eapmName = $eapmName;
75       
76         $this->_localeSettings['importlocale_num_grp_sep'] = $current_user->getPreference('num_grp_sep');
77         $this->_localeSettings['importlocale_dec_sep'] = $current_user->getPreference('dec_sep');
78         $this->_localeSettings['importlocale_default_currency_significant_digits'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user);
79         $this->_localeSettings['importlocale_default_locale_name_format'] = $locale->getLocaleFormatMacro($current_user);
80         $this->_localeSettings['importlocale_currency'] = $locale->getPrecedentPreference('currency', $current_user);
81         $this->_localeSettings['importlocale_timezone'] = $current_user->getPreference('timezone');
82
83         $this->setSourceName();
84     }
85     /**
86      * Return a feed of google contacts using the EAPM and Connectors farmework.
87      *
88      * @throws Exception
89      * @param  $maxResults
90      * @return array
91      */
92     public function loadDataSet($maxResults = 0)
93     {
94          if ( !$eapmBean = EAPM::getLoginInfo($this->_eapmName,true) )
95          {
96             throw new Exception("Authentication error with {$this->_eapmName}");
97          }
98
99         $api = ExternalAPIFactory::loadAPI($this->_eapmName);
100         $api->loadEAPM($eapmBean);
101         $conn = $api->getConnector();
102
103         $feed = $conn->getList(array('maxResults' => $maxResults, 'startIndex' => $this->_offset));
104         if($feed !== FALSE)
105         {
106             $this->_totalRecordCount = $feed['totalResults'];
107             $this->_recordSet = $feed['records'];
108         }
109         else
110         {
111             throw new Exception("Unable to retrieve {$this->_eapmName} feed.");
112         }
113     }
114
115     public function getHeaderColumns()
116     {
117         return '';
118     }
119     
120     public function getTotalRecordCount()
121     {
122         return $this->_totalRecordCount;
123     }
124
125     public function setSourceName($sourceName = '')
126     {
127         $this->_sourcename = $this->_eapmName;
128     }
129
130     //Begin Implementation for SPL's Iterator interface
131     public function current()
132     {
133         $this->_currentRow =  current($this->_recordSet);
134         return $this->_currentRow;
135     }
136
137     public function key()
138     {
139         return key($this->_recordSet);
140     }
141     
142     public function rewind()
143     {
144         reset($this->_recordSet);
145     }
146
147     public function next()
148     {
149         $this->_rowsCount++;
150         next($this->_recordSet);
151     }
152
153     public function valid()
154     {
155         return (current($this->_recordSet) !== FALSE);
156     }
157 }
158