0

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

            }
            }
stawek
  • 257
  • 2
  • 5
  • 13

2 Answers2

5

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();
TechyGypo
  • 824
  • 1
  • 11
  • 27
0

Your variable $events will be an instance of Zend_Gdata_Calendar_EventEntry, which inherits Zend_Gdata_Kind_EventEntry which has the function getWhen.

ie:

$when = $evt->getWhen();

http://framework.zend.com/manual/en/zend.gdata.calendar.html

Ashley
  • 5,939
  • 9
  • 39
  • 82
  • Unfortunately it's what I'm doing now and seems that it doesn't work - see my sample testcode. – stawek Apr 16 '12 at 10:48