- Improve export link conversion to be able to handle links as arrays with app & id

- Fix sometimes missing infolog link titles when exporting
This commit is contained in:
nathangray 2016-09-14 09:25:23 -06:00
parent c09cfa5a23
commit 6e2e877778
2 changed files with 61 additions and 26 deletions

View File

@ -341,9 +341,14 @@ class importexport_export_csv implements importexport_iface_export_record
$links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']); $links[$name] = ($link['link_app1'] == $appname ? $link['link_app2'] : $link['link_app1']);
$record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']); $record->$name = ($link['link_app1'] == $appname ? $link['link_id2'] : $link['link_id1']);
} }
if($links[$name]) { if($links[$name])
{
$record->$name = Link::title($links[$name], $record->$name); $record->$name = Link::title($links[$name], $record->$name);
} }
else if ( is_array($record->$name) && $record->$name['app'] && $record->$name['id'])
{
$record->$name = Link::title($record->$name['app'], $record->$name['id']);
}
} }
else else
{ {

View File

@ -17,10 +17,12 @@ use EGroupware\Api\Link;
/** /**
* export plugin of infolog * export plugin of infolog
*/ */
class infolog_export_csv implements importexport_iface_export_plugin { class infolog_export_csv implements importexport_iface_export_plugin
{
public function __construct() { public function __construct()
{
Api\Translation::add_app('infolog'); Api\Translation::add_app('infolog');
$this->bo = new infolog_bo(); $this->bo = new infolog_bo();
$this->get_selects(); $this->get_selects();
@ -31,7 +33,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* @param egw_record $_definition * @param egw_record $_definition
*/ */
public function export( $_stream, importexport_definition $_definition) { public function export( $_stream, importexport_definition $_definition)
{
$options = $_definition->plugin_options; $options = $_definition->plugin_options;
$selection = array(); $selection = array();
@ -52,7 +55,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
// do we need to query the cf's // do we need to query the cf's
$query['custom_fields'] = false; $query['custom_fields'] = false;
foreach($options['mapping'] + (array)$_definition->filter as $field => $map) { foreach($options['mapping'] + (array)$_definition->filter as $field => $map) {
if($field[0] == '#') { if($field[0] == '#')
{
$query['custom_fields'] = true; $query['custom_fields'] = true;
$query['selectcols'] .= ",$field"; $query['selectcols'] .= ",$field";
@ -86,17 +90,21 @@ class infolog_export_csv implements importexport_iface_export_plugin {
} }
$query['num_rows'] = 500; $query['num_rows'] = 500;
$query['start'] = 0; $query['start'] = 0;
do { do
{
$selection = $this->bo->search($query); $selection = $this->bo->search($query);
$ids = array_keys($selection); $ids = array_keys($selection);
// Pre-load any cfs that are links // Pre-load any cfs that are links
$cf_preload = array(); $cf_preload = array();
foreach($cf_links as $field => $app) { foreach($cf_links as $field => $app)
foreach($selection as &$row) { {
foreach($selection as &$row)
{
if($row[$field]) $cf_preload[$app][] = $row[$field]; if($row[$field]) $cf_preload[$app][] = $row[$field];
} }
if($cf_preload[$app]){ if($cf_preload[$app])
{
$selects[$field] = Link::titles($app, $cf_preload[$app]); $selects[$field] = Link::titles($app, $cf_preload[$app]);
//error_log('Preload ' . $field . '['.$app . ']: ' . implode(',',$cf_preload[$app])); //error_log('Preload ' . $field . '['.$app . ']: ' . implode(',',$cf_preload[$app]));
} }
@ -122,10 +130,14 @@ class infolog_export_csv implements importexport_iface_export_plugin {
if($ids && $options['mapping']['info_link_id']) if($ids && $options['mapping']['info_link_id'])
{ {
$links = Link::get_links_multiple('infolog', $ids, true, '!'.Link::VFS_APPNAME); $links = Link::get_links_multiple('infolog', $ids, true, '!'.Link::VFS_APPNAME);
foreach($links as $id => $link) { foreach($links as $id => $link)
{
if(!is_array($selection[$id])) break; if(!is_array($selection[$id])) break;
$selection[$id]['info_link_id'] = $link; $selection[$id]['info_link_id'] = $link = array_pop($link);
if($options['convert']) $selection[$id]['info_link_id'] = Link::title($link['app'], $link['id']); if(!$options['convert'])
{
$selection[$id]['info_link_id'] = $link['app'].':'. $link['id'];
}
} }
} }
// If exporting PM fields, pre-load them all at once // If exporting PM fields, pre-load them all at once
@ -141,21 +153,29 @@ class infolog_export_csv implements importexport_iface_export_plugin {
} }
} }
foreach ($selection as $_identifier) { foreach ($selection as $_identifier)
if(!is_array($_identifier)) { {
if(!is_array($_identifier))
{
$record = new infolog_egw_record($_identifier); $record = new infolog_egw_record($_identifier);
if(($link = $links[$record->info_id])) $record->info_link_id = $options['convert'] ? Link::title($link['app'], $link['id']) : $link; if(($link = $links[$record->info_id]))
{
$record->info_link_id = $options['convert'] ? Link::title($link['app'], $link['id']) : ($link['app'].':'.$link['id']);
}
if(($project = $projects[$record->info_id])) if(($project = $projects[$record->info_id]))
{ {
$record->pm_id = current($project); $record->pm_id = current($project);
$record->project = Link::title('projectmanager', $record->pm_id); $record->project = Link::title('projectmanager', $record->pm_id);
} }
} else { }
else
{
$record = new infolog_egw_record(); $record = new infolog_egw_record();
$record->set_record($_identifier); $record->set_record($_identifier);
} }
// Some conversion // Some conversion
if($options['convert']) { if($options['convert'])
{
$this->selects['info_status'] = $this->bo->get_status($record->info_type); $this->selects['info_status'] = $this->bo->get_status($record->info_type);
importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog', $this->selects); importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog', $this->selects);
$this->convert($record); $this->convert($record);
@ -165,9 +185,12 @@ class infolog_export_csv implements importexport_iface_export_plugin {
{ {
if($record->$field == 0) $record->$field = ''; if($record->$field == 0) $record->$field = '';
} }
} else { }
else
{
// Implode arrays, so they don't say 'Array' // Implode arrays, so they don't say 'Array'
foreach($record->get_record_array() as $key => $value) { foreach($record->get_record_array() as $key => $value)
{
if(is_array($value)) $record->$key = implode(',', $value); if(is_array($value)) $record->$key = implode(',', $value);
} }
} }
@ -181,7 +204,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* @return string name * @return string name
*/ */
public static function get_name() { public static function get_name()
{
return lang('Infolog CSV export'); return lang('Infolog CSV export');
} }
@ -190,7 +214,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* @return string descriprion * @return string descriprion
*/ */
public static function get_description() { public static function get_description()
{
return lang("Exports Infolog entries into a CSV File."); return lang("Exports Infolog entries into a CSV File.");
} }
@ -199,11 +224,13 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* @return string suffix * @return string suffix
*/ */
public static function get_filesuffix() { public static function get_filesuffix()
{
return 'csv'; return 'csv';
} }
public static function get_mimetype() { public static function get_mimetype()
{
return 'text/csv'; return 'text/csv';
} }
@ -226,14 +253,16 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* @return string html * @return string html
*/ */
public function get_options_etpl() { public function get_options_etpl()
{
} }
/** /**
* returns slectors of this plugin via xajax * returns slectors of this plugin via xajax
* *
*/ */
public function get_selectors_etpl() { public function get_selectors_etpl()
{
return array( return array(
'name' => 'infolog.export_csv_selectors', 'name' => 'infolog.export_csv_selectors',
); );
@ -263,7 +292,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
* *
* This is for something specific to Infolog, in addition to the normal conversions. * This is for something specific to Infolog, in addition to the normal conversions.
*/ */
public static function convert(infolog_egw_record &$record) { public static function convert(infolog_egw_record &$record)
{
// Stub, for now // Stub, for now
} }