From 4f59f282a0d4313ba76a777857ca6eae2abb97ce Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 16 Oct 2012 18:45:13 +0000 Subject: [PATCH] If exporting a single record, name the download file accordingly --- .../inc/class.addressbook_egw_record.inc.php | 5 +-- ...ss.addressbook_export_contacts_csv.inc.php | 15 ++++++++- .../class.addressbook_export_vcard.inc.php | 31 +++++++++++++------ infolog/inc/class.infolog_egw_record.inc.php | 2 +- infolog/inc/class.infolog_export_csv.inc.php | 25 +++++++++++---- infolog/inc/class.infolog_export_ical.inc.php | 19 ++++++++++-- 6 files changed, 73 insertions(+), 24 deletions(-) diff --git a/addressbook/inc/class.addressbook_egw_record.inc.php b/addressbook/inc/class.addressbook_egw_record.inc.php index 5889e8321b..1c0b1ae3a9 100644 --- a/addressbook/inc/class.addressbook_egw_record.inc.php +++ b/addressbook/inc/class.addressbook_egw_record.inc.php @@ -83,10 +83,7 @@ class addressbook_egw_record implements importexport_iface_egw_record *@return string tiltle */ public function get_title() { - if (empty($this->contact)) { - $this->get_record(); - } - return $this->contact['fn']; + return $this->bocontacts->link_title(empty($this->contact) ? $this->identifier : $this->contact); } /** diff --git a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php index f793d6b1b6..465cf47267 100644 --- a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php @@ -33,7 +33,7 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi public function export( $_stream, importexport_definition $_definition) { $options = $_definition->plugin_options; - $export_object = new importexport_export_csv($_stream, (array)$options); + $this->export_object = $export_object = new importexport_export_csv($_stream, (array)$options); $uicontacts = new addressbook_ui(); $selection = array(); @@ -249,6 +249,19 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi return 'text/csv'; } + /** + * Suggest a file name for the downloaded file + * No suffix + */ + public function get_filename() + { + if(is_object($this->export_object) && $this->export_object->get_num_of_records() == 1) + { + return $this->export_object->record->get_title(); + } + return false; + } + /** * return html for options. * this way the plugin has all opertunities for options tab diff --git a/addressbook/inc/class.addressbook_export_vcard.inc.php b/addressbook/inc/class.addressbook_export_vcard.inc.php index c35681a6f8..7963d15e21 100644 --- a/addressbook/inc/class.addressbook_export_vcard.inc.php +++ b/addressbook/inc/class.addressbook_export_vcard.inc.php @@ -25,8 +25,8 @@ class addressbook_export_vcard implements importexport_iface_export_plugin { public function export( $_stream, importexport_definition $_definition) { $options = $_definition->plugin_options; - $uicontacts = new addressbook_ui(); - $selection = array(); + $this->uicontacts = new addressbook_ui(); + $this->selection = array(); // Addressbook defines its own export imits $limit_exception = bo_merge::is_export_limit_excepted(); @@ -46,24 +46,24 @@ class addressbook_export_vcard implements importexport_iface_export_plugin { $query['num_rows'] = -1; // all $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session if(!array_key_exists('filter',$query)) $query['filter'] = $GLOBALS['egw_info']['user']['account_id']; - $uicontacts->get_rows($query,$selection,$readonlys, true); // only return the ids + $this->uicontacts->get_rows($query,$this->selection,$readonlys, true); // only return the ids } elseif ( $options['selection'] == 'all_contacts' ) { if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts']) { $col_filter['account_id'] = null; } - $selection = ExecMethod2('addressbook.addressbook_bo.search', array(), true, '', '','',false,'AND',false,$col_filter); - //$uicontacts->get_rows($query,$selection,$readonlys,true); + $this->selection = ExecMethod2('addressbook.addressbook_bo.search', array(), true, '', '','',false,'AND',false,$col_filter); + //$this->uicontacts->get_rows($query,$this->selection,$readonlys,true); } else { - $selection = explode(',',$options['selection']); + $this->selection = explode(',',$options['selection']); } $GLOBALS['egw_info']['flags']['currentapp'] = $old_app; if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { - $selection = array_slice($selection, 0, $export_limit); + $this->selection = array_slice($this->selection, 0, $export_limit); } - foreach ($selection as &$_contact) { + foreach ($this->selection as &$_contact) { if(is_array($_contact) && ($_contact['id'] || $_contact['contact_id'])) { $_contact = $_contact[$_contact['id'] ? 'id' : 'contact_id']; @@ -74,7 +74,7 @@ class addressbook_export_vcard implements importexport_iface_export_plugin { $meta = stream_get_meta_data($_stream); $vcard = new addressbook_vcal(); - $vcard->export($selection, $meta['uri']); + $vcard->export($this->selection, $meta['uri']); } /** @@ -108,6 +108,19 @@ class addressbook_export_vcard implements importexport_iface_export_plugin { return 'text/x-vcard'; } + /** + * Suggest a file name for the downloaded file + * No suffix + */ + public function get_filename() + { + if(is_array($this->selection) && count($this->selection) == 1) + { + return $this->uicontacts->link_title($this->selection[0]); + } + return false; + } + /** * return html for options. * this way the plugin has all opertunities for options tab diff --git a/infolog/inc/class.infolog_egw_record.inc.php b/infolog/inc/class.infolog_egw_record.inc.php index 49c9d704b0..7ed15f1454 100644 --- a/infolog/inc/class.infolog_egw_record.inc.php +++ b/infolog/inc/class.infolog_egw_record.inc.php @@ -85,7 +85,7 @@ class infolog_egw_record implements importexport_iface_egw_record if (empty($this->record)) { $this->get_record(); } - return $this->record['title']; + return self::$bo->link_title($this->record); } /** diff --git a/infolog/inc/class.infolog_export_csv.inc.php b/infolog/inc/class.infolog_export_csv.inc.php index 17e7ed1247..8e42dd3ac8 100644 --- a/infolog/inc/class.infolog_export_csv.inc.php +++ b/infolog/inc/class.infolog_export_csv.inc.php @@ -37,8 +37,8 @@ class infolog_export_csv implements importexport_iface_export_plugin { $this->selects['info_priority'] = $this->bo->enums['priority']; } - $export_object = new importexport_export_csv($_stream, (array)$options); - $export_object->set_mapping($options['mapping']); + $this->export_object = new importexport_export_csv($_stream, (array)$options); + $this->export_object->set_mapping($options['mapping']); // do we need to query the cf's foreach($options['mapping'] as $field => $map) { @@ -77,18 +77,18 @@ class infolog_export_csv implements importexport_iface_export_plugin { } } - $this->export_records($export_object, $options, $selection, $ids); + $this->export_records($this->export_object, $options, $selection, $ids); $query['start'] += $query['num_rows']; } while($query['start'] < $query['total']); - return $export_object; + return $this->export_object; break; default: $ids = $selection = explode(',',$options['selection']); - $this->export_records($export_object, $options, $selection, $ids); + $this->export_records($this->export_object, $options, $selection, $ids); break; } - return $export_object; + return $this->export_object; } protected function export_records(&$export_object, $options, &$selection, $ids = array()) @@ -182,6 +182,19 @@ class infolog_export_csv implements importexport_iface_export_plugin { return 'text/csv'; } + /** + * Suggest a file name for the downloaded file + * No suffix + */ + public function get_filename() + { + if(is_object($this->export_object) && $this->export_object->get_num_of_records() == 1) + { + return $this->export_object->record->get_title(); + } + return false; + } + /** * return html for options. * this way the plugin has all opertunities for options tab diff --git a/infolog/inc/class.infolog_export_ical.inc.php b/infolog/inc/class.infolog_export_ical.inc.php index 213aa0f29a..d59b1314a2 100644 --- a/infolog/inc/class.infolog_export_ical.inc.php +++ b/infolog/inc/class.infolog_export_ical.inc.php @@ -38,16 +38,16 @@ class infolog_export_ical extends infolog_export_csv { case 'all': $query['num_rows'] = $export_limit ? $export_limit : -1; $query['start'] = 0; - $selection = $this->bo->search($query); + $this->selection = $this->bo->search($query); break; default: - $ids = $selection = explode(',',$options['selection']); + $ids = $this->selection = explode(',',$options['selection']); break; } $boical = new infolog_ical(); - fwrite($_stream, $boical->exportvCalendar($selection)); + fwrite($_stream, $boical->exportvCalendar($this->selection)); } /** @@ -81,6 +81,19 @@ class infolog_export_ical extends infolog_export_csv { return 'text/infolog'; } + /** + * Suggest a file name for the downloaded file + * No suffix + */ + public function get_filename() + { + if(is_array($this->selection) && count($this->selection) == 1) + { + return $this->bo->link_title(current($this->selection)); + } + return false; + } + /** * return html for options. *