From 522009d565f219292244aa5c104b95453962b1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Fri, 10 Nov 2006 15:35:35 +0000 Subject: [PATCH] plugin and wrapper class for addressbook to use importexport framework --- .../inc/class.egw_addressbook_record.inc.php | 151 ++++++++++++++++++ .../inc/class.export_contacts_csv.inc.php | 100 ++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 addressbook/inc/class.egw_addressbook_record.inc.php create mode 100644 addressbook/inc/class.export_contacts_csv.inc.php diff --git a/addressbook/inc/class.egw_addressbook_record.inc.php b/addressbook/inc/class.egw_addressbook_record.inc.php new file mode 100644 index 0000000000..2e2800ab5f --- /dev/null +++ b/addressbook/inc/class.egw_addressbook_record.inc.php @@ -0,0 +1,151 @@ + + * @copyright Cornelius Weiss + * @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 +?> diff --git a/addressbook/inc/class.export_contacts_csv.inc.php b/addressbook/inc/class.export_contacts_csv.inc.php new file mode 100644 index 0000000000..f28dff0a37 --- /dev/null +++ b/addressbook/inc/class.export_contacts_csv.inc.php @@ -0,0 +1,100 @@ + + * @copyright Cornelius Weiss + * @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 'Selectors:'; + } +} \ No newline at end of file