- 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 16992899d4
commit db5851e725
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']);
$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);
}
else if ( is_array($record->$name) && $record->$name['app'] && $record->$name['id'])
{
$record->$name = Link::title($record->$name['app'], $record->$name['id']);
}
}
else
{

View File

@ -17,10 +17,12 @@ use EGroupware\Api\Link;
/**
* 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');
$this->bo = new infolog_bo();
$this->get_selects();
@ -31,7 +33,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition) {
public function export( $_stream, importexport_definition $_definition)
{
$options = $_definition->plugin_options;
$selection = array();
@ -52,7 +55,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
// do we need to query the cf's
$query['custom_fields'] = false;
foreach($options['mapping'] + (array)$_definition->filter as $field => $map) {
if($field[0] == '#') {
if($field[0] == '#')
{
$query['custom_fields'] = true;
$query['selectcols'] .= ",$field";
@ -86,17 +90,21 @@ class infolog_export_csv implements importexport_iface_export_plugin {
}
$query['num_rows'] = 500;
$query['start'] = 0;
do {
do
{
$selection = $this->bo->search($query);
$ids = array_keys($selection);
// Pre-load any cfs that are links
$cf_preload = array();
foreach($cf_links as $field => $app) {
foreach($selection as &$row) {
foreach($cf_links as $field => $app)
{
foreach($selection as &$row)
{
if($row[$field]) $cf_preload[$app][] = $row[$field];
}
if($cf_preload[$app]){
if($cf_preload[$app])
{
$selects[$field] = Link::titles($app, $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'])
{
$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;
$selection[$id]['info_link_id'] = $link;
if($options['convert']) $selection[$id]['info_link_id'] = Link::title($link['app'], $link['id']);
$selection[$id]['info_link_id'] = $link = array_pop($link);
if(!$options['convert'])
{
$selection[$id]['info_link_id'] = $link['app'].':'. $link['id'];
}
}
}
// 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) {
if(!is_array($_identifier)) {
foreach ($selection as $_identifier)
{
if(!is_array($_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]))
{
$record->pm_id = current($project);
$record->project = Link::title('projectmanager', $record->pm_id);
}
} else {
}
else
{
$record = new infolog_egw_record();
$record->set_record($_identifier);
}
// Some conversion
if($options['convert']) {
if($options['convert'])
{
$this->selects['info_status'] = $this->bo->get_status($record->info_type);
importexport_export_csv::convert($record, infolog_egw_record::$types, 'infolog', $this->selects);
$this->convert($record);
@ -165,9 +185,12 @@ class infolog_export_csv implements importexport_iface_export_plugin {
{
if($record->$field == 0) $record->$field = '';
}
} else {
}
else
{
// 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);
}
}
@ -181,7 +204,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
*
* @return string name
*/
public static function get_name() {
public static function get_name()
{
return lang('Infolog CSV export');
}
@ -190,7 +214,8 @@ class infolog_export_csv implements importexport_iface_export_plugin {
*
* @return string descriprion
*/
public static function get_description() {
public static function get_description()
{
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
*/
public static function get_filesuffix() {
public static function get_filesuffix()
{
return 'csv';
}
public static function get_mimetype() {
public static function get_mimetype()
{
return 'text/csv';
}
@ -226,14 +253,16 @@ class infolog_export_csv implements importexport_iface_export_plugin {
*
* @return string html
*/
public function get_options_etpl() {
public function get_options_etpl()
{
}
/**
* returns slectors of this plugin via xajax
*
*/
public function get_selectors_etpl() {
public function get_selectors_etpl()
{
return array(
'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.
*/
public static function convert(infolog_egw_record &$record) {
public static function convert(infolog_egw_record &$record)
{
// Stub, for now
}