好的,经过大量搜索,我决定实施自己的解决方案,因为我找不到符合我需求的解决方案。
我决定使用FullCalendar 插件。它确实有一个 gCal 功能,它将从日历提要中获取数据,但日历需要公开才能使用此功能。所以我创建了我自己的。
在页面视图 (calendar.phtml) 上:
<?php if ($this->worker == "office"): ?>
<div id='calendar'></div>
<?php else: ?>
<iframe src="https://www.google.com/calendar/embed?showTitle=0&showCalendars=0&showTz=0&height=600&wkst=2&hl=en_GB&bgcolor=%23FFFFFF&src=YOU-CALENDAR-LINK&color=%2329527A&ctz=Europe%2FLondon&pvttk=YOUR-PRIVATE-KEY"
style="border-width:0;"
width="580"
height="600"
frameborder="0"
scrolling="no"></iframe>
<?php endif; ?>
在 calendarAction 方法中:
$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'));
在我的日历控制器中,我添加了一个函数来返回一个 json 数组(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);
最后是未完成的 JS 类 (myCal.js) - 它未完成,因为我将连接到可编辑和添加 fullcalendar 的操作,并使用一些 ajax 调用来创建对话框并添加新事件、编辑事件和删除事件 - 否则这会基本上是一个私人嵌入的谷歌日历(就像向工人展示的那样):
$j("#calendar").fullCalendar({
editable: false,
header: {
left: "prev,next today",
center: "title",
right: "month,basicWeek,agendaDay"},
events: "calendar/events"});