Search code examples
phpzend-frameworkcalendargdata

How to get Google Calendar event startime using Zend_Gdata?


Currently I'm working on project where I need to access Google Calenadar data using API - everything works fine but I'm unable to get event start time/end time - most important informations.

I'm using Zend framework and Zend_Gdata library , unfortunately zend's documentation isn't detailed

How to get needed event data? Or maybe should I use another library?

Here is my function for getting event feed:

public function getEvents($future_only = TRUE,$force_refresh = FALSE) {

    if (($this->events != NULL) && $force_refresh == FALSE) {
        return $this->events;
    } else {
        if ($this->getService() != NULL) {
            $service = $this->getService();
            try {

                $query = $service->newEventQuery($this->url);
                $query->setUser(null);
                $query->setProjection(null);
                $query->setVisibility(null);
                $query->setOrderby('starttime');
                if ($future_only) {
                    $query->setFutureevents('true');
                } else {
                    $query->setFutureevents('false');
                }

                $event_feed = $service->getCalendarEventFeed($query);

                $this->events = $event_feed;

                return $event_feed;
            } catch (Exception $exc) {
                .
                .
                .
                return NULL;
            }
        } else {
            return NULL;
               }
           }
        }

And sample test code where I'm trying to obtain event informations:

       $gcalendar = new  Common_Model_GoogleCalendar();

             $events = $gcalendar->getEvents();

            if($events){

            foreach ($events as $evt) {
                echo $evt->title.'<br />';
                echo $evt->id.'<br />';
                echo $evt->published.'<br />';
                Zend_Debug::dump($evt->getWhen());       //returns empty array

            }
            }

Solution

  • Not sure if you have sorted this by now, but in addition to @Ashley's contribution, this is how to get getWhen() to work:

    $when = $evt->getWhen();
    echo $when[0]->getStartTime();
    echo $when[0]->getEndTime();