Secure shared Google Calendar

我的未来我决定 提交于 2019-12-06 05:29:27

Okay after lots of searching, I have decided to implement my own solution seeings as I couldn't find one out there that matched my needs.

I have decided to use the FullCalendar Plugin. It does have a gCal function, where it will get the data from a calendar feed, but the calendar needs to be public to use this function. So I created my own.

On the page view (calendar.phtml):

    <?php if ($this->worker == "office"): ?>
        <div id='calendar'></div>
    <?php else: ?>
        <iframe src="https://www.google.com/calendar/embed?showTitle=0&amp;showCalendars=0&amp;showTz=0&amp;height=600&amp;wkst=2&amp;hl=en_GB&amp;bgcolor=%23FFFFFF&amp;src=YOU-CALENDAR-LINK&amp;color=%2329527A&amp;ctz=Europe%2FLondon&pvttk=YOUR-PRIVATE-KEY" 
            style="border-width:0;" 
            width="580" 
            height="600" 
            frameborder="0" 
            scrolling="no"></iframe>
    <?php endif; ?>

In the calendarAction method:

    $this->view->jQuery()->addStyleSheet($this->view->baseUrl('css/JQuery/fullcalendar.css'));
    $this->view->jQuery()->addJavascriptFile($this->view->baseUrl('js/fullcalendar.js'));  
    $this->view->jQuery()->addJavascriptFile($this->view->baseUrl('js/myCal.js'));  

In my Calendar Controler I added a function to return a json array (CalendarControler.php):

    $startDate = $this->_getParam('start');
    $startDate = date("Y-m-d", $startDate);
    $endDate = $this->_getParam('end');
    $endDate = date("Y-m-d", $endDate);
    // Remove the view & layout
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    // Query Google GData for the calendar
    $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $source = "YOU-APP-NAME";
    $user = "USERNAME";
    $pass = "PASSWORD";
    $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service,null,$source);
    $cal = new Zend_Gdata_Calendar($client);
    $events = array();
    $query = $cal->newEventQuery();
    $query->setUser('default');
    $query->setVisibility('private');
    $query->setStartMin($startDate);
    $query->setStartMax($endDate);
    $eventFeed = $cal->getCalendarEventFeed($query);
    // Loop through the returned events:
    foreach ($eventFeed as $event) 
    {
        $temp['id'] = $event->id->text;
        $temp['title'] = $event->title->text;
        $temp['allDay'] = false;
        foreach ($event->when as $when) 
        {
            $temp['start'] = date("D M j Y H:i:s eO", strtotime($when->startTime));
            $temp['end'] = date("D M j Y H:i:s eO", strtotime($when->endTime));
        }
        array_push($events, $temp);
    }
    echo json_encode($events);

Finally the unfinished JS class (myCal.js) - It is unfinished as I will be hooking onto the editable and adding actions of fullcalendar and using some ajax calls to create a dialog and add new events, edit events and delete events - otherwise this would basically be a private embeded google calendar (like what is shown to the workers):

    $j("#calendar").fullCalendar({    
        editable: false,            
        header: {
            left: "prev,next today",
            center: "title",
            right: "month,basicWeek,agendaDay"},
        events: "calendar/events"});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!