Created
March 10, 2011 09:58
-
-
Save ahomu/863850 to your computer and use it in GitHub Desktop.
[a-blog cms] (去年|むかし)のおもいでモジュール
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
テンプレートはこんなかんじで | |
<!-- BEGIN_MODULE Sample_KyonenNoOmoide --> | |
<p>去年のおもいで</p> | |
<ul><!-- BEGIN omoide:loop --> | |
<li><a href="{url}">{title}</a></li><!-- END omoide:loop --><!-- BEGIN notFound --> | |
<li>おもいでなかった・・・</li><!-- END notFound --> | |
</ul> | |
<!-- END_MODULE Sample_KyonenNoOmoide --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// このファイルを,php/ACMS/GET/Sample/KyonenNoOmoide.php として配置します | |
require_once ACMS_LIB_DIR.'GET.php'; | |
class ACMS_GET_Sample_KyonenNoOmoide extends ACMS_GET | |
{ | |
function get() | |
{ | |
// 詳細ページでなければ,モジュールを処理しない | |
if ( VIEW !== 'entry' || !EID ) { | |
return false; | |
} | |
// テンプレートとデータベースを初期化(おまじない) | |
$Tpl = new Template($this->tpl, new ACMS_Corrector()); | |
$DB = DB::singleton(dsn()); | |
// 今年の日付(エントリーの日付) | |
$kotosi = strtotime(ACMS_RAM::entryDatetime(EID)); | |
// entryテーブルのデータを取り寄せますよ | |
$SQL = SQL::newSelect('entry'); | |
/** | |
* 去年のおもいで | |
*/ | |
// 去年の日付 | |
$kyonen = strtotime('-1 year', $kotosi); | |
// 去年の00:00:00から | |
$start = date('Y-m-d 00:00:00', $kyonen); | |
// 去年の23:59:59までを | |
$end = date('Y-m-d 23:59:59', $kyonen); | |
// 表示の対象にする | |
ACMS_Filter::entrySpan($SQL, $start, $end); | |
/** | |
* むかしのおもいで | |
* ※こっちにするときは,'去年のおもいで'処理はコメントアウト. | |
*/ | |
// 今よりも前の日付で | |
// $SQL->addWhereOpr('entry_datetime', date('Y-m-d 00:00:00', $kotosi), '<'); | |
// 日付の月日部分が,一致するエントリーを対象にする | |
// $SUBSTR = SQL::newFunction('entry_datetime', array('SUBSTR', 5, 5)); | |
// $SQL->addWhereOpr($SUBSTR, date('m-d', $kotosi)); | |
// インデキシングがONのエントリーだけ | |
$SQL->addWhereOpr('entry_indexing', 'on'); | |
// 公開状態のエントリーだけ | |
$SQL->addWhereOpr('entry_status', 'open'); | |
// 同じカテゴリー内に限定したいときは,コメントアウトを外す | |
//$SQL->addWhereOpr('entry_category_id', CID); | |
// 同じブログ内に限定したいときは,コメントアウトを外す | |
//$SQL->addWhereOpr('entry_blog_id', BID); | |
// SQLを発行して,結果を全件取得 | |
$all = $DB->query($SQL->get(dsn()), 'all'); | |
// もし,結果が空っぽだったら・・・ | |
if ( empty($all) ) { | |
// notFoundブロックだけ追加して終わる | |
$Tpl->add('notFound'); | |
} else { | |
// テンプレートに結果行を渡す | |
foreach ( $all as $row ) { | |
$title = $row['entry_title']; | |
$datetime = $row['entry_datetime']; | |
$eid = $row['entry_id']; | |
$Tpl->add('omoide:loop', array( | |
'title' => $title, | |
'datetime' => $datetime, | |
'url' => acmsLink(array('eid'=>$eid)), | |
)); | |
} | |
} | |
return $Tpl->get(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a-blog由来のむかしのおもいでにもなるように処理を追加.