Import/Export - change signature of method that gets options to allow definition-specific values

Do export too, for consistency
This commit is contained in:
nathangray 2018-11-29 10:32:42 -07:00
parent 85a3b3e027
commit 8451836a92
8 changed files with 202 additions and 75 deletions

View File

@ -349,9 +349,19 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
* return html for options. * return html for options.
* this way the plugin has all opertunities for options tab * this way the plugin has all opertunities for options tab
* *
* @return string html * @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() { public function get_options_etpl(importexport_definition &$definition = NULL)
{
return false;
} }
/** /**

View File

@ -16,7 +16,8 @@ use EGroupware\Api;
/** /**
* export addressbook contacts as vcard * export addressbook contacts as vcard
*/ */
class addressbook_export_vcard implements importexport_iface_export_plugin { class addressbook_export_vcard implements importexport_iface_export_plugin
{
/** /**
@ -24,7 +25,8 @@ class addressbook_export_vcard 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;
$this->uicontacts = new addressbook_ui(); $this->uicontacts = new addressbook_ui();
@ -33,7 +35,8 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
// Addressbook defines its own export imits // Addressbook defines its own export imits
$limit_exception = Api\Storage\Merge::is_export_limit_excepted(); $limit_exception = Api\Storage\Merge::is_export_limit_excepted();
$export_limit = Api\Storage\Merge::getExportLimit($app='addressbook'); $export_limit = Api\Storage\Merge::getExportLimit($app='addressbook');
if($export_limit == 'no' && !$limit_exception) { if($export_limit == 'no' && !$limit_exception)
{
return; return;
} }
@ -41,7 +44,8 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
$old_app = $GLOBALS['egw_info']['flags']['currentapp']; $old_app = $GLOBALS['egw_info']['flags']['currentapp'];
$GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook'; $GLOBALS['egw_info']['flags']['currentapp'] = 'addressbook';
if ($options['selection'] == 'search') { if ($options['selection'] == 'search')
{
// uicontacts selection with checkbox 'use_all' // uicontacts selection with checkbox 'use_all'
$query = Api\Cache::getSession('addressbook', 'index'); $query = Api\Cache::getSession('addressbook', 'index');
$query['num_rows'] = -1; // all $query['num_rows'] = -1; // all
@ -50,22 +54,28 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
$readonlys = null; $readonlys = null;
$this->uicontacts->get_rows($query,$this->selection,$readonlys, true); // only return the ids $this->uicontacts->get_rows($query,$this->selection,$readonlys, true); // only return the ids
} }
elseif ( $options['selection'] == 'all' ) { elseif ( $options['selection'] == 'all' )
if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '1') { {
if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '1')
{
$col_filter['account_id'] = null; $col_filter['account_id'] = null;
} }
$this->selection = ExecMethod2('addressbook.addressbook_bo.search', array(), true, '', '','',false,'AND',false,$col_filter); $this->selection = ExecMethod2('addressbook.addressbook_bo.search', array(), true, '', '','',false,'AND',false,$col_filter);
//$this->uicontacts->get_rows($query,$this->selection,$readonlys,true); //$this->uicontacts->get_rows($query,$this->selection,$readonlys,true);
} else { }
else
{
$this->selection = explode(',',$options['selection']); $this->selection = explode(',',$options['selection']);
} }
$GLOBALS['egw_info']['flags']['currentapp'] = $old_app; $GLOBALS['egw_info']['flags']['currentapp'] = $old_app;
if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception) { if(Api\Storage\Merge::hasExportLimit($export_limit) && !$limit_exception)
{
$this->selection = array_slice($this->selection, 0, $export_limit); $this->selection = array_slice($this->selection, 0, $export_limit);
} }
foreach ($this->selection as &$_contact) { foreach ($this->selection as &$_contact)
{
if(is_array($_contact) && ($_contact['id'] || $_contact['contact_id'])) if(is_array($_contact) && ($_contact['id'] || $_contact['contact_id']))
{ {
$_contact = $_contact[$_contact['id'] ? 'id' : 'contact_id']; $_contact = $_contact[$_contact['id'] ? 'id' : 'contact_id'];
@ -86,7 +96,8 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
* *
* @return string name * @return string name
*/ */
public static function get_name() { public static function get_name()
{
return lang('Addressbook vCard export'); return lang('Addressbook vCard export');
} }
@ -95,7 +106,8 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
* *
* @return string descriprion * @return string descriprion
*/ */
public static function get_description() { public static function get_description()
{
return lang("Exports contacts from your Addressbook into a vCard File."); return lang("Exports contacts from your Addressbook into a vCard File.");
} }
@ -104,11 +116,13 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
* *
* @return string suffix * @return string suffix
*/ */
public static function get_filesuffix() { public static function get_filesuffix()
{
return 'vcf'; return 'vcf';
} }
public static function get_mimetype() { public static function get_mimetype()
{
return 'text/x-vcard'; return 'text/x-vcard';
} }
@ -126,19 +140,29 @@ class addressbook_export_vcard implements importexport_iface_export_plugin {
} }
/** /**
* return html for options. * Return array of settings for export dialog
* this way the plugin has all opertunities for options tab
* *
* @return string html * @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() { public function get_options_etpl(importexport_definition &$definition = NULL)
{
return false;
} }
/** /**
* 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' => 'addressbook.export_vcard_selectors', 'name' => 'addressbook.export_vcard_selectors',
'content' => 'all', 'content' => 'all',

View File

@ -222,13 +222,23 @@ class calendar_export_csv implements importexport_iface_export_plugin {
{ {
return 'text/csv'; return 'text/csv';
} }
/** /**
* return html for options. * Return array of settings for export dialog
* *
* @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl($definition = null) public function get_options_etpl(importexport_definition &$definition = NULL)
{ {
return false;
} }
/** /**

View File

@ -124,13 +124,23 @@ class calendar_export_ical extends calendar_export_csv {
} }
/** /**
* return html for options. * Return array of settings for export dialog
* *
* @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl($definition = null) { public function get_options_etpl(importexport_definition &$definition = NULL)
unset($definition); // not used, but required by function signature {
return false;
} }
/** /**
* returns selectors of this plugin * returns selectors of this plugin
* *

View File

@ -251,10 +251,19 @@ class infolog_export_csv implements importexport_iface_export_plugin
* return html for options. * return html for options.
* this way the plugin has all opertunities for options tab * this way the plugin has all opertunities for options tab
* *
* @return string html * @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() public function get_options_etpl(importexport_definition &$definition = NULL)
{ {
return false;
} }
/** /**

View File

@ -97,10 +97,21 @@ class infolog_export_ical extends infolog_export_csv {
} }
/** /**
* return html for options. * return array for options.
* *
* @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() { public function get_options_etpl(importexport_definition &$definition = NULL)
{
return false;
} }
/** /**

View File

@ -17,7 +17,8 @@ use EGroupware\Api\Acl;
/** /**
* export resources to CSV * export resources to CSV
*/ */
class resources_export_csv implements importexport_iface_export_plugin { class resources_export_csv implements importexport_iface_export_plugin
{
public function __construct() public function __construct()
{ {
@ -31,11 +32,13 @@ class resources_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();
if ($options['selection'] == 'search') { if ($options['selection'] == 'search')
{
// ui selection with checkbox 'selected' // ui selection with checkbox 'selected'
$query = Api\Cache::getSession('resources', 'get_rows'); $query = Api\Cache::getSession('resources', 'get_rows');
$query['num_rows'] = -1; // all $query['num_rows'] = -1; // all
@ -43,13 +46,14 @@ class resources_export_csv implements importexport_iface_export_plugin {
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
$this->bo->get_rows($query,$selection,$readonlys); $this->bo->get_rows($query,$selection,$readonlys);
} }
elseif ( $options['selection'] == 'all' || $options['selection'] == 'filter') { elseif ( $options['selection'] == 'all' || $options['selection'] == 'filter')
{
$query = array( $query = array(
'num_rows' => -1, 'num_rows' => -1,
'filter2' => -3, // Accessories & resources 'filter2' => -3, // Accessories & resources
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
); // all ); // all
if($options['selection'] == 'filter') if($options['selection'] == 'filter')
{ {
$filter = $_definition->filter; $filter = $_definition->filter;
@ -75,9 +79,11 @@ class resources_export_csv implements importexport_iface_export_plugin {
unset($query['col_filter'][$field]); unset($query['col_filter'][$field]);
} }
} }
$this->bo->get_rows($query,$selection,$readonlys); $this->bo->get_rows($query,$selection,$readonlys);
} else { }
else
{
$selection = explode(',',$options['selection']); $selection = explode(',',$options['selection']);
} }
@ -86,27 +92,35 @@ class resources_export_csv implements importexport_iface_export_plugin {
// Check if we need to load the custom fields // Check if we need to load the custom fields
$need_custom = false; $need_custom = false;
foreach(Api\Storage\Customfields::get('resources') as $field => $settings) { foreach(Api\Storage\Customfields::get('resources') as $field => $settings)
if($options['mapping']['#'.$field]) { {
if($options['mapping']['#'.$field])
{
$need_custom = true; $need_custom = true;
break; break;
} }
} }
foreach ($selection as $record) { foreach ($selection as $record)
{
if(!is_array($record) || !$record['res_id']) continue; if(!is_array($record) || !$record['res_id']) continue;
if($need_custom) { if($need_custom)
{
$record = $this->bo->read($record['res_id']); $record = $this->bo->read($record['res_id']);
} }
$resource = new resources_egw_record(); $resource = new resources_egw_record();
$resource->set_record($record); $resource->set_record($record);
$resource->long_description = strip_tags($resource->long_description); $resource->long_description = strip_tags($resource->long_description);
if($options['convert']) { if($options['convert'])
{
importexport_export_csv::convert($resource, resources_egw_record::$types, 'resources', $this->selects); importexport_export_csv::convert($resource, resources_egw_record::$types, 'resources', $this->selects);
} else { }
else
{
// Implode arrays, so they don't say 'Array' // Implode arrays, so they don't say 'Array'
foreach($resource->get_record_array() as $key => $value) { foreach($resource->get_record_array() as $key => $value)
{
if(is_array($value)) $resource->$key = implode(',', $value); if(is_array($value)) $resource->$key = implode(',', $value);
} }
} }
@ -122,7 +136,8 @@ class resources_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('Resources CSV export'); return lang('Resources CSV export');
} }
@ -131,7 +146,8 @@ class resources_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 a list of resources to a CSV File."); return lang("Exports a list of resources to a CSV File.");
} }
@ -140,27 +156,40 @@ class resources_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';
} }
/** /**
* return html for options. * Return array of settings for export dialog
* this way the plugin has all opportunities for options tab
* *
* @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() { public function get_options_etpl(importexport_definition &$definition = NULL)
{
return false;
} }
/** /**
* returns selectors information * returns selectors information
* *
*/ */
public function get_selectors_etpl() { public function get_selectors_etpl()
{
return array( return array(
'name' => 'importexport.export_csv_selectors', 'name' => 'importexport.export_csv_selectors',
); );
@ -170,9 +199,9 @@ class resources_export_csv implements importexport_iface_export_plugin {
* Get selectbox values * Get selectbox values
*/ */
protected function get_selects() protected function get_selects()
{ {
$this->selects = array(); $this->selects = array();
} }
/** /**
* Customize automatically generated filter fields * Customize automatically generated filter fields

View File

@ -16,7 +16,8 @@ use EGroupware\Api;
/** /**
* export plugin of addressbook * export plugin of addressbook
*/ */
class timesheet_export_csv implements importexport_iface_export_plugin { class timesheet_export_csv implements importexport_iface_export_plugin
{
public function __construct() public function __construct()
{ {
@ -29,18 +30,22 @@ class timesheet_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;
$this->ui = new timesheet_ui(); $this->ui = new timesheet_ui();
$selection = array(); $selection = array();
if($options['selection'] == 'search') { if($options['selection'] == 'search')
{
$query = Api\Cache::getSession(TIMESHEET_APP, 'index'); $query = Api\Cache::getSession(TIMESHEET_APP, 'index');
$query['num_rows'] = -1; // all records $query['num_rows'] = -1; // all records
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
$this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's $this->ui->get_rows($query,$selection,$readonlys,true); // true = only return the id's
} elseif($options['selection'] == 'all') { }
elseif($options['selection'] == 'all')
{
$query = array( $query = array(
'num_rows' => -1, 'num_rows' => -1,
'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session 'csv_export' => true, // so get_rows method _can_ produce different content or not store state in the session
@ -83,13 +88,18 @@ class timesheet_export_csv implements importexport_iface_export_plugin {
// $options['selection'] is array of identifiers as this plugin doesn't // $options['selection'] is array of identifiers as this plugin doesn't
// support other selectors atm. // support other selectors atm.
foreach ($selection as $identifier) { foreach ($selection as $identifier)
{
$record = new timesheet_egw_record($identifier); $record = new timesheet_egw_record($identifier);
if($options['convert']) { if($options['convert'])
{
importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects); importexport_export_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $this->selects);
} 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);
} }
} }
@ -104,7 +114,8 @@ class timesheet_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('Timesheet CSV export'); return lang('Timesheet CSV export');
} }
@ -113,7 +124,8 @@ class timesheet_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 entries from your Timesheet into a CSV File. "); return lang("Exports entries from your Timesheet into a CSV File. ");
} }
@ -122,21 +134,31 @@ class timesheet_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';
}
/** /**
* return html for options. * Return array of settings for export dialog
* this way the plugin has all opportunities for options tab
* *
* @return string html * @param $definition Specific definition
*
* @return array (
* name => string,
* content => array,
* sel_options => array,
* readonlys => array,
* preserv => array,
* )
*/ */
public function get_options_etpl() { public function get_options_etpl(importexport_definition &$definition = NULL)
{
return false; return false;
} }
@ -144,7 +166,8 @@ class timesheet_export_csv implements importexport_iface_export_plugin {
* 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' => 'importexport.export_csv_selectors', 'name' => 'importexport.export_csv_selectors',
); );
@ -155,7 +178,8 @@ class timesheet_export_csv implements importexport_iface_export_plugin {
$this->selects = array( $this->selects = array(
'ts_status' => $this->ui->status_labels+array(lang('No status')) 'ts_status' => $this->ui->status_labels+array(lang('No status'))
); );
foreach($this->selects['ts_status'] as &$status) { foreach($this->selects['ts_status'] as &$status)
{
$status = str_replace(' ','',$status); // Remove   $status = str_replace(' ','',$status); // Remove  
} }