piCal用Googleカレンダープラグインの実験(3)
大型連休の休みボケがようやく抜けてきたgusagiです。
かなり間が空いてしまいましたが、前回の記事の続きです。
前回のコードで、"example@example.com"というアカウントに共有されているカレンダーのリストを取得しましたので、リストの分だけ処理を繰り返して、カレンダーごとのイベントを取得します。
foreach ( $users as $user ) {
$zfQuery = $zfService->newEventQuery();
$zfQuery->setUser( $user );
$zfQuery->setVisibility('private');
$zfQuery->setProjection('full');
$zfQuery->setOrderby('starttime');
$zfQuery->setStartMin($startMin);
$zfQuery->setStartMax($startMax);
$zfQuery->setRecurrenceExpansionStart($startMin);
$zfQuery->setRecurrenceExpansionEnd($startMax);
$eventFeed = array();
$message = '';
$body = '';
try {
$eventFeed = $zfService->getCalendarEventFeed($zfQuery);
} catch (Zend_Gdata_App_Exception $e) {
$message = $e->getMessage();
$message = mb_convert_encoding( $message, mb_internal_encoding(), 'utf-8' );
echo 'error : ' . $message . "<br />";
$response = $e->getResponse();
if ( isset($response) && is_object($response) ) {
$body = $response->getBody();
$body = mb_convert_encoding( $body, mb_internal_encoding(), 'utf-8' );
echo $body . "<br />";
}
}
カレンダー毎に、一回目の記事で取得した取得期間をセットして、イベントフィードを取得します。
フィードの取得に失敗した場合は、エラーメッセージを取得した上で、この場合はUTF-8に変換してechoしています。
foreach ( $eventFeed as $event ) {
$who =& $event->who[0];
$when =& $event->when[0];
$startTime = $when->getStartTime();
$startTimeArray = sscanf( $startTime, '%d-%d-%dT%d:%d:%d' );
$startDay = intval( $startTimeArray[2] );
$startTime = sprintf( '%02d', $startTimeArray[3] ) . _PICAL_MB_HOUR_SUF .
sprintf( '%02d', $startTimeArray[4] ) . _PICAL_MB_MINUTE_SUF;
$endTime = $when->getEndTime();
$endTimeArray = sscanf( $endTime, '%d-%d-%dT%d:%d:%d' );
$endTime = sprintf( '%02d', $endTimeArray[3] ) . _PICAL_MB_HOUR_SUF .
sprintf( '%02d', $endTimeArray[4] ) . _PICAL_MB_MINUTE_SUF;
if ( $requestMode === 'Daily' || $requestMode === 'Weekly' ) {
$title = $eventFeed->title->getText() . ' : ' . $event->title->getText();
$titleString = mb_convert_encoding( $title, mb_internal_encoding(), 'utf-8' );
$title = $titleString . ' : ' . $startTime . _PICAL_MB_TIMESEPARATOR . $endTime;
} else {
$title = $event->title->getText();
$title = mb_convert_encoding( $title, mb_internal_encoding(), 'utf-8' );
}
$description = $event->content->getText();
$description = mb_convert_encoding( $description, mb_internal_encoding(), 'utf-8' );
$description = '<div style="padding-left: 1.5em;">' . nl2br( $description ) . '</div>';
$plugin_returns[$startDay][] = array(
'dotgif' => $plugin['dotgif'],
'link' => 'https://www.google.com/accounts/Login?Email=example%40example.com',
'title' => $title,
'description' => $description
);
}
}
}
次に、イベントフィード毎に、イベントタイトルや説明文の変換、日付フォーマットの変更などを行います。
それらが終わったら、piCalに変換する配列$plugin_returns に値を格納します。
この繰り返し処理が一通り終わると、Googleカレンダーから必要な情報を取得出来ているはずです。
以上で、piCal用Googleカレンダーの実験は終了ですが、最後に補足として。
piCalのブロック全てがプラグインを呼んでくれるわけではないので、カレンダー以外のブロックに関しては、プラグインでの取得が出来ないみたいです。
最終的に、このあたりも簡単に取得できるようになると、更に使い勝手が上がると思いますので、機会があったら手を出して見たいと思います
RSS feed for comments on this post.
ƤˤϡޤȤդƤޤ
Ȥ
ʤߥȤդ뤳ȤϽޤ