Add exporting via importexport

This commit is contained in:
Nathan Gray 2010-11-08 17:20:20 +00:00
commit ac83f67993
4 changed files with 318 additions and 2 deletions

View File

@ -0,0 +1,148 @@
<?php
/**
* eGroupWare - Infolog - importexport
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package infolog
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray
* @version $Id$
*/
/**
* class infolog_egw_record
*
* compability layer for iface_egw_record needet for importexport
*/
class infolog_egw_record implements importexport_iface_egw_record
{
private $identifier = '';
private $record = array();
private $bo;
/**
* constructor
* reads record from backend if identifier is given.
*
* @param string $_identifier
*/
public function __construct( $_identifier='' ){
$this->identifier = $_identifier;
$this->bo = new infolog_bo();
if($_identifier) {
$this->record = $this->bo->read($this->identifier);
}
}
/**
* magic method to set attributes of record
*
* @param string $_attribute_name
*/
public function __get($_attribute_name) {
return $this->record[$_attribute_name];
}
/**
* magig method to set attributes of record
*
* @param string $_attribute_name
* @param data $data
*/
public function __set($_attribute_name, $data) {
$this->record[$_attribute_name] = $data;
}
/**
* converts this object to array.
* @abstract We need such a function cause PHP5
* dosn't allow objects do define it's own casts :-(
* once PHP can deal with object casts we will change to them!
*
* @return array complete record as associative array
*/
public function get_record_array() {
return $this->record;
}
/**
* gets title of record
*
*@return string tiltle
*/
public function get_title() {
if (empty($this->record)) {
$this->get_record();
}
return $this->record['title'];
}
/**
* sets complete record from associative array
*
* @todo add some checks
* @return void
*/
public function set_record(array $_record){
$this->record = $_record;
}
/**
* gets identifier of this record
*
* @return string identifier of current record
*/
public function get_identifier() {
return $this->identifier;
}
/**
* saves record into backend
*
* @return string identifier
*/
public function save ( $_dst_identifier ) {
}
/**
* copys current record to record identified by $_dst_identifier
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function copy ( $_dst_identifier ) {
}
/**
* moves current record to record identified by $_dst_identifier
* $this will become moved record
*
* @param string $_dst_identifier
* @return string dst_identifier
*/
public function move ( $_dst_identifier ) {
}
/**
* delets current record from backend
*
*/
public function delete () {
}
/**
* destructor
*
*/
public function __destruct() {
unset ($this->bo);
}
} // end of egw_addressbook_record
?>

View File

@ -0,0 +1,133 @@
<?php
/**
* eGroupWare
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package infolog
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright Nathan Gray
* @version $Id$
*/
/**
* export plugin of infolog
*/
class infolog_export_csv implements importexport_iface_export_plugin {
// Used in conversions
static $types = array(
'select-account' => array('info_owner','info_responsible','modifier'),
'date-time' => array('info_datecompleted', 'info_datemodified','created','last_event','next_event'),
'date' => array('info_startdate', 'info_enddate'),
'select-cat' => array('info_cat', 'cat_id'),
'links' => array('info_link_id'),
);
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public function export( $_stream, importexport_definition $_definition) {
$options = $_definition->plugin_options;
$bo = new infolog_bo();
$selection = array();
$query = array();
// do we need to query the cf's
foreach($options['mapping'] as $field => $map) {
if($field[0] == '#') $query['custom_fields'][] = $field;
}
if ($options['selection'] == 'search') {
$query = array_merge($GLOBALS['egw']->session->appsession('session_data','infolog'), $query);
$query['num_rows'] = -1; // all
$selection = $bo->search($query);
}
elseif ( $options['selection'] == 'all' ) {
$query['num_rows'] = -1;
$selection = $bo->search($query);
} else {
$selection = explode(',',$options['selection']);
}
$export_object = new importexport_export_csv($_stream, (array)$options);
$export_object->set_mapping($options['mapping']);
foreach ($selection as $_identifier) {
if(!is_array($_identifier)) {
$record = new infolog_egw_record($_identifier);
} else {
$record = new infolog_egw_record();
$record->set_record($_identifier);
}
// Some conversion
importexport_export_csv::convert($record, self::$types, 'infolog');
$this->convert($record);
$export_object->export_record($record);
unset($record);
}
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('Infolog CSV export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Exports Infolog entries into a CSV File.");
}
/**
* retruns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix() {
return 'csv';
}
public static function get_mimetype() {
return 'text/csv';
}
/**
* return html for options.
* this way the plugin has all opertunities for options tab
*
* @return string html
*/
public function get_options_etpl() {
return 'infolog.export_csv_options';
}
/**
* returns slectors of this plugin via xajax
*
*/
public function get_selectors_etpl() {
return 'infolog.export_csv_selectors';
}
/**
* Convert some internal data to something with more meaning
*
* This is for something specific to Infolog, in addition to the normal conversions.
*/
public static function convert(infolog_egw_record &$record) {
// Stub, for now
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* eGroupWare - Wizard for Infolog CSV export
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package infolog
* @subpackage importexport
* @link http://www.egroupware.org
* @author Nathan Gray
* @version $Id$
*/
class infolog_wizard_export_csv extends importexport_wizard_basic_export_csv
{
public function __construct() {
parent::__construct();
// Field mapping
$bo = new infolog_tracking();
$this->export_fields = $bo->field2label;
// Custom fields
unset($this->export_fields['custom']); // Heading, not a real field
$custom = config::get_customfields('infolog', true);
foreach($custom as $name => $data) {
$this->export_fields['#'.$name] = $data['label'];
}
}
}

View File

@ -2,7 +2,7 @@
/**
* eGroupWare - eTemplates for Application infolog
* http://www.egroupware.org
* generated by soetemplate::dump4setup() 2010-11-02 15:12
* generated by soetemplate::dump4setup() 2010-11-08 10:19
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package infolog
@ -33,7 +33,9 @@ $templ_data[] = array('name' => 'infolog.edit.delegation','template' => '','lang
$templ_data[] = array('name' => 'infolog.edit.description','template' => '','lang' => '','group' => '0','version' => '1.6.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:3:{s:1:"A";s:3:"100";s:2:"c1";s:2:"th";s:2:"c2";s:7:"row,top";}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:11:"Description";s:4:"size";s:11:",,,info_des";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:6:{s:4:"type";s:8:"textarea";s:4:"size";s:2:"13";s:7:"no_lang";s:1:"1";s:4:"name";s:8:"info_des";s:4:"help";s:44:"enter a textual description of the log-entry";s:4:"span";s:12:",description";}}}s:4:"rows";i:2;s:4:"cols";i:2;s:4:"size";s:10:"100%,245,0";s:7:"options";a:3:{i:0;s:4:"100%";i:1;s:3:"245";i:2;s:1:"0";}}}','size' => '100%,245,0','style' => '','modified' => '1229074983',);
$templ_data[] = array('name' => 'infolog.edit.history','template' => '','lang' => '','group' => '0','version' => '1.3.002','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:1:{s:2:"c1";s:4:",top";}i:1;a:1:{s:1:"A";a:2:{s:4:"type";s:10:"historylog";s:4:"name";s:7:"history";}}}s:4:"rows";i:1;s:4:"cols";i:1;s:4:"size";s:17:"100%,245,,,,,auto";s:7:"options";a:3:{i:0;s:4:"100%";i:1;s:3:"245";i:6;s:4:"auto";}}}','size' => '100%,250,,,,,auto','style' => '','modified' => '1181576846',);
$templ_data[] = array('name' => 'infolog.edit.GroupType','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"template";s:4:"span";s:8:",noPrint";s:4:"name";s:12:"infolog.edit";}}i:2;a:1:{s:1:"A";a:1:{s:4:"type";s:5:"hrule";}}i:3;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:5:"label";s:10:"contact CF";s:4:"name";s:8:"#contact";}}i:4;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:5:"label";s:12:"Selection CF";s:4:"name";s:10:"#selection";}}i:5;a:1:{s:1:"A";a:6:{s:4:"type";s:13:"infolog-value";s:4:"size";s:10:"#selection";s:5:"label";s:7:"Auswahl";s:4:"name";s:7:"#linked";s:8:"readonly";s:1:"1";s:7:"options";a:1:{i:0;s:10:"#selection";}}}i:6;a:1:{s:1:"A";a:6:{s:4:"type";s:13:"infolog-value";s:4:"name";s:7:"#linked";s:8:"readonly";s:1:"1";s:4:"size";s:8:"#auftrag";s:5:"label";s:7:"Auftrag";s:7:"options";a:1:{i:0;s:8:"#auftrag";}}}}s:4:"rows";i:6;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1196994147',);
$templ_data[] = array('name' => 'infolog.edit.history','template' => '','lang' => '','group' => '0','version' => '1.3.002','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:1:{s:2:"c1";s:4:",top";}i:1;a:1:{s:1:"A";a:2:{s:4:"type";s:10:"historylog";s:4:"name";s:7:"history";}}}s:4:"rows";i:1;s:4:"cols";i:1;s:4:"size";s:17:"100%,245,,,,,auto";s:7:"options";a:3:{i:0;s:4:"100%";i:1;s:3:"245";i:6;s:4:"auto";}}}','size' => '100%,245,,,,,auto','style' => '','modified' => '1181576846',);
$templ_data[] = array('name' => 'infolog.edit.links','template' => '','lang' => '','group' => '0','version' => '1.3.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:6:{i:0;a:7:{s:1:"A";s:3:"100";s:2:"h1";s:13:",@status_only";s:2:"h2";s:13:",@status_only";s:2:"c1";s:2:"th";s:2:"c2";s:3:"row";s:2:"c4";s:2:"th";s:2:"c5";s:11:"row_off,top";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:16:"Create new links";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:3:{s:4:"type";s:7:"link-to";s:4:"span";s:3:"all";s:4:"name";s:7:"link_to";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:8:"link-add";s:4:"span";s:3:"all";s:4:"name";s:7:"link_to";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:14:"Existing links";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:9:"link-list";s:4:"span";s:3:"all";s:4:"name";s:7:"link_to";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:5;s:4:"cols";i:2;s:4:"size";s:17:"100%,245,,,,,auto";s:7:"options";a:3:{i:0;s:4:"100%";i:1;s:3:"245";i:6;s:4:"auto";}}}','size' => '100%,245,,,,,auto','style' => '','modified' => '1075977056',);
@ -49,6 +51,10 @@ $templ_data[] = array('name' => 'infolog.edit.print.project','template' => '','l
$templ_data[] = array('name' => 'infolog.edit.project','template' => '','lang' => '','group' => '0','version' => '1.5.004','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:8:{s:1:"A";s:3:"100";s:2:"c1";s:2:"th";s:2:"c2";s:3:"row";s:2:"c3";s:3:"row";s:2:"c4";s:3:"row";s:2:"c6";s:7:"row,top";s:2:"h6";s:3:"60%";s:2:"c5";s:3:"row";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:14:"Projectmanager";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:7:"Project";}s:1:"B";a:4:{s:4:"type";s:21:"projectmanager-select";s:4:"name";s:5:"pm_id";s:8:"onchange";s:1:"1";s:4:"size";s:4:"None";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:5:"Price";}s:1:"B";a:5:{s:4:"type";s:4:"hbox";s:4:"span";s:3:"all";s:4:"size";s:1:"2";i:1;a:4:{s:4:"type";s:24:"projectmanager-pricelist";s:4:"name";s:5:"pl_id";s:4:"size";s:4:"None";s:8:"onchange";s:207:"this.form[\'exec[info_price]\'].value=this.options[this.selectedIndex].text.lastIndexOf(\'(\') < 0 ? \'\' : this.options[this.selectedIndex].text.slice(this.options[this.selectedIndex].text.lastIndexOf(\'(\')+1,-1);";}i:2;a:3:{s:4:"type";s:5:"float";s:4:"name";s:10:"info_price";s:4:"span";s:3:"all";}}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:20:",,,info_planned_time";s:5:"label";s:12:"planned time";}s:1:"B";a:3:{s:4:"type";s:13:"date-duration";s:4:"name";s:17:"info_planned_time";s:4:"size";s:23:",$cont[duration_format]";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:22:",,,info_replanned_time";s:5:"label";s:15:"Re-planned time";}s:1:"B";a:3:{s:4:"type";s:13:"date-duration";s:4:"name";s:19:"info_replanned_time";s:4:"size";s:23:",$cont[duration_format]";}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"size";s:17:",,,info_used_time";s:5:"label";s:9:"used time";s:4:"help";s:64:"Leave blank to get the used time calculated by timesheet entries";}s:1:"B";a:2:{s:4:"type";s:13:"date-duration";s:4:"name";s:14:"info_used_time";}}}s:4:"rows";i:6;s:4:"cols";i:2;s:4:"size";s:8:"100%,245";s:7:"options";a:2:{i:0;s:4:"100%";i:1;s:3:"245";}}}','size' => '100%,245','style' => '','modified' => '1223093893',);
$templ_data[] = array('name' => 'infolog.export_csv_options','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:4:{i:0;a:1:{s:1:"B";s:5:"180px";}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";s:4:"name";s:3:"msg";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:14:"Fieldseperator";}s:1:"B";a:4:{s:4:"type";s:4:"text";s:7:"no_lang";s:1:"1";s:4:"name";s:9:"delimiter";s:4:"size";s:1:"1";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:14:"Include header";}s:1:"B";a:2:{s:4:"type";s:11:"select-bool";s:4:"name";s:21:"begin_with_fieldnames";}}}s:4:"rows";i:3;s:4:"cols";i:2;}}','size' => '','style' => '.width180 select { width:150px;}','modified' => '1289231885',);
$templ_data[] = array('name' => 'infolog.export_csv_selectors','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:7:"Use all";s:4:"size";s:3:"all";s:4:"name";s:9:"selection";}}i:2;a:1:{s:1:"A";a:4:{s:4:"type";s:5:"radio";s:5:"label";s:18:"Use search results";s:4:"name";s:9:"selection";s:4:"size";s:6:"search";}}}s:4:"rows";i:2;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1289231918',);
$templ_data[] = array('name' => 'infolog.importexport_wizard_chooseowner','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:6:{i:0;a:1:{s:2:"h2";s:14:",@no_owner_map";}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}}i:2;a:1:{s:1:"A";a:3:{s:4:"type";s:8:"checkbox";s:5:"label";s:30:"Use field from CSV if possible";s:4:"name";s:14:"owner_from_csv";}}i:3;a:1:{s:1:"A";a:2:{s:4:"type";s:14:"select-account";s:4:"name";s:5:"owner";}}i:4;a:1:{s:1:"A";a:1:{s:4:"type";s:5:"label";}}i:5;a:1:{s:1:"A";a:3:{s:4:"type";s:11:"select-bool";s:5:"label";s:26:"Change owner when updating";s:4:"name";s:12:"change_owner";}}}s:4:"rows";i:5;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1286389863',);
$templ_data[] = array('name' => 'infolog.index','template' => '','lang' => '','group' => '0','version' => '1.7.003','data' => 'a:1:{i:0;a:5:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:6:{s:1:"A";s:3:"90%";s:2:"h3";s:2:",1";s:2:"h2";s:6:",!@msg";s:2:"c6";s:7:"noPrint";s:2:"h4";s:7:",!@main";s:2:"h1";s:6:",!@css";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:4:"html";s:4:"span";s:3:"all";s:4:"name";s:3:"css";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:5:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:5:"align";s:6:"center";s:4:"name";s:3:"msg";s:7:"no_lang";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:8:"template";s:4:"name";s:11:"header_left";}s:1:"B";a:2:{s:4:"type";s:8:"template";s:4:"name";s:12:"header_right";}}i:4;a:2:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:4:"main";s:4:"span";s:3:"all";s:4:"name";s:27:"infolog.index.rows-noheader";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:4:{s:4:"type";s:9:"nextmatch";s:4:"size";s:20:"infolog.index.rows,1";s:4:"span";s:3:"all";s:4:"name";s:2:"nm";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:6;a:2:{s:1:"A";a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";s:4:"span";s:3:"all";i:1;a:5:{s:4:"type";s:6:"button";s:5:"label";s:3:"Add";s:4:"name";s:9:"add[note]";s:4:"help";s:15:"Add a new Entry";s:7:"onclick";s:245:"window.open(egw::link(\'/index.php\',\'menuaction=infolog.infolog_ui.edit&type=note&action=$cont[action]&action_id=$cont[action_id]&cat_id={$cont[nm][cat_id]}\'),\'_blank\',\'dependent=yes,width=750,height=600,scrollbars=yes,status=yes\'); return false;";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:6:"cancel";s:4:"help";s:17:"Back to main list";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:2;s:4:"size";s:12:"100%,,0,,0,0";}}','size' => '100%,,0,,0,0','style' => '','modified' => '1242996117',);