I am working on a small scale website. It has a very simple idea, there are two sets of users, office and workers, both have to login to acess the site (the site is built with the Zend framework).
The problem: I want to have a calendar which is accessible by all the users. The office staff being able to edit the calendar and the workers only being able to view the calendar.
I really want to user google as the backend for the calendar due to its flexibility: A couple of the office workers work on the road (all have android phones) so the calendar can be shared with those users and they can use their mobile devices to update the calendar.
The problem I've got is sharing the calendar with the workers. I wanted to embed the viewable calendar inside a secured page - but obviously the user would have to be logged in as a google user to view the calendar (it couldn't be public). I had hoped I could use the Zend_Gdata_Calendar but there doesn't appear to be an easy way to get the calendar view. Is there any way to do this? Would it be possible to get the website to auth with google and get an embeded calendar?
The other side is I want office users to be able to add to the calendar - which is easy enough through the Zend_Gdata_Calendar - maybe not as neat as I had hoped for.
The other option I was thinking was using Zend_Gdata_Calendar and a jQuery Calendar possibly, then allowing different users to do the different tasks.
Is there any good tutorials out there that could help in this situation?
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&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; ?>
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"});
来源:https://stackoverflow.com/questions/4278208/secure-shared-google-calendar