If exporting a single record, name the download file accordingly

This commit is contained in:
Nathan Gray 2012-10-16 18:45:13 +00:00
parent e75e112598
commit 4f59f282a0
6 changed files with 73 additions and 24 deletions

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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.
*