如何使用CalDAV将新记录添加到日历中? 我可以通过该代码将Thunderbird Lightning日历中的所有当前记录作为数组:
require_once 'class.CalDavClient.php';
$cal = new CalDAVClient(
'###',
'###',
'###'
);
if ( isset($options["PROPFIND"]) ) {
$cal->SetDepth(1);
$folder_xml = $cal->DoXMLRequest(
"PROPFIND",
'<?xml version="1.0" encoding="utf-8" ?>
<propfind xmlns="DAV:"><prop><getcontentlength/><getcontenttype/>
<resourcetype/><getetag/></prop></propfind>'
);
}
$date_from = date('Ymd', mktime(0, 0, 0, date('m')-3, date('d'), date('Y')));
$calendar_events = CalDAVClient::normalize_events($cal->GetEvents($date_from,
"20991212"), $row['calendar_Title']);
print_r($calendar_events);
但我如何添加新活动?我查找了文档,但无法找到相关内容。
答案 0 :(得分:1)
要创建新事件,请使用HTTP PUT操作,iCalendar实体代表新事件。
答案 1 :(得分:0)
感谢 hnh 链接我为我找到了一个解决方案,我在CalDavCliet类中创建了为请求生成数据的方法
public function create_event($title, $desc, $tstart, $tend) {
$event_id = $this->generate_eventID();
$tstamp = gmdate("Ymd\THis\Z");
$xml = "BEGIN:VCALENDAR\n".
"VERSION:2.0\n".
"BEGIN:VEVENT\n".
"DTSTAMP:$tstamp\n".
"DTSTART:$tstart\n".
"DTEND:$tend\n".
"UID:$event_id\n".
"DESCRIPTION:$desc\n".
"LOCATION:Office\n".
"SUMMARY:$title\n".
"END:VEVENT\n".
"END:VCALENDAR";
$etag = $this->DoPUTRequest($this->base_url . $event_id . '.ics', $xml);
return $etag;
}
现在我可以使用该方法添加新记录
$etag = $cal->create_event('тест1', 'описание...', '20141220T173000Z', '20141220T180000Z');
if (!empty($etag)) {
echo "Событие успешно добавлено !";
}
我怎么理解,没有办法为新记录自动生成eID,所以我编写并使用该方法生成“简单”的eID,就像它制作Thunderbird客户端
protected function generate_eventID() {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$eventID = '';
for ($i = 0; $i < 8; $i++) {$eventID .= $characters[rand(0, $charactersLength - 1)];}
for ($i = 0; $i < 3; $i++) {
$eventID .= '-';
for ($j = 0; $j < 4; $j++) {$eventID .= $characters[rand(0, $charactersLength - 1)];}
}
$eventID .= '-';
for ($i = 0; $i < 12; $i++) {$eventID .= $characters[rand(0, $charactersLength - 1)];}
return $eventID;
}