This is an old revision of the document!


Custom Google Calendar Sync

To setup the Vtiger Google Calendar sync with another calendar than the default one, you could apply this modifications.

At first install latest version of my Vtiger Tools. This is absolutely necessary, because I use this module to implement to management logic.

You need to press the “initialize” button on the management view of Vtiger Tools in the section “Google Calendar”

1. File: /modules/Google/connectors/Calendar.php

$query = $calendars->newEventQuery($query);

Insert after

        /* modified by swarnat - mod61.01 */
        if($this->calendarId !== null) {
            $query->setUser($this->calendarId);
        }
        /* modified by swarnat - mod61.01 */

1.2 Search

$createdEntry = $gContact->insertEvent($entity);

Replace this line with

                    /* modified by swarnat - mod61.01 */
                    try {
                        if($this->calendarId !== null) {
                            $createdEntry = $gContact->insertEvent($entity, "http://www.google.com/calendar/feeds/".$this->calendarId."/private/full");
                        } else {
                            $createdEntry = $gContact->insertEvent($entity);
                        }
                    } catch (Exception $e) {
                        var_dump($e->getMessage());
                    }
                    /* modified by swarnat - mod61.01 */

1.3 Search (The end of this file)

}
?>

Insert before

    /* modified by swarnat - mod61.01 */
    public function getCalendarList() {
        $gdata = new Zend_Gdata_Calendar($this->apiInstance);
        $calendarList = $gdata->getCalendarListFeed();
        $calendars = array();
        foreach ($calendarList as $calendar) {
            $calendars[] = array('title' => (string)$calendar->title, 'id' => (string)$calendar->id);
        }
        return $calendars;
    }
    protected $calendarId = null;
    public function setCalendarId($calendarId) {
        $this->calendarId = $calendarId;
    }
    /* modified by swarnat - mod61.01 */

2. File: /modules/Google/controllers/Calendar.php

2.1 Search

    public function getSourceType() {
        return 'Events';
    }

Insert after

    /* modified by swarnat - mod61.01 */
    public function getCalendarId() {
        $adb = \PearDatabase::getInstance();
        $sql = 'SELECT calendar_id FROM vtiger_gcal_sync WHERE user_id = ?';
        $result = $adb->pquery($sql, array($this->user->id));
        if($adb->num_rows($result) == 0) {
            return null;
        }
 
        return $adb->query_result($result, 0, 'calendar_id');
    }
 
    public function getCalendarList() {
        return $this->targetConnector->getCalendarList();
    }
    public function setCalendarId($calendarId) {
        $this->targetConnector->setCalendarId($calendarId);
    }
    /* modified by swarnat - mod61.01 */

3. File: /modules/Google/models/Module.php

3.1 Search

$db->pquery($query, array($module, $id));

Insert after

        /* modified by swarnat - mod61.01 */
        $query = "DELETE FROM vtiger_gcal_sync WHERE user_id = ?";
        $db->pquery($query, array($id));
        /* modified by swarnat - mod61.01 */

4. File: /modules/Google/views/List.php

4.1 Search

$controller = new Google_Calendar_Controller($user);

Insert After

        /* modified by swarnat - mod61.01 */
        $calId = $controller->getCalendarId();
        if(empty($calId)) {
            $list = $controller->getCalendarList();
            $this->viewer->assign('calendars', $list);
            $this->viewer->view('GCalChooser.tpl', 'SwVtTools');
 
            return;
        }
        $controller->setCalendarId($calId);
        /* modified by swarnat - mod61.01 */