/** * Return list of available data importers * * @param int $pn_table_num * @param array $pa_options * countOnly = return number of importers available rather than a list of importers * formats = array of input formats to limit returned importers to. Only importers that accept at least one of the specified formats will be returned. * * @return mixed List of importers, or integer count of importers if countOnly option is set */ public static function getImporters($pn_table_num = null, $pa_options = null) { $o_db = new Db(); $t_importer = new ca_data_importers(); $vo_dm = $t_importer->getAppDatamodel(); $va_formats = caGetOption('formats', $pa_options, null, array('forceLowercase' => true)); $va_sql_wheres = array("(deleted = 0)"); $va_sql_params = array(); if ((int) $pn_table_num) { $va_sql_wheres[] = "(di.table_num = ?)"; $va_sql_params[] = (int) $pn_table_num; } $vs_sql_wheres = sizeof($va_sql_wheres) ? " WHERE " . join(" AND ", $va_sql_wheres) : ""; $qr_res = $o_db->query("\n\t\t\tSELECT *\n\t\t\tFROM ca_data_importers di\n\t\t\t{$vs_sql_wheres}\n\t\t", $va_sql_params); $va_importers = array(); $va_ids = array(); if (isset($pa_options['countOnly']) && $pa_options['countOnly']) { return (int) $qr_res->numRows(); } while ($qr_res->nextRow()) { $va_row = $qr_res->getRow(); $va_settings = caUnserializeForDatabase($va_row['settings']); if (isset($va_settings['inputFormats']) && is_array($va_settings['inputFormats']) && is_array($va_formats)) { $va_settings['inputFormats'] = array_map('strtolower', $va_settings['inputFormats']); if (!sizeof(array_intersect($va_settings['inputFormats'], $va_formats))) { continue; } } $va_ids[] = $vn_id = $va_row['importer_id']; $va_importers[$vn_id] = $va_row; $t_instance = $vo_dm->getInstanceByTableNum($va_row['table_num'], true); $va_importers[$vn_id]['importer_type'] = $t_instance->getProperty('NAME_PLURAL'); $va_importers[$vn_id]['type'] = $va_settings['type']; $va_importers[$vn_id]['type_for_display'] = $t_instance->getTypeName($va_settings['type']); $va_importers[$vn_id]['settings'] = $va_settings; $va_importers[$vn_id]['last_modified_on'] = $t_importer->getLastChangeTimestamp($vn_id, array('timestampOnly' => true)); } $va_labels = $t_importer->getPreferredDisplayLabelsForIDs($va_ids); foreach ($va_labels as $vn_id => $vs_label) { $va_importers[$vn_id]['label'] = $vs_label; } return $va_importers; }