我正在开发一个网站,以使用此博客文章中的代码将事件添加到 Google 日历。
现在我想为每个在活动前 15 分钟设置的活动设置提醒。
谁能给我一些关于如何实现这一目标的指导?
创建事件时设置提醒非常容易。<gd:when></gd:when>
您只需在标签中添加几行。
<gd:when startTime='2006-03-30T22:00:00.000Z' endTime='2006-03-30T23:00:00.000Z'>
<gd:reminder minutes='15' method='email' />
<gd:reminder minutes='15' method='alert' />
</gd:when>
这是一个更新的addEvent()
方法,包括对提醒的支持:
public function addEvent($params) {
$url = "http://www.google.com/calendar/feeds/{$this->getFeedEmail()}/private/full";
//startTime should be a time() value so we can convert it into the correct format
$params["startTime"] = date("c", $params["startTime"]);
//If no end-time is specified, set the end-time to 1 hour after the start-time
if(!array_key_exists("endTime", $params)) {
$params["endTime"] = date("c", strtotime($params["startTime"])+60*60*1);
}
$reminders = '';
if(is_array($params['reminders'])) {
foreach($params['reminders'] as $rem) {
$reminders .= "<gd:reminder minutes='{$rem['minutes']}' method='{$rem['method']}' />"\n;
}
}
$xml = "<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"></category>
<title type="text">{$params["title"]}</title>
<content type="text">{$params["content"]}</content>
<gd:transparency value="http://schemas.google.com/g/2005#event.opaque">
</gd:transparency>
<gd:eventstatus value="http://schemas.google.com/g/2005#event.confirmed">
</gd:eventstatus>
<gd:where valuestring="{$params["where"]}"></gd:where>
<gd:when starttime="{$params["startTime"]}" endtime="{$params["endTime"]}">
{$reminders}
</gd:when>
</entry>";
//Do the initial POST to Google
$ret = $this->calPostRequest($url, $xml);
//If Google sends back a gsessionid, we need to make the request again
$matches = array();
if(preg_match('/gsessionid=(.*?)\s+/', $ret, $matches)) {
$url .= "?gsessionid={$matches[1]}";
$ret = $this->calPostRequest($url, $xml);
}
//Parse the XML response (which contains the newly added entry)
$retFields = explode("\n", $ret);
//print_r($retFields);
$entryXML = simplexml_load_string($retFields[count($retFields)-1]);
//Return an array containing the entry id (url) and the etag
return array(
"id"=> (string)$entryXML->id,
"etag"=> $this->getETagFromHeader($retFields),
"link"=> $this->getEditLinkFromHeader($retFields)
);
}
你会这样称呼它:
$entryData = $cal->addEvent(array(
"title"=> "Auto Test event",
"content"=> "This is a test event",
"where"=> "Test location",
"startTime"=> time()+60*60*24*1,
"reminders"=> array(
array("method"=>"email", "minutes"=>"15"),
array("method"=>"alert", "minutes"=>"15"),
)
));