【freo】【freoTips】【プラグイン系TIPS】スケジュールカレンダー表示プラグインで登録しているスケジュールのカテゴリー別にカレンダーを色分けする方法
- 2014/08/22 21:21
- スケジュールプラグイン
- スケジュールカテゴリー表示プラグイン
- 57
スケジュールプラグインを利用すると、予定を登録することができます。
予定はカテゴリーで分類することができます。
スケジュールカレンダー表示プラグインを利用すると、予定が登録されている日に該当日の予定一覧へのリンクを貼るカレンダーを表示できます。
スケジュールカレンダー表示プラグインで、登録している予定のカテゴリー別にカレンダーを色分けする方法は以下のとおりです。
(1日につき1件の予定が登録されているという想定です。複数の予定が登録されていた場合正常に動作しない可能性があります。)
スケジュールカレンダー表示プラグインでカテゴリー情報を取得できるようにする
- [freo/libs/freo/plugins/display.schedule_calender.php]の46行目~50行目を
if (FREO_DATABASE_TYPE == 'mysql') { $stmt = $freo->pdo->prepare('SELECT datetime,category_id FROM ' . FREO_DATABASE_PREFIX . 'plugin_schedules WHERE DATE_FORMAT(datetime, \'%Y%m\') = :month' . $condition); } else { $stmt = $freo->pdo->prepare('SELECT datetime,category_id FROM ' . FREO_DATABASE_PREFIX . 'plugin_schedules WHERE STRFTIME(\'%Y%m\', datetime) = :month' . $condition); }
- [freo/libs/freo/plugins/display.schedule_calender.php]の57行目~62行目を
$schedule_days = array(); while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { if (preg_match('/^\d\d\d\d-\d\d-(\d\d)/', $data['datetime'], $matches)) { $schedule_days[intval($matches[1])] = true; $category_id[intval($matches[1])] = $data['category_id']; } }
上記修正で、
<!--{foreach from=$plugin_schedule_calenders|smarty:nodefaults item='plugin_schedule_calender' name='loop'}-->~<!--{/foreach}-->
内で{$plugin_schedule_calender.category_id}
と記載すれば、予定のある日に登録されている予定のカテゴリーIDを取得できるようになります。
カレンダーテーブルにカテゴリーごとのクラスを付与する
[freo/templates/plugins/schedule_calender.html]の18行目~26行目を
<!--{if $plugin_schedule_calender.type == 'day'}--> <td {if $plugin_schedule_calender.flag}class="{$plugin_schedule_calender.category_id}"{/if}><!--{if $plugin_schedule_calender.flag}--><a href="{$freo.core.http_file}/schedule?date={$plugin_schedule_calender.date}"><!--{/if}--><span class="day">{$plugin_schedule_calender.day}</span><!--{if $plugin_schedule_calender.flag}--></a><!--{/if}--></td> <!--{elseif $plugin_schedule_calender.type == 'satday'}--> <td {if $plugin_schedule_calender.flag}class="{$plugin_schedule_calender.category_id}"{/if}><!--{if $plugin_schedule_calender.flag}--><a href="{$freo.core.http_file}/schedule?date={$plugin_schedule_calender.date}"><!--{/if}--><span class="satday">{$plugin_schedule_calender.day}</span><!--{if $plugin_schedule_calender.flag}--></a><!--{/if}--></td> <!--{elseif $plugin_schedule_calender.type == 'sunday'}--> <td {if $plugin_schedule_calender.flag}class="{$plugin_schedule_calender.category_id}"{/if}><!--{if $plugin_schedule_calender.flag}--><a href="{$freo.core.http_file}/schedule?date={$plugin_schedule_calender.date}"><!--{/if}--><span class="sunday">{$plugin_schedule_calender.day}</span><!--{if $plugin_schedule_calender.flag}--></a><!--{/if}--></td> <!--{else}--> <td>-</td> <!--{/if}-->
のように修正します。
上記修正で、予定がある日のカレンダーテーブルのセルに予定のある日に登録されている予定のカテゴリーIDをクラス付与することができるようになります。
カテゴリーごとのクラスを色分けする
[freo/css/default.css]の任意の場所で、
div#utility div.utility div.content table.calender td.予定カテゴリーID1{background-color: #ccc;} div#utility div.utility div.content table.calender td.予定カテゴリーID2{background-color: #666;} div#utility div.utility div.content table.calender td.予定カテゴリーID3{background-color: #999;}
のように、予定カテゴリーごとのセルの色分けを設定してください。
予定がある日のカテゴリーIDのカテゴリー名を取得する方法
上記手順で、<!--{foreach from=$plugin_schedule_calenders|smarty:nodefaults item='plugin_schedule_calender' name='loop'}-->~<!--{/foreach}-->
内で{$plugin_schedule_calender.category_id}
と記載すれば、予定のある日に登録されている予定のカテゴリーIDを取得できます。
{$plugin_schedule_calender.category_id}のカテゴリー名を取得するには、
<!--{foreach from=$plugin_schedule_calenders|smarty:nodefaults item='plugin_schedule_calender' name='loop'}-->~<!--{/foreach}-->
内で
{$plugin_schedule_categories[$plugin_schedule_calender.category_id].name}
と記載すればOKです。