3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
39 require_once('modules/Import/sources/ImportDataSource.php');
42 class ExternalSourceEAPMAdapter extends ImportDataSource
46 * @var string The name of the EAPM object.
48 private $_eapmName = 'Google';
51 * @var int Total record count of rows that will be imported
53 private $_totalRecordCount = -1;
56 * @var The record set loaded from the external source
58 private $_recordSet = array();
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' => '');
71 public function __construct($eapmName)
73 global $current_user, $locale;
74 $this->_eapmName = $eapmName;
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');
83 $this->setSourceName();
86 * Return a feed of google contacts using the EAPM and Connectors farmework.
92 public function loadDataSet($maxResults = 0)
94 if ( !$eapmBean = EAPM::getLoginInfo($this->_eapmName,true) )
96 throw new Exception("Authentication error with {$this->_eapmName}");
99 $api = ExternalAPIFactory::loadAPI($this->_eapmName);
100 $api->loadEAPM($eapmBean);
101 $conn = $api->getConnector();
103 $feed = $conn->getList(array('maxResults' => $maxResults, 'startIndex' => $this->_offset));
106 $this->_totalRecordCount = $feed['totalResults'];
107 $this->_recordSet = $feed['records'];
111 throw new Exception("Unable to retrieve {$this->_eapmName} feed.");
115 public function getHeaderColumns()
120 public function getTotalRecordCount()
122 return $this->_totalRecordCount;
125 public function setSourceName($sourceName = '')
127 $this->_sourcename = $this->_eapmName;
130 //Begin Implementation for SPL's Iterator interface
131 public function current()
133 $this->_currentRow = current($this->_recordSet);
134 return $this->_currentRow;
137 public function key()
139 return key($this->_recordSet);
142 public function rewind()
144 reset($this->_recordSet);
147 public function next()
150 next($this->_recordSet);
153 public function valid()
155 return (current($this->_recordSet) !== FALSE);