public static function getInstance($source_name, $filter_name = '') { require_once 'include/connectors/filters/default/filter.php'; $key = $source_name . $filter_name; if (empty(self::$filter_map[$key])) { if (empty($filter_name)) { $filter_name = $source_name; } //split the wrapper name to find the path to the file. $dir = str_replace('_', '/', $filter_name); $parts = explode("/", $dir); $file = $parts[count($parts) - 1]; //check if this override wrapper file exists. require_once 'include/connectors/ConnectorFactory.php'; if (file_exists("modules/Connectors/connectors/filters/{$dir}/{$file}.php") || file_exists("custom/modules/Connectors/connectors/filters/{$dir}/{$file}.php")) { ConnectorFactory::load($filter_name, 'filters'); try { $filter_name .= '_filter'; } catch (Exception $ex) { return null; } } else { //if there is no override wrapper, use the default. $filter_name = 'default_filter'; } $component = ConnectorFactory::getInstance($source_name); $filter = new $filter_name(); $filter->setComponent($component); self::$filter_map[$key] = $filter; } //if return self::$filter_map[$key]; }
/** * getInstance * This method returns a formatter instance for the given source name and * formatter name. If no formatter name is specified, the default formatter * for the source is used. * * @param $source_name The data source name to retreive formatter for * @param $formatter_name Optional formatter name to use * @param $wrapper_name Optional wrapper name to use * @return $instance The formatter instance */ public static function getInstance($source_name, $formatter_name = '') { require_once 'include/connectors/formatters/default/formatter.php'; $key = $source_name . $formatter_name; if (empty(self::$formatter_map[$key])) { if (empty($formatter_name)) { $formatter_name = $source_name; } $dir = str_replace('_', '/', $formatter_name); $parts = explode("/", $dir); $file = array_pop($parts); if (ConnectorFactory::load($formatter_name, 'formatters')) { $formatter_name .= '_formatter'; } else { //if there is no override wrapper, use the default. $formatter_name = 'default_formatter'; } $component = ConnectorFactory::getInstance($source_name); $formatter = new $formatter_name(); $formatter->setComponent($component); $tpl = SugarAutoLoader::existingCustomOne("modules/Connectors/connectors/formatters/{$dir}/tpls/{$file}.tpl"); if (!empty($tpl)) { $formatter->setTplFileName($tpl); } self::$formatter_map[$key] = $formatter; } //if return self::$formatter_map[$key]; }
function display() { $source_id = $_REQUEST['source_id']; if (empty($source_id)) { $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_EMPTY_SOURCE_ID']); echo $GLOBALS['mod_strings']['ERROR_EMPTY_SOURCE']; return; } $record_id = $_REQUEST['record']; if (empty($record_id)) { $GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_EMPTY_RECORD_ID']); echo $GLOBALS['mod_strings']['ERROR_EMPTY_RECORD_ID']; return; } $merge_module = $_SESSION['merge_module']; if (empty($_SESSION['searchDefs'][$merge_module][$record_id][$source_id])) { $GLOBALS['log']->error("ERROR_NO_SEARCHDEFS_MAPPING"); echo $GLOBALS['mod_strings']['ERROR_NO_SEARCHDEFS_MAPPING']; return; } $args = $_SESSION['searchDefs'][$merge_module][$record_id][$source_id]; $source_instance = ConnectorFactory::getInstance($source_id); try { $beans = $source_instance->fillBeans($args, $merge_module); } catch (Exception $ex) { echo $ex->getMessage(); return; } if (empty($beans)) { echo '<br>' . $GLOBALS['mod_strings']['LBL_EMPTY_BEANS']; return; } $json = getJSONobj(); $json_data = array(); foreach ($beans as $id => $record) { $json_data[$id] = $json->encode($record->get_list_view_array()); } $this->ss->assign('source_id', $source_id); $this->ss->assign('json_data', $json_data); $this->ss->assign('DATA', $beans); //Setup listview to display $lv = new ListViewSmarty(); if (is_array($beans)) { $displayColumns = $this->getDisplayColumns($source_instance, $beans); $this->ss->assign('displayColumns', $displayColumns); global $odd_bg, $even_bg, $hilite_bg, $click_bg; $this->ss->assign('bgHilite', $hilite_bg); $this->ss->assign('rowColor', array('oddListRow', 'evenListRow')); $this->ss->assign('bgColor', array($odd_bg, $even_bg)); $this->ss->assign('module', $merge_module); echo $this->ss->fetch($this->getCustomFilePathIfExists('modules/Connectors/tpls/listview.tpl')); } }
/** * Given a source param, load the correct source and return the object * * @param string $class string representing the source to load * @param bool $call_init * * @return source|null */ public static function getSource($class, $call_init = true) { $dir = str_replace('_', '/', $class); $parts = explode("/", $dir); $file = $parts[count($parts) - 1]; $pos = strrpos($file, '/'); require_once DOCROOT . 'include/connectors/sources/default/source.php'; require_once DOCROOT . 'include/connectors/ConnectorFactory.php'; ConnectorFactory::load($class, 'sources'); try { $instance = new $class(); if ($call_init) { $instance->init(); } return $instance; } catch (Exception $ex) { } return null; }
public static function getInstance($source_name, $filter_name = '') { require_once 'include/connectors/filters/default/filter.php'; $key = $source_name . $filter_name; if (empty(self::$filter_map[$key])) { if (empty($filter_name)) { $filter_name = $source_name; } if (ConnectorFactory::load($filter_name, 'filters')) { $filter_name .= '_filter'; } else { //if there is no override wrapper, use the default. $filter_name = 'default_filter'; } $component = ConnectorFactory::getInstance($source_name); $filter = new $filter_name(); $filter->setComponent($component); self::$filter_map[$key] = $filter; } //if return self::$filter_map[$key]; }
/** * gets connectors meta * @return array */ public function buildConnectorsMeta() { require_once 'include/connectors/sources/SourceFactory.php'; require_once 'include/connectors/utils/ConnectorUtils.php'; $allConnectors = $this->getConnectorList(); $connectors = array(); // get general connector info foreach ($allConnectors as $name => $connector) { $instance = ConnectorFactory::getInstance($connector['id']); $connectorInfo = array('testing_enabled' => false, 'test_passed' => false, 'eapm_bean' => false, 'field_mapping' => array(), 'id' => $connector['id']); if (!empty($connector['name'])) { $connectorInfo['name'] = $connector['name']; } $source = $this->getSourceForConnector($connector); if (isset($source)) { if ($source->hasTestingEnabled()) { $connectorInfo['testing_enabled'] = true; try { $testpassed = $source->test(); } catch (exception $e) { $GLOBALS['log']->error($name . ' testing enabled but test throwing php errors'); } if (isset($testpassed)) { $connectorInfo['test_passed'] = $testpassed; } } } if (method_exists($instance, 'getMapping')) { $connectorInfo['field_mapping'] = $instance->getMapping(); } $connectors[$name] = $connectorInfo; } $connectorsHash = $this->hash($connectors); $connectors['_hash'] = $connectorsHash; $this->putConnectorCache($connectors); return $connectors; }
function action_DefaultSoapPopup() { $this->view = 'ajax'; $source_id = $_REQUEST['source_id']; $module = $_REQUEST['module_id']; $id = $_REQUEST['record_id']; $mapping = $_REQUEST['mapping']; $mapping = explode(',', $mapping); //Error checking //Load bean $bean = loadBean($module); $bean->retrieve($id); require_once 'include/connectors/ConnectorFactory.php'; $component = ConnectorFactory::getInstance($source_id); //Create arguments $args = array(); $field_defs = $bean->getFieldDefinitions(); foreach ($field_defs as $id => $field) { if (!empty($bean->{$id})) { $args[$id] = $bean->{$id}; } } $beans = $component->fillBeans($args, $module); if (!empty($beans) && !empty($mapping)) { $results = array(); $count = 0; foreach ($beans as $bean) { foreach ($mapping as $field) { $results[$count][$field] = $bean->{$field}; } $count++; } $json = getJSONobj(); echo $json->encode($results); } else { $GLOBALS['log']->error($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']); echo ''; } }
/** * getSources * Returns an Array of source entries found under the given directory * @param String $directory The directory to search * @return mixed $sources An Array of source entries */ private static function getSources($directory = 'modules/Connectors/connectors/sources') { if (file_exists($directory)) { $files = array(); $files = findAllFiles($directory, $files, false, 'config\\.php'); $start = strrpos($directory, '/') == strlen($directory) - 1 ? strlen($directory) : strlen($directory) + 1; $sources = array(); $sources_ordering = array(); foreach ($files as $file) { require $file; $end = strrpos($file, '/') - $start; $source = array(); $source['id'] = str_replace('/', '_', substr($file, $start, $end)); $source['name'] = !empty($config['name']) ? $config['name'] : $source['id']; $source['enabled'] = true; $source['directory'] = $directory . '/' . str_replace('_', '/', $source['id']); $order = isset($config['order']) ? $config['order'] : 99; //default to end using 99 if no order set $instance = ConnectorFactory::getInstance($source['id']); $source['eapm'] = empty($config['eapm']) ? false : $config['eapm']; $mapping = $instance->getMapping(); $modules = array(); if (!empty($mapping['beans'])) { foreach ($mapping['beans'] as $module => $mapping_entry) { $modules[] = $module; } } $source['modules'] = $modules; $sources_ordering[$source['id']] = array('order' => $order, 'source' => $source); } usort($sources_ordering, 'sources_sort_function'); foreach ($sources_ordering as $entry) { $sources[$entry['source']['id']] = $entry['source']; } return $sources; } return array(); }
/** * @see SugarView::display() */ public function display() { if (!empty($_REQUEST['record'])) { $module = $_SESSION['merge_module']; $field_count = 1; $diff_field_count = 0; require_once 'include/connectors/utils/ConnectorUtils.php'; $sources = ConnectorUtils::getModuleConnectors($module); $source_names = array(); $source_names['module']['name'] = $this->_leadQual->merge_bean->name; $result_beans = array(); require_once 'include/connectors/ConnectorFactory.php'; $index = 1; $viewdef_sources = array(); foreach ($sources as $source_id => $source_info) { if (!empty($_REQUEST[$source_id . '_id'])) { $viewdef_sources[$source_id] = true; $source_instance = ConnectorFactory::getInstance($source_id); try { $bean = $source_instance->fillBean(array('id' => $_REQUEST[$source_id . '_id']), $module); } catch (Exception $ex) { echo $ex->getMessage(); continue; } $result_beans[$index] = $bean; $source_names[$index]['name'] = $source_info['name']; $source_names[$index]['color'] = $this->_getRandomColor($index); $source_names[$index]['id'] = $index; $index++; if (!empty($bean->parent_duns) && (!empty($bean->duns) && $bean->parent_duns != $bean->duns)) { //go get the parent as well. $parent_bean = $source_instance->fillBean(array('id' => $bean->parent_duns), $module); $result_beans[$index] = $parent_bean; $source_names[$index]['name'] = $source_info['name']; $source_names[$index]['color'] = $this->_getRandomColor($index); $source_names[$index]['id'] = $index; $index++; } } } $viewdefs = ConnectorUtils::getViewDefs($viewdef_sources); if (empty($viewdefs['Connector']['MergeView'][$module])) { return; } $merge_fields = array(); $focusBean = BeanFactory::getBean($module); foreach ($viewdefs['Connector']['MergeView'][$module] as $field) { if ($focusBean->field_defs[$field]['type'] == 'relate') { continue; } $merge_fields[$field] = isset($focusBean->field_defs[$field]['vname']) ? $focusBean->field_defs[$field]['vname'] : $field; } //do not show the id on the merge screen if (!empty($merge_fields['id'])) { unset($merge_fields['id']); } $this->ss->assign('merge_fields', $merge_fields); $this->ss->assign('record_name', $this->_leadQual->merge_bean->name); $this->ss->assign('source_names', $source_names); $this->ss->assign('result_beans', $result_beans); $this->ss->assign('record', $this->_leadQual->merge_bean); $this->ss->assign('merge_module', $module); $this->ss->assign('mod', $GLOBALS['mod_strings']); echo $this->getModuleTitle(false); $this->ss->display($this->getCustomFilePathIfExists('modules/Connectors/tpls/step2.tpl')); } }
/** * @see SugarView::display() */ public function display() { $this->ss->assign('RECORD', $_REQUEST['record']); $this->ss->assign('module', $this->_merge_module); $this->ss->assign('mod', $GLOBALS['mod_strings']); $this->ss->assign('search_fields', $this->_trueFields); $this->ss->assign('fields', $this->seed->field_defs); $this->_tabs = array(); $first_source = ''; $source_instance = null; $source_list = array(); foreach ($this->_modules_sources[$_SESSION['merge_module']] as $source) { $s = SourceFactory::getSource($source); if ($s->isEnabledInWizard()) { $config = $s->getConfig(); $this->_tabs[] = array('title' => $config['name'], 'link' => $source, 'key' => $source); if (empty($first_source)) { $first_source = $source; $source_instance = ConnectorFactory::getInstance($source); } $source_list[] = $source; } } $this->ss->assign('SOURCES', $source_list); $this->ss->assign('source_id', $first_source); $this->_trueFields = array(); $field_defs = $source_instance->getFieldDefs(); $sMap = $source_instance->getModuleMapping($this->_merge_module); $searchLabels = ConnectorUtils::getConnectorStrings($first_source); if (!empty($this->_searchDefs[$first_source][$this->_merge_module])) { foreach ($this->_searchDefs[$first_source][$this->_merge_module] as $key) { $beanKey = $key; if (!empty($sMap[$key])) { $beanKey = $sMap[$key]; } if (!empty($this->seed->{$beanKey})) { $this->_trueFields[$key]['value'] = $this->seed->{$beanKey}; } else { $this->_trueFields[$key]['value'] = ''; } if (!empty($field_defs[$key]) && isset($searchLabels[$field_defs[$key]['vname']])) { $this->_trueFields[$key]['label'] = $searchLabels[$field_defs[$key]['vname']]; } else { $this->_trueFields[$key]['label'] = $key; } //$_trueFields[$key]['label'] = isset($searchLabels[$field_defs[$key]['vname']]) ? $searchLabels[$field_defs[$key]['vname']] : $key; $_SESSION['searchDefs'][$this->_merge_module][$this->seed->id][$first_source][$key] = $this->_trueFields[$key]['value']; } //foreach } //fi $this->ss->assign('search_fields', $this->_trueFields); $tab_panel = new ConnectorWidgetTabs($this->_tabs, $first_source, 'SourceTabs.loadTab', 'subpanelTablist'); $this->ss->assign('TABS', $tab_panel->display()); echo $this->getModuleTitle(false); echo $this->ss->fetch($this->getCustomFilePathIfExists('modules/Connectors/tpls/step1.tpl')); //display bean detail view $GLOBALS['module'] = $this->_merge_module; //end display bean detail view }
/** * getSources * Returns an Array of source entries found under the given directory * @param String $directory The directory to search * @return mixed $sources An Array of source entries */ private static function getSources($directory = 'modules/Connectors/connectors/sources') { if (file_exists($directory)) { $files = array(); $files = findAllFiles($directory, $files, false, 'config\\.php'); $start = strrpos($directory, '/') == strlen($directory) - 1 ? strlen($directory) : strlen($directory) + 1; $sources = array(); foreach ($files as $file) { require $file; $end = strrpos($file, '/') - $start; $source = array(); $source['id'] = str_replace('/', '_', substr($file, $start, $end)); $source['name'] = !empty($config['name']) ? $config['name'] : $source['id']; $source['enabled'] = true; $source['directory'] = $directory . '/' . str_replace('_', '/', $source['id']); $instance = ConnectorFactory::getInstance($source['id']); $mapping = $instance->getMapping(); $modules = array(); if (!empty($mapping['beans'])) { foreach ($mapping['beans'] as $module => $mapping_entry) { $modules[] = $module; } } $source['modules'] = $modules; $sources[$source['id']] = $source; } return $sources; } return array(); }