move egw_ical_iterator to Api\CalDAV\IcalIterator

This commit is contained in:
Ralf Becker 2016-04-04 23:45:39 +00:00
parent ca1bf71361
commit fc9c345930
3 changed files with 26 additions and 21 deletions

View File

@ -10,6 +10,7 @@
* @version $Id$
*/
use EGroupware\Api;
/**
* Plugin to import vCard files
@ -17,7 +18,7 @@
class addressbook_import_vcard implements importexport_iface_import_plugin {
private static $plugin_options = array(
'contact_owner'
);
@ -124,7 +125,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
// Fix for Apple Addressbook
$vCard = preg_replace('/item\d\.(ADR|TEL|EMAIL|URL)/', '\1', stream_get_contents($_stream));
$contacts = new egw_ical_iterator($vCard, '', $charset, array($this, '_vcard'),array(
$contacts = new Api\CalDAV\IcalIterator($vCard, '', $charset, array($this, '_vcard'),array(
// Owner (addressbook)
$contact_owner
));
@ -147,7 +148,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
$count++;
$contacts->next();
}
return $count;
}
@ -166,8 +167,8 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
if(!array_key_exists($record['owner'], $this->bocontacts->get_addressbooks()))
{
$this->errors[$this->current] = lang("Unable to import into %1, using %2",
common::grab_owner_name($record['owner']),
common::grab_owner_name($this->user)
Api\Accounts::username($record['owner']),
Api\Accounts::username($this->user)
);
$record['owner'] = $this->user;
}
@ -220,7 +221,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
} else {
//error_log(__METHOD__.__LINE__.array2string($changed).' Old:'.$old['adr_one_countryname'].' ('.$old['adr_one_countrycode'].') New:'.$_data['adr_one_countryname'].' ('.$_data['adr_one_countryname'].')');
}
// Make sure n_fn gets updated
unset($_data['n_fn']);
@ -249,8 +250,8 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
return $result;
}
default:
throw new egw_exception('Unsupported action: '. $_action);
throw new Api\Exception('Unsupported action: '. $_action);
}
}
@ -289,7 +290,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
$row += $record;
$rows[] = $row;
}
return html::table($rows);
return Api\Html::table($rows);
}
/**
@ -380,4 +381,3 @@ class addressbook_import_vcard implements importexport_iface_import_plugin {
return $this->results;
}
} // end of iface_export_plugin
?>

View File

@ -5,12 +5,17 @@
* @link http://www.egroupware.org
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package api
* @subpackage groupdav
* @subpackage caldav
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2010-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright (c) 2010-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @version $Id$
*/
namespace EGroupware\Api\CalDAV;
use EGroupware\Api;
use Horde_Icalendar;
// required for tests at the end of this file (run if file called directly)
if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__)
{
@ -20,7 +25,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_
'nonavbar' => 'true',
),
);
include('../../header.inc.php');
include('../../../header.inc.php');
}
/**
@ -28,7 +33,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_
*
* try {
* $ical_file = fopen($path,'r');
* $ical_it = new egw_ical_iterator($ical_file,'VCALENDAR');
* $ical_it = new Api\CalDAV\IcalIterator($ical_file,'VCALENDAR');
* }
* catch (Exception $e)
* {
@ -40,7 +45,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_
* }
* fclose($ical_file)
*/
class egw_ical_iterator extends Horde_Icalendar implements Iterator
class IcalIterator extends Horde_Icalendar implements \Iterator
{
/**
* File we work on
@ -124,7 +129,7 @@ class egw_ical_iterator extends Horde_Icalendar implements Iterator
}
if (!is_resource($this->ical_file))
{
throw new egw_exception_wrong_parameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file),0,100));
throw new Api\Exception\WrongParameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file),0,100));
}
}
@ -425,12 +430,12 @@ X-MS-OLK-CONFTYPE:0
END:VEVENT
END:VCALENDAR
';
common::egw_header();
$GLOBALS['egw']->framework->header();
//$ical_file = fopen('/tmp/KalenderFelicitasKubala.ics');
if (!is_resource($ical_file)) echo "<pre>$ical_file</pre>\n";
//$calendar_ical = new calendar_ical();
//$calendar_ical->setSupportedFields('file');
$ical_it = new egw_ical_iterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
$ical_it = new IcalIterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
foreach($ical_it as $uid => $vevent)
{
echo "$uid<pre>".print_r($vevent->toHash(), true)."</pre>\n";

View File

@ -2249,10 +2249,10 @@ class calendar_ical extends calendar_boupdate
if (!is_array($this->supportedFields)) $this->setSupportedFields();
// we use egw_ical_iterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
// we use Api\CalDAV\IcalIterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
if (is_resource($_vcalData))
{
return new egw_ical_iterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($this->tzid,$principalURL));
return new Api\CalDAV\IcalIterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($this->tzid,$principalURL));
}
if ($this->tzid)
@ -2317,7 +2317,7 @@ class calendar_ical extends calendar_boupdate
}
/**
* Callback for egw_ical_iterator to convert Horde_iCalendar_Vevent to EGw event array
* Callback for Api\CalDAV\IcalIterator to convert Horde_iCalendar_Vevent to EGw event array
*
* @param Horde_iCalendar $component
* @param string $tzid timezone