protected function generateFreeBusyCalendar(FreeBusyData $fbData)
    {
        if ($this->baseObject) {
            $calendar = $this->baseObject;
        } else {
            $calendar = new VCalendar();
        }

        $vfreebusy = $calendar->createComponent('VFREEBUSY');
        $calendar->add($vfreebusy);

        if ($this->start) {
            $dtstart = $calendar->createProperty('DTSTART');
            $dtstart->setDateTime($this->start);
            $vfreebusy->add($dtstart);
        }
        if ($this->end) {
            $dtend = $calendar->createProperty('DTEND');
            $dtend->setDateTime($this->end);
            $vfreebusy->add($dtend);
        }

        $tz = new \DateTimeZone('UTC');
        $dtstamp = $calendar->createProperty('DTSTAMP');
        $dtstamp->setDateTime(new DateTimeImmutable('now', $tz));
        $vfreebusy->add($dtstamp);

        foreach ($fbData->getData() as $busyTime) {
            $busyType = strtoupper($busyTime['type']);

            // Ignoring all the FREE parts, because those are already assumed.
            if ('FREE' === $busyType) {
                continue;
            }

            $busyTime[0] = new \DateTimeImmutable('@'.$busyTime['start'], $tz);
            $busyTime[1] = new \DateTimeImmutable('@'.$busyTime['end'], $tz);

            $prop = $calendar->createProperty(
                'FREEBUSY',
                $busyTime[0]->format('Ymd\\THis\\Z').'/'.$busyTime[1]->format('Ymd\\THis\\Z')
            );

            // Only setting FBTYPE if it's not BUSY, because BUSY is the
            // default anyway.
            if ('BUSY' !== $busyType) {
                $prop['FBTYPE'] = $busyType;
            }
            $vfreebusy->add($prop);
        }

        return $calendar;
    }
protected function generateFreeBusyCalendar(FreeBusyData $fbData)
    {
        if ($this->baseObject) {
            $calendar = $this->baseObject;
        } else {
            $calendar = new VCalendar();
        }

        $vfreebusy = $calendar->createComponent('VFREEBUSY');
        $calendar->add($vfreebusy);

        if ($this->start) {
            $dtstart = $calendar->createProperty('DTSTART');
            $dtstart->setDateTime($this->start);
            $vfreebusy->add($dtstart);
        }
        if ($this->end) {
            $dtend = $calendar->createProperty('DTEND');
            $dtend->setDateTime($this->end);
            $vfreebusy->add($dtend);
        }

        $tz = new \DateTimeZone('UTC');
        $dtstamp = $calendar->createProperty('DTSTAMP');
        $dtstamp->setDateTime(new DateTimeImmutable('now', $tz));
        $vfreebusy->add($dtstamp);

        foreach ($fbData->getData() as $busyTime) {
            $busyType = strtoupper($busyTime['type']);

            // Ignoring all the FREE parts, because those are already assumed.
            if ('FREE' === $busyType) {
                continue;
            }

            $busyTime[0] = new \DateTimeImmutable('@'.$busyTime['start'], $tz);
            $busyTime[1] = new \DateTimeImmutable('@'.$busyTime['end'], $tz);

            $prop = $calendar->createProperty(
                'FREEBUSY',
                $busyTime[0]->format('Ymd\\THis\\Z').'/'.$busyTime[1]->format('Ymd\\THis\\Z')
            );

            // Only setting FBTYPE if it's not BUSY, because BUSY is the
            // default anyway.
            if ('BUSY' !== $busyType) {
                $prop['FBTYPE'] = $busyType;
            }
            $vfreebusy->add($prop);
        }

        return $calendar;
    }
protected function generateFreeBusyCalendar ( FreeBusyData $ fbData ) { if ( $ this -> baseObject ) { $ calendar = $ this -> baseObject ; } else { $ calendar = new VCalendar ( ) ; } $ vfreebusy = $ calendar -> createComponent ( 'VFREEBUSY' ) ; $ calendar -> add ( $ vfreebusy ) ; if ( $ this -> start ) { $ dtstart = $ calendar -> createProperty ( 'DTSTART' ) ; $ dtstart -> setDateTime ( $ this -> start ) ; $ vfreebusy -> add ( $ dtstart ) ; } if ( $ this -> end ) { $ dtend = $ calendar -> createProperty ( 'DTEND' ) ; $ dtend -> setDateTime ( $ this -> end ) ; $ vfreebusy -> add ( $ dtend ) ; } $ tz = new \ DateTimeZone ( 'UTC' ) ; $ dtstamp = $ calendar -> createProperty ( 'DTSTAMP' ) ; $ dtstamp -> setDateTime ( new DateTimeImmutable ( 'now' , $ tz ) ) ; $ vfreebusy -> add ( $ dtstamp ) ; foreach ( $ fbData -> getData ( ) as $ busyTime ) { $ busyType = strtoupper ( $ busyTime [ 'type' ] ) ; // Ignoring all the FREE parts, because those are already assumed. if ( 'FREE' === $ busyType ) { continue ; } $ busyTime [ 0 ] = new \ DateTimeImmutable ( '@' . $ busyTime [ 'start' ] , $ tz ) ; $ busyTime [ 1 ] = new \ DateTimeImmutable ( '@' . $ busyTime [ 'end' ] , $ tz ) ; $ prop = $ calendar -> createProperty ( 'FREEBUSY' , $ busyTime [ 0 ] -> format ( 'Ymd\\THis\\Z' ) . '/' . $ busyTime [ 1 ] -> format ( 'Ymd\\THis\\Z' ) ) ; // Only setting FBTYPE if it's not BUSY, because BUSY is the // default anyway. if ( 'BUSY' !== $ busyType ) { $ prop [ 'FBTYPE' ] = $ busyType ; } $ vfreebusy -> add ( $ prop ) ; } return $ calendar ; }
This method takes a FreeBusyData object and generates the VCALENDAR
object associated with it.

@return VCalendar
This method takes a FreeBusyData object and generates the VCALENDAR object associated with it .