plugin and wrapper class for addressbook to use importexport framework

This commit is contained in:
Cornelius Weiß 2006-11-10 15:35:35 +00:00
parent b7d62c7b09
commit 522009d565
2 changed files with 251 additions and 0 deletions

View File

@ -0,0 +1,151 @@
<?php
/**
* eGroupWare - Addressbook - importexport
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package addressbook
* @subpackage importexport
* @link http://www.egroupware.org
* @author Cornelius Weiss <nelius@cwtech.de>
* @copyright Cornelius Weiss <nelius@cwtech.de>
* @version $Id$
*/
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_egw_record.inc.php');
require_once(EGW_INCLUDE_ROOT. '/addressbook/inc/class.bocontacts.inc.php');
/**
* class egw_addressbook_record
* compability layer for iface_egw_record needet for importexport
*/
class egw_addressbook_record implements iface_egw_record
{
private $identifier = '';
private $contact = array();
private $bocontacts;
/**
* constructor
* reads record from backend if identifier is given.
*
* @param string $_identifier
*/
public function __construct( $_identifier='' ){
$this->identifier = $_identifier;
$this->bocontacts = new bocontacts();
$this->contact = $this->bocontacts->read($this->identifier);
}
/**
* magic method to set attributes of record
*
* @param string $_attribute_name
*/
public function __get($_attribute_name) {
}
/**
* magig method to set attributes of record
*
* @param string $_attribute_name
* @param data $data
*/
public function __set($_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->contact;
}
/**
* gets title of record
*
*@return string tiltle
*/
public function get_title() {
if (empty($this->contact)) {
$this->get_record();
}
return $this->contact['fn'];
}
/**
* sets complete record from associative array
*
* @todo add some checks
* @return void
*/
public function set_record(array $_record){
$this->contact = $_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->bocontacts);
}
} // end of egw_addressbook_record
?>

View File

@ -0,0 +1,100 @@
<?php
/**
* eGroupWare
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package addressbook
* @subpackage importexport
* @link http://www.egroupware.org
* @author Cornelius Weiss <nelius@cwtech.de>
* @copyright Cornelius Weiss <nelius@cwtech.de>
* @version $Id$
*/
require_once(EGW_INCLUDE_ROOT. '/etemplate/inc/class.etemplate.inc.php');
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.export_csv.inc.php');
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.iface_export_plugin.inc.php');
require_once(EGW_INCLUDE_ROOT. '/addressbook/inc/class.egw_addressbook_record.inc.php');
require_once(EGW_INCLUDE_ROOT. '/addressbook/inc/class.uicontacts.inc.php');
/**
* export plugin of addressbook
*/
class export_contacts_csv implements iface_export_plugin {
/**
* Exports records as defined in $_definition
*
* @param egw_record $_definition
*/
public static function export( $_stream, $_charset, definition $_definition) {
$options = $_definition->options;
$uicontacts = new uicontacts();
$selection = array();
if ($options['selection'] == 'use_all') {
$query = $GLOBALS['egw']->session->appsession('index','addressbook');
$query['num_rows'] = -1; // all
$uicontacts->get_rows($query,$selection,$readonlys,true); // true = only return the id's
}
else {
$selection = explode(',',$options['selection']);
}
$options['begin_with_fieldnames'] = true;
$export_object = new export_csv($_stream, $charset, (array)$options);
// $options['selection'] is array of identifiers as this plugin doesn't
// support other selectors atm.
foreach ($selection as $identifier) {
$contact = new egw_addressbook_record($identifier);
$export_object->export_record($contact);
unset($contact);
}
}
/**
* returns translated name of plugin
*
* @return string name
*/
public static function get_name() {
return lang('Addressbook CSV export');
}
/**
* returns translated (user) description of plugin
*
* @return string descriprion
*/
public static function get_description() {
return lang("Exports contacts from your Addressbook into a CSV File. CSV means 'Comma Seperated Values'. However in the options Tab you can also choose other seperators.");
}
/**
* retruns file suffix for exported file
*
* @return string suffix
*/
public static function get_filesuffix() {
return 'csv';
}
/**
* return html for options.
* this way the plugin has all opertunities for options tab
*
* @return string html
*/
public static function get_options_etpl() {
return 'addressbook.export_csv_options';
}
/**
* returns slectors of this plugin via xajax
*
*/
public static function get_selectors_etpl() {
return '<b>Selectors:</b>';
}
}