Created
March 17, 2011 01:53
-
-
Save ahomu/873716 to your computer and use it in GitHub Desktop.
[a-blog cms] @tatsunori2989 さんリクエスト:フォームモジュールの特定フォームIDの投稿数を表示する
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_FormCount --> | |
{count} | |
<!-- END_MODULE Sample_FormCount--> |
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 | |
require_once ACMS_LIB_DIR.'GET.php'; | |
class ACMS_GET_Sample_FormCount extends ACMS_GET | |
{ | |
function get() | |
{ | |
/** | |
* フォーム投稿数のカウントは現状のa-blog cmsには存在しない機能なので, | |
* ここではSQLヘルパからクエリを発行する手順を示します. | |
* | |
* 一般ページでカウントを表示する際は, | |
* 投稿件数が数千件レベルになったあたりで性能低下が考えられます. | |
* 適宜DBにインデックスを振った方がよいかもしれませんが,, | |
* ここはモジュールの話なので割愛します. | |
*/ | |
$Tpl = new Template($this->tpl, new ACMS_Corrector()); | |
$DB = DB::singleton(dsn()); | |
// 対象にしたいフォームID(DB上ではform_codeに相当) | |
$code = 'order'; | |
// 表示中のブログ内のフォームに限定・別ブログのフォームならbidを直打ちで指定 | |
$bid = BID; | |
$SQL = SQL::newSelect('form'); | |
$SQL->setSelect('form_id'); | |
$SQL->addWhereOpr('form_code', $code); | |
$SQL->addWhereOpr('form_blog_id', $bid); | |
$fmid = $DB->query($SQL->get(dsn()), 'one'); | |
// form_idを正しく取得できたら続きを実行 | |
if ( !empty($fmid) ) { | |
$SQL = SQL::newSelect('log_form'); | |
$SQL->addSelect('*', 'count', null, 'count'); | |
$SQL->addWhereOpr('log_form_form_id', $fmid); | |
// 期間を限定する場合は,以下のように.例: 2011/01/01〜2011/03/31の期間 | |
//$SQL->addWhereBw('log_form_datetime', '2011-01-01 00:00:00', '2011-03-31 23:59:59'); | |
$count = $DB->query($SQL->get(dsn()), 'one'); | |
$Tpl->add(null, array('count' => intval($count))); | |
} | |
return $Tpl->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment