diff --git a/infolog/inc/class.infolog_export_csv.inc.php b/infolog/inc/class.infolog_export_csv.inc.php index a8781b4b5f..ebed04e313 100644 --- a/infolog/inc/class.infolog_export_csv.inc.php +++ b/infolog/inc/class.infolog_export_csv.inc.php @@ -90,6 +90,15 @@ class infolog_export_csv implements importexport_iface_export_plugin } $query['num_rows'] = 500; $query['start'] = 0; + if ($query['col_filter']['info_contact']) + { + $ui = new infolog_ui(); + $link_filters['linked'] = $query['col_filter']['info_contact']; + $links['linked'] = array(); + unset($query['col_filter']['info_contact']); + $rows = array(); + $linked = $ui->link_filters($links, $link_filters, $query, $rows); + } do { $selection = $this->bo->search($query); diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index 053deff27c..27f5b67402 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -358,40 +358,13 @@ class infolog_ui $link_filters['action'] = array('app'=>$query['action'], 'id' => $query['action_id']); $links['action'] = array(); } - foreach($link_filters as $key => $link) - { - if(!is_array($link)) - { - // Legacy string style - list($app,$id) = explode(':',$link); - } - else - { - // Full info - $app = $link['app']; - $id = $link['id']; - } - if(!is_array($id)) $id = explode(',',$id); - if (!($linked = Link::get_links_multiple($app,$id,true,'infolog','',$query['col_filter']['info_status'] == 'deleted'))) - { - $rows = array(); // no infologs linked to selected link --> no rows to return - return 0; - } - - foreach($linked as $infos) - { - $links[$key] = array_merge($links[$key],$infos); - } - $links[$key] = array_unique($links[$key]); - if($key == 'linked') - { - $linked = array('app' => $app, 'id' => $id, 'title' => (count($id) == 1 ? Link::title($app, $id) : lang('multiple'))); - } - } - if(count($links)) + // Process links + $linked = $this->link_filters($links, $link_filters, $query, $rows); + if($linked === 0) { - $query['col_filter']['info_id'] = count($links) > 1 ? call_user_func_array('array_intersect', $links) : $links[$key]; + // Link filter but no results, early exit + return 0; } // check if we have a custom, type-specific template @@ -576,6 +549,56 @@ class infolog_ui return $query['total']; } + /** + * Deal with link filters and translate them into something we can filter on, ids. + * + * @param $links + * @param $link_filters + * @param $query + * @param $rows + * @return int + */ + public function link_filters(&$links, $link_filters, &$query, &$rows) + { + foreach($link_filters as $key => $link) + { + if(!is_array($link)) + { + // Legacy string style + list($app,$id) = explode(':',$link); + } + else + { + // Full info + $app = $link['app']; + $id = $link['id']; + } + if(!is_array($id)) $id = explode(',',$id); + if (!($linked = Link::get_links_multiple($app,$id,true,'infolog','',$query['col_filter']['info_status'] == 'deleted'))) + { + $rows = array(); // no infologs linked to selected link --> no rows to return + return 0; + } + + + foreach($linked as $infos) + { + $links[$key] = array_merge($links[$key],$infos); + } + $links[$key] = array_unique($links[$key]); + if($key == 'linked') + { + $linked = array('app' => $app, 'id' => $id, 'title' => (count($id) == 1 ? Link::title($app, $id) : lang('multiple'))); + } + } + + if(count($links)) + { + $query['col_filter']['info_id'] = count($links) > 1 ? call_user_func_array('array_intersect', $links) : $links[$key]; + } + return $linked; + } + /** * Hook for timesheet to set some extra data and links *