mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-26 18:03:39 +01:00
Add import / export support through importexport app
This commit is contained in:
parent
7c55020318
commit
831c5e0f84
91
calendar/inc/class.calendar_export_ical.inc.php
Normal file
91
calendar/inc/class.calendar_export_ical.inc.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package calendar
|
||||
* @subpackage importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Nathan Gray
|
||||
* @copyright Nathan Gray
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* export iCal plugin of calendar
|
||||
*/
|
||||
class calendar_export_ical extends calendar_export_csv {
|
||||
|
||||
/**
|
||||
* Exports records as defined in $_definition
|
||||
*
|
||||
* @param egw_record $_definition
|
||||
*/
|
||||
public function export( $_stream, importexport_definition $_definition) {
|
||||
$options = $_definition->plugin_options;
|
||||
$this->bo = new calendar_bo();
|
||||
$boical = new calendar_ical();
|
||||
$events =& $this->bo->search(array(
|
||||
'start' => $options['selection']['start'],
|
||||
'end' => $options['selection']['end'],
|
||||
'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'],
|
||||
'enum_recuring' => false,
|
||||
'daywise' => false,
|
||||
'date_format' => 'server',
|
||||
));
|
||||
$ical =& $boical->exportVCal($events,'2.0','PUBLISH',false);
|
||||
fwrite($_stream, $ical);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('Calendar iCal export');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Exports events from your Calendar in iCal format.");
|
||||
}
|
||||
|
||||
/**
|
||||
* retruns file suffix for exported file
|
||||
*
|
||||
* @return string suffix
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'ics';
|
||||
}
|
||||
|
||||
public static function get_mimetype() {
|
||||
return 'text/calendar';
|
||||
}
|
||||
|
||||
/**
|
||||
* return html for options.
|
||||
*
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns selectors of this plugin
|
||||
*
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
return array(
|
||||
'name' => 'calendar.export_csv_select',
|
||||
'content' => array(
|
||||
'start' => time(),
|
||||
'end' => time()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
212
calendar/inc/class.calendar_import_ical.inc.php
Normal file
212
calendar/inc/class.calendar_import_ical.inc.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* eGroupWare
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package calendar
|
||||
* @subpackage importexport
|
||||
* @link http://www.egroupware.org
|
||||
* @author Nathan Gray
|
||||
* @copyright Nathan Gray
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* import ical for calendar
|
||||
*/
|
||||
class calendar_import_ical implements importexport_iface_import_plugin {
|
||||
|
||||
private static $plugin_options = array(
|
||||
'fieldsep', // char
|
||||
'charset', // string
|
||||
'owner', // int
|
||||
'update_cats', // string {override|add} overides record
|
||||
// with cat(s) from csv OR add the cat from
|
||||
// csv file to exeisting cat(s) of record
|
||||
'num_header_lines', // int number of header lines
|
||||
'field_conversion', // array( $csv_col_num => conversion)
|
||||
'field_mapping', // array( $csv_col_num => adb_filed)
|
||||
'conditions', /* => array containing condition arrays:
|
||||
'type' => exists, // exists
|
||||
'string' => '#kundennummer',
|
||||
'true' => array(
|
||||
'action' => update,
|
||||
'last' => true,
|
||||
),
|
||||
'false' => array(
|
||||
'action' => insert,
|
||||
'last' => true,
|
||||
),*/
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* actions wich could be done to data entries
|
||||
*/
|
||||
protected static $actions = array();
|
||||
|
||||
/**
|
||||
* conditions for actions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $conditions = array();
|
||||
|
||||
/**
|
||||
* @var definition
|
||||
*/
|
||||
private $definition;
|
||||
|
||||
/**
|
||||
* @var bo
|
||||
*/
|
||||
private $bo;
|
||||
|
||||
/**
|
||||
* For figuring out if an entry has changed
|
||||
*/
|
||||
protected $tracking;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $dry_run = false;
|
||||
|
||||
/**
|
||||
* @var bool is current user admin?
|
||||
*/
|
||||
private $is_admin = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $user = null;
|
||||
|
||||
/**
|
||||
* List of import errors
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* List of actions, and how many times that action was taken
|
||||
*/
|
||||
protected $results = array();
|
||||
|
||||
/**
|
||||
* imports entries according to given definition object.
|
||||
* @param resource $_stream
|
||||
* @param string $_charset
|
||||
* @param definition $_definition
|
||||
*/
|
||||
public function import( $_stream, importexport_definition $_definition ) {
|
||||
|
||||
$this->definition = $_definition;
|
||||
|
||||
// user, is admin ?
|
||||
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
||||
|
||||
// dry run?
|
||||
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
||||
|
||||
// fetch the addressbook bo
|
||||
$this->bo= new calendar_boupdate();
|
||||
|
||||
|
||||
// Failures
|
||||
$this->errors = array();
|
||||
|
||||
@set_time_limit(0); // try switching execution time limit off
|
||||
|
||||
$calendar_ical = new calendar_ical;
|
||||
$calendar_ical->setSupportedFields('file', '');
|
||||
if (!$calendar_ical->importVCal(stream_get_contents($_stream)))
|
||||
{
|
||||
$this->errors[] = lang('Error: importing the iCal');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->results['imported'] = $calendar_ical->events_imported;
|
||||
}
|
||||
|
||||
return $calendar_ical->events_imported;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns translated name of plugin
|
||||
*
|
||||
* @return string name
|
||||
*/
|
||||
public static function get_name() {
|
||||
return lang('iCal import');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns translated (user) description of plugin
|
||||
*
|
||||
* @return string descriprion
|
||||
*/
|
||||
public static function get_description() {
|
||||
return lang("Imports events into your Calendar from an iCal File.");
|
||||
}
|
||||
|
||||
/**
|
||||
* retruns file suffix(s) plugin can handle (e.g. csv)
|
||||
*
|
||||
* @return string suffix (comma seperated)
|
||||
*/
|
||||
public static function get_filesuffix() {
|
||||
return 'ics';
|
||||
}
|
||||
|
||||
/**
|
||||
* return etemplate components for options.
|
||||
* @abstract We can't deal with etemplate objects here, as an uietemplate
|
||||
* objects itself are scipt orientated and not "dialog objects"
|
||||
*
|
||||
* @return array (
|
||||
* name => string,
|
||||
* content => array,
|
||||
* sel_options => array,
|
||||
* preserv => array,
|
||||
* )
|
||||
*/
|
||||
public function get_options_etpl() {
|
||||
// lets do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* returns etemplate name for slectors of this plugin
|
||||
*
|
||||
* @return string etemplate name
|
||||
*/
|
||||
public function get_selectors_etpl() {
|
||||
// lets do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns errors that were encountered during importing
|
||||
* Maximum of one error message per record, but you can append if you need to
|
||||
*
|
||||
* @return Array (
|
||||
* record_# => error message
|
||||
* )
|
||||
*/
|
||||
public function get_errors() {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of actions taken, and the number of records for that action.
|
||||
* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
|
||||
*
|
||||
* @return Array (
|
||||
* action => record count
|
||||
* )
|
||||
*/
|
||||
public function get_results() {
|
||||
return $this->results;
|
||||
}
|
||||
} // end of iface_export_plugin
|
||||
?>
|
Loading…
Reference in New Issue
Block a user