create OC_Calendar_Object::generateStartEndDate function

This commit is contained in:
Georg Ehrke 2012-06-15 12:11:22 +02:00
parent 4767c70578
commit aa7ce480f4
3 changed files with 22 additions and 44 deletions

View File

@ -400,36 +400,10 @@ class OC_Calendar_App{
}else{
$object->expand($start, $end);
foreach($object->getComponents() as $vevent){
if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){
if(!($vevent instanceof Sabre_VObject_Component_VEvent)){
continue;
}
$dynamicoutput = array();
$dtstart = $vevent->DTSTART;
$start_dt = $dtstart->getDateTime();
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
$end_dt = $dtend->getDateTime();
if($allday){
$dynamicoutput['start'] = $start_dt->format('Y-m-d');
$end_dt->modify('-1 sec');
$dynamicoutput['end'] = $end_dt->format('Y-m-d');
}else{
$start_dt->setTimezone(new DateTimeZone(self::$tz));
$end_dt->setTimezone(new DateTimeZone(self::$tz));
$dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s');
$dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s');
}
// Handle exceptions to recurring events
/*$exceptionDateObjects = $vevent->select('EXDATE');
$exceptionDateMap = Array();
foreach ($exceptionDateObjects as $exceptionObject) {
foreach($exceptionObject->getDateTimes() as $datetime) {
$ts = $datetime->getTimestamp();
$exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true;
}
}*/
$dynamicoutput = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), self::$tz);
$return[] = array_merge($staticoutput, $dynamicoutput);
}
}

View File

@ -807,4 +807,21 @@ class OC_Calendar_Object{
$event = self::find($id);
return ($event['repeating'] == 1)?true:false;
}
public static function generateStartEndDate($dtstart, $dtend, $tz){
$start_dt = $dtstart->getDateTime();
$end_dt = $dtend->getDateTime();
$return = array();
if($allday){
$return['start'] = $start_dt->format('Y-m-d');
$end_dt->modify('-1 hour');
$return['end'] = $end_dt->format('Y-m-d');
}else{
$start_dt->setTimezone(new DateTimeZone($tz));
$end_dt->setTimezone(new DateTimeZone($tz));
$return['start'] = $start_dt->format('Y-m-d H:i:s');
$return['end'] = $end_dt->format('Y-m-d H:i:s');
}
return $return;
}
}

View File

@ -95,25 +95,12 @@ class OC_Calendar_Repeat{
$end->modify('+5 years');
$object->expand($start, $end);
foreach($object->getComponents() as $vevent){
if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){
if(!($vevent instanceof Sabre_VObject_Component_VEvent)){
continue;
}
$dtstart = $vevent->DTSTART;
$start_dt = $dtstart->getDateTime();
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
$end_dt = $dtend->getDateTime();
if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
$startdate = $start_dt->format('Y-m-d');
$end_dt->modify('-1 sec');
$enddate = $end_dt->format('Y-m-d');
}else{
$start_dt->setTimezone(new DateTimeZone('UTC'));
$end_dt->setTimezone(new DateTimeZone('UTC'));
$startdate = $start_dt->format('Y-m-d H:i:s');
$enddate = $end_dt->format('Y-m-d H:i:s');
}
$startenddate = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), 'UTC');
$stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)');
$stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startdate,$enddate));
$stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startenddate['start'],$startenddate['end']));
}
return true;
}