import works now for dropimport

This commit is contained in:
Georg Ehrke 2012-06-30 22:08:30 +02:00
parent 390f5cc89f
commit 376431fa0d
2 changed files with 36 additions and 22 deletions

View File

@ -12,15 +12,14 @@ $data = base64_decode($data);
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar'); OCP\App::checkAppEnabled('calendar');
$import = new OC_Calendar_Import($data); $import = new OC_Calendar_Import($data);
$import->setUserID(OCP\User::getUser());
$import->setTimeZone(OC_Calendar_App::$tz); $import->setTimeZone(OC_Calendar_App::$tz);
$import->disableProgressCache(); $import->disableProgressCache();
if(!$import->isValid()){ if(!$import->isValid()){
OCP\JSON::error(); OCP\JSON::error();
exit; exit;
} }
$calendarname = $import->createCalendarName(OCP\User::getUser()); $newid = OC_Calendar_Calendar::addCalendar(OCP\User::getUser(),strip_tags($import->createCalendarName()),'VEVENT,VTODO,VJOURNAL',null,0,$import->createCalendarColor());
$calendarcolor = $import->createCalendarColor();
$newid = OC_Calendar_Calendar::addCalendar(OCP\User::getUser(),strip_tags($calendarname),'VEVENT,VTODO,VJOURNAL',null,0,$calendarcolor);
$import->setCalendarID($newid); $import->setCalendarID($newid);
$import->import(); $import->import();
OCP\JSON::success(); OCP\JSON::success();

View File

@ -43,6 +43,11 @@ class OC_Calendar_Import{
* @brief var saves the timezone the events shell converted to * @brief var saves the timezone the events shell converted to
*/ */
private $tz; private $tz;
/*
* @brief var saves the userid
*/
private $userid;
/* /*
* public methods * public methods
@ -69,20 +74,21 @@ class OC_Calendar_Import{
/* /*
* @brief imports a calendar * @brief imports a calendar
* @param boolean $force force import even though calendar is not valid
* @return boolean * @return boolean
*/ */
public function import($force = false){ public function import(){
if(!$this->isValid() && !$force){ if(!$this->isValid()){
return false; return false;
} }
foreach($this->calobject->getComponents() as $object){ foreach($this->calobject->getComponents() as $object){
if(!($object instanceof Sabre_VObject_Component_VEvent) && !($object instanceof Sabre_VObject_Component_VJournal) && !($object instanceof Sabre_VObject_Component_VTodo)){ if(!($object instanceof Sabre_VObject_Component_VEvent) && !($object instanceof Sabre_VObject_Component_VJournal) && !($object instanceof Sabre_VObject_Component_VTodo)){
continue; continue;
} }
$object->DTSTART->getDateTime()->setTimezone(new DateTimeZone($this->tz));
$object->DTEND = OC_Calendar_Object::getDTEndFromVEvent($object);
$object->DTEND->getDateTime()->setTimezone(new DateTimeZone($this->tz));
$vcalendar = $this->createVCalendar($object->serialize());
OC_Calendar_Object::add($this->id, $vcalendar);
} }
return true; return true;
} }
@ -135,14 +141,13 @@ class OC_Calendar_Import{
/* /*
* @brief generates a new calendar name * @brief generates a new calendar name
* @param string $userid
* @return string * @return string
*/ */
public function createCalendarName($userid){ public function createCalendarName(){
$calendars = OC_Calendar_Calendar::allCalendars($userid); $calendars = OC_Calendar_Calendar::allCalendars($this->userid);
$calendarname = $guessedcalendarname = !is_null($this->guessCalendarName())?($this->guessCalendarName()):(OC_Calendar_App::$l10n->t('New Calendar')); $calendarname = $guessedcalendarname = !is_null($this->guessCalendarName())?($this->guessCalendarName()):(OC_Calendar_App::$l10n->t('New Calendar'));
$i = 1; $i = 1;
while(!OC_Calendar_Calendar::isCalendarNameavailable($calendarname, $userid)){ while(!OC_Calendar_Calendar::isCalendarNameavailable($calendarname, $this->userid)){
$calendarname = $guessedcalendarname . ' (' . $i . ')'; $calendarname = $guessedcalendarname . ' (' . $i . ')';
$i++; $i++;
} }
@ -153,8 +158,8 @@ class OC_Calendar_Import{
* @brief generates a new calendar color * @brief generates a new calendar color
* @return string * @return string
*/ */
public function createCalendarColor($userid){ public function createCalendarColor(){
if(is_null($this->guessCalendarColor()))){ if(is_null($this->guessCalendarColor())){
return '#9fc6e7'; return '#9fc6e7';
} }
return $this->guessCalendarColor(); return $this->guessCalendarColor();
@ -165,9 +170,19 @@ class OC_Calendar_Import{
* @param integer $id of the calendar * @param integer $id of the calendar
* @return boolean * @return boolean
*/ */
public static function setCalendarID($id){ public function setCalendarID($id){
$this->id = $id; $this->id = $id;
return true: return true;
}
/*
* @brief sets the userid to import the calendar
* @param string $id of the user
* @return boolean
*/
public function setUserID($userid){
$this->userid = $userid;
return true;
} }
/* /*
@ -207,12 +222,12 @@ class OC_Calendar_Import{
} }
/* /*
* @brief * @brief checks if an event already exists in the user's calendars
* @return * @return boolean
*/ */
//private function (){ private function isDuplicate(){
//} }
/* /*
* @brief * @brief
@ -223,7 +238,7 @@ class OC_Calendar_Import{
//} //}
/* /*
* private methods for prerendering of X-... Attributes * private methods for (pre)rendering of X-... Attributes
*/ */
/* /*