views:

30

answers:

1

I'm trying to create a PHP function that adds an event to a google Calendar. It appears to be building the object correctly but it throws a "Call to a member function getDOM() on a non-object in FeedEntryParent.php" error when trying to add the event. Here is the abbreviated class with only the constructor and the function that adds the event:

class GCal_datasource {
    private $user = 'xxxxxxx';
    private $pass = 'xxxxxxxxx';
    private $client;
    private $gdata_cal;

    private $calendar; 
    private $visibility;

        public function __construct($settings = NULL){
        session_start();        
        require_once 'Zend/Loader.php';     
        Zend_Loader::loadClass('Zend_Gdata');
        Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
        Zend_Loader::loadClass('Zend_Gdata_HttpClient');
        Zend_Loader::loadClass('Zend_Gdata_Calendar');

        if($settings == NULL){
            $settings = array();
            $settings['calendar'] = 'default';
            $settings['visibility'] = 'full';
        }       

        $this->calendar = $settings['calendar']; 
        $this->visibility = $settings['visibility'];    
        $this->client = $this->get_ClientLoginHttpClient();
        $this->gdata_cal = new Zend_Gdata_Calendar($this->client);      
    }

    public function create_event($fields){
        $gc = $this->gdata_cal;
        $new_event = $this->gdata_cal->newEventEntry();
        echo '<pre>';
        print_r($fields);
        echo '</pre>';

        if(isset($fields['quick_add'])){ 
            $new_event->content = $gc->newContent($fields['quick_add']);
            $new_event->quickAdd = $gc->newQuickAdd(true);
        } else if (isset($fields['title']) && isset($fields['when'])) { 
            $new_event->title = $fields['title'];
            $where = $gc->newWhere($fields['where']);
            $new_event->where = array($where);
            $desc = $gc->newContent($fields['desc']);
            $new_event->content = $desc;
            $new_event->content->type = 'text';
            $new_event->when = self::build_when_array($fields['when']);
            if(isset($fields['web_content'])){
                $new_event->link = web_event_array($fields['web_content']);
            }   
        }

        echo '<pre>';
        print_r($new_event);
        echo '</pre>';

        $gc->insertEvent($new_event);
        return $created_event->id->text;
    }
}

The error (I believe) is how I am calling insertEvent() towards the end of the code. The only reason I think that is I only get the error when it exists and if I remove it the echo above it prints out the Event object as intended.

Anyone with a better grasp of the Goggle PHP API that can lend me a hand I would greatly appreciate.

+1  A: 

Call to a member function getDOM() on a non-object in FeedEntryParent.php means that somewhere in the file named "FeedEntryParent.php" you have called getDOM() on a variable and that variable is not an object and so does not have a getDOM() method.

Nowhere in the code you posted is a call to getDOM(), so the error is not generated in the posted code.

Track down that call to getDOM(). The error usually gives you a line number. See what variable you are calling the method on. That variable is not an object. Find where that variable is set - that's probably where your problem is.

Scott Saunders