/**
* Merges the busy periods of another Horde_Icalendar_Vfreebusy object
* into this one.
*
* This might lead to simplification no matter what you specify for the
* "simplify" flag since periods with the same start date will lead to the
* shorter period being removed (see addBusyPeriod).
*
* @param Horde_Icalendar_Vfreebusy $freebusy A freebusy object.
* @param boolean $simplify If true, simplify() will
* called after the merge.
*/
public function merge(Horde_Icalendar_Vfreebusy $freebusy, $simplify = true)
{
$extra = $freebusy->getExtraParams();
foreach ($freebusy->getBusyPeriods() as $start => $end) {
// This might simplify the busy periods without taking the
// "simplify" flag into account.
$this->addBusyPeriod('BUSY', $start, $end, null, isset($extra[$start]) ? $extra[$start] : array());
}
foreach (array('DTSTART', 'DTEND') as $val) {
try {
$thisattr = $this->getAttribute($val);
} catch (Horde_Icalendar_Exception $e) {
$thisattr = null;
}
try {
$thatattr = $freebusy->getAttribute($val);
} catch (Horde_Icalendar_Exception $e) {
$thatattr = null;
}
if (is_null($thisattr) && !is_null($thatattr)) {
$this->setAttribute($val, $thatattr, array(), false);
} elseif (!is_null($thatattr)) {
switch ($val) {
case 'DTSTART':
$set = $thatattr < $thisattr;
break;
case 'DTEND':
$set = $thatattr > $thisattr;
break;
}
if ($set) {
$this->setAttribute($val, $thatattr, array(), false);
}
}
}
if ($simplify) {
$this->simplify();
}
return true;
}