RevObjectTest03
構成
$MT_DIR/
|__ plugins/
| |__ RevObjectTest03/
| |__ config.yaml
| |__ lib/
| | |__ RevObjectTest03
| | |__ L10N
| | | |__ ja.pm
| | | |__ en_us.pm
| | |__ CMS.pm
| | |__ Callback.pm
| | |__ RevObject03.pm
| |__ tmpl/
| | |__ revobjecttest03_list.tmpl
| | |__ revobjecttest03_edit.tmpl
ソース
config.yaml
id: RevObjectTest03
key: RevObjectTest03
name: <__trans phrase="_REVOBJECTTEST03_NAME_">
version: 1.0
description: <__trans phrase="_REVOBJECTTEST03_DESCRIPTION">
author_name: <__trans phrase="_REVOBJECTTEST03_AUTHOR">
author_link: http://www.example.com/about/
doc_link: http://www.example.com/docs/
# 言語対応
l10n_class: RevObjectTest03::L10N
# 独自オブジェクトの定義
schema_version: 0.00
object_types:
revobject03: RevObjectTest03::RevObject03
callbacks:
# 保存前に起動させる
cms_pre_save.revobject03:
code: $RevObjectTest03::RevObjectTest03::Callback::pre_save
priority: 10
# 保存後に起動させる
cms_post_save.revobject03:
code: $RevObjectTest03::RevObjectTest03::Callback::post_save
priority: 5
# MT::Revisable::gather_changed_colsから起動
RevObjectTest03::RevObject03::gather_changed_cols:
code: $RevObjectTest03::RevObjectTest03::CMS::gather_changed_cols
priority: 5
# アプリケーション
applications:
# CMS管理画面
cms:
# メニュー画面
menus:
# カスタムメニュー
custom_menu:
# 表示名
label: Custom Menu
# 表示順
order: 1000
# 一覧表示
custom_menu:list:
# 表示名
label: _revobjecttest03_list
# 表示順
order: 300
# 表示スコープ
view:
- website
- blog
# モード
mode: revobjecttest03_list
condition: sub { return 1 }
# 編集表示
custom_menu:edit:
# 表示名
label: _revobjecttest03_new
# 表示順
order: 310
# 表示スコープ
view:
- website
- blog
# モード
mode: revobjecttest03_edit
# 引数
args:
_type: new
condition: sub { return 1 }
# メソッド定義
methods:
# "custom_menu:test1"をクリックした場合に呼び出される
revobjecttest03_list: $RevObjectTest03::RevObjectTest03::CMS::list
revobjecttest03_edit: $RevObjectTest03::RevObjectTest03::CMS::edit
revobjecttest03_save: $RevObjectTest03::RevObjectTest03::CMS::save
lib/RevObjectTest03/RevObject03.pm
package RevObjectTest03::RevObject03;
use strict;
use base qw( MT::Object MT::Revisable );
use Data::Dumper;
__PACKAGE__->install_properties ({
column_defs => {
'id' => 'integer not null auto_increment',
'name' => {
type => 'string',
size => 255,
label => 'name',
revisioned => 1
},
'type' => {
type => 'string',
size => 255,
label => 'type',
revisioned => 1
},
'num' => {
type => 'string',
size => 255,
label => 'num',
revisioned => 1
},
'kingaku' => {
type => 'string',
size => 255,
label => 'num',
revisioned => 1
},
'revision' => 'integer meta',
},
indexes => {
},
meta => 1,
audit => 1,
datasource => 'revobject03',
primary_key => 'id',
class_type => 'revobject03',
});
sub blog{
0;
}
sub gather_changed_cols {
my $obj = shift;
my ( $orig, $app ) = @_;
MT::Revisable::gather_changed_cols( $obj, @_ );
my $changed_cols = $obj->{changed_revisioned_cols} || [];
1;
}
sub pack_revision {
my $obj = shift;
my $values = MT::Revisable::pack_revision($obj);
$values;
}
sub unpack_revision {
my $obj = shift;
my ($packed_obj) = @_;
MT::Revisable::unpack_revision( $obj, @_ );
}
1;
lib/RevObjectTest03/L10N.pm
package RevObjectTest03::L10N;
use strict;
use base 'MT::Plugin::L10N';
1;
lib/RevObjectTest03/L10N/ja.pm
package RevObjectTest03::L10N::ja;
use strict;
use base 'RevObjectTest03::L10N::en_us';
use vars qw( %Lexicon );
%Lexicon = (
'_REVOBJECTTEST03_NAME_' => 'RevObjectTest03',
'_REVOBJECTTEST03_DESCRIPTION' => 'RevObjectTest03のテスト',
'_REVOBJECTTEST03_AUTHOR' => 'プラグイン作者',
'_revobjecttest03_list' => '一覧',
'_revobjecttest03_edit' => '編集',
'_revobjecttest03_new' => '新規',
'_RevObjectTest03_ItemId' => '商品ID',
'_RevObjectTest03_ItemName' => '商品名',
'_RevObjectTest03_ItemType' => '種類',
'_RevObjectTest03_ItemNum' => '数量',
'_RevObjectTest03_ItemKingaku' => '金額',
'_RevObjectTest03_ItemNote' => 'メモ',
'_RevObjectTest03_ItemName Set' => '商品名を入力してください',
'_RevObjectTest03_ItemType Set' => '種類を入力してください',
'_RevObjectTest03_ItemNum Set' => '数量を入力してください',
'_RevObjectTest03_ItemKingaku Set' => '金額を入力してください',
'_RevObjectTest03_ItemNote Set' => '変更メモを入力してください',
'_RevObjectTest03_Save' => '保存',
);
1;
lib/RevObjectTest03/L10N/en_us.pm
package RevObjectTest03::L10N::en_us;
use strict;
use base 'RevObjectTest03::L10N';
use vars qw( %Lexicon );
%Lexicon = (
'_REVOBJECTTEST03_NAME_' => 'RevObjectTest03',
'_REVOBJECTTEST03_DESCRIPTION' => 'RevObjectTest03 Test',
'_REVOBJECTTEST03_AUTHOR' => 'RevObjectTest03 author',
'_revobjecttest03_list' => 'list',
'_revobjecttest03_edit' => 'edit',
'_revobjecttest03_new' => 'new',
);
1;
lib/RevObjectTest03/CMS.pm
package RevObjectTest03::CMS;
use strict;
use MT::FileMgr;
use Data::Dumper;
use Encode;
use utf8;
sub list{
# パラメータ取得
my ($app) = @_;
# 返却用パラメータ定義
my ( %param, %args, %terms );
# パラメータコンテキスト取得
my $q = $app->param;
# ブログID取得
my $blog_id = $q->param('blog_id');
my $_type = $q->param('_type');
# 保存
my $class_name = 'revobject03';
my $class = MT->model($class_name);
# 読み込み
my $iter = $class->load_iter();
my @list;
while(my $obj = $iter->()){
# ハッシュ配列に設定
my %item;
# 各値を設定
$item{id} = $obj->id;
$item{name} = $obj->name;
$item{type} = $obj->type;
$item{num} = $obj->num;
$item{kingaku} = $obj->kingaku;
# ハッシュのリファレンスを配列に追加
push @list, \%item;
}
# 配列のリファレンスを設定
$param{list} = \@list;
# テンプレートを設定
$app->load_tmpl('revobjecttest03_list.tmpl', \%param );
}
sub edit{
# パラメータ取得
my ($app) = @_;
# 返却用パラメータ定義
my ( %param, %args, %terms );
# パラメータコンテキスト取得
my $q = $app->param;
# ブログID取得
my $blog_id = $q->param('blog_id');
# 処理タイプ
my $_type = $q->param('_type');
# リビジョンコード
my $_r = $q->param('_r');
my $id = $q->param('id');
my $name = "";
my $type = "";
my $num = "";
my $kingaku = "";
my @rev_list;
if( $_type eq "edit"){
my $class_name = 'revobject03';
my $class = MT->model($class_name);
my $obj = $class->load({id => $id});
if($obj){
# リビジョン一覧を取得
my $datasource = $obj->datasource;
my $rev_class = MT->model( $datasource . ':revision' );
my $terms = { $datasource . '_id' => $obj->id };
my $count = $rev_class->count($terms);
my $rev_iter = $rev_class->load_iter(
$terms,
{ sort => 'created_on',
direction => 'ascend',
}
);
while ( my $rev = $rev_iter->() ) {
# ハッシュ定義
my %rev_info;
$rev_info{id} = $rev->id;
$rev_info{label} = $rev->label;
$rev_info{rev_number} = $rev->rev_number;
$rev_info{changed} = $rev->changed;
$rev_info{created_on} = $rev->created_on;
$rev_info{modified_on} = $rev->modified_on;
$rev_info{entry_id} = $rev->revobject03_id;
$rev_info{description} = $rev->description;
$rev_info{created_date} = MT::Util::format_ts("%Y-%m-%d %H:%M:%S", $rev->created_on);
# 配列に設定
push @rev_list, \%rev_info;
}
# リビジョンデータより判定
if($_r ne ""){
# 指定リビジョンのデータを取得
my $load_rev = $obj->load_revision( { rev_number => $_r } );
# 取得したリビジョンのオブジェクトを設定
$obj = $load_rev->[0];
}
# パラメータ設定
$name = $obj->name;
$type = $obj->type;
$num = $obj->num;
$kingaku = $obj->kingaku;
}
}
# 設定
$param{_type} = $_type;
$param{revobjecttest03_id} = $id;
$param{revobjecttest03_name} = $name;
$param{revobjecttest03_type} = $type;
$param{revobjecttest03_num} = $num;
$param{revobjecttest03_kingaku} = $kingaku;
# リビジョン情報
$param{revobjecttest02_rev} = \@rev_list; # リファレンスを渡す
# テンプレートを設定
$app->load_tmpl('revobjecttest03_edit.tmpl', \%param );
}
sub save{
# パラメータ取得
my ($app) = @_;
# 返却用パラメータ定義
my ( %param, %args, %terms );
# パラメータコンテキスト取得
my $q = $app->param;
# ブログID取得
my $blog_id = $q->param('blog_id');
# パラメータ取得
my $id = $q->param('revobjecttest03_id');
my $name = $q->param('revobjecttest03_name');
my $type = $q->param('revobjecttest03_type');
my $num = $q->param('revobjecttest03_num');
my $kingaku = $q->param('revobjecttest03_kingaku');
# 保存
my $class_name = 'revobject03';
my $class = MT->model($class_name);
# 読み込み
my $orig_obj;
my $obj = $class->load({id => $id});
if(!$obj){
$obj = $class->new();
}else{
$orig_obj = $obj->clone;
}
# リビジョン設定
my $note = $q->param('revobjecttest03_note');
# リビジョン保存設定用パラメータ
$app->param('save_revision', "1"); # 1に設定するとリビジョンを保存する
$app->param('revision-note', $note); # 変更メモ
# パラメータ設定
$obj->name($name);
$obj->type($type);
$obj->num($num);
$obj->kingaku($kingaku);
# pre_saveコールバック起動
$app->run_callbacks( 'cms_pre_save.revobject03', $app, $obj, $orig_obj );
# 保存
$obj->save or die $obj->errstr;
# post_saveコールバック起動
$app->run_callbacks( 'cms_post_save.revobject03', $app, $obj, $orig_obj );
my $id = $obj->id;
return $app->redirect(
$app->uri(
mode => 'revobjecttest03_list',
args => {
blog_id => $blog_id,
},
)
);
}
sub debug{
my ($data) = @_;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 1;
my $dump = Dumper($data);
my $file = "/home/httpd/cgi-bin/mt/aaa.txt";
my $fmgr = MT::FileMgr->new('Local');
$fmgr->put_data($dump, $file);
}
1;
lib/RevObjectTest03/Callback.pm
package RevObjectTest03::Callback;
use strict;
use MT::FileMgr;
use Data::Dumper;
use Encode;
use utf8;
sub pre_save{
my $eh = shift;
my ( $app, $obj ) = @_;
}
sub post_save{
my $eh = shift;
my ( $app, $obj ) = @_;
}
1;
tmpl/revobjecttest03_list.tmpl
<mt:setvarblock name="page_title"><__trans phrase="_REVOBJECTTEST03_NAME_"></mt:setvarblock>
<mt:setvar name="export_webpage" value="1">
<mt:setvarblock name="html_head" append="1">
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/dialog.js"></script>
</mt:setvarblock>
<mt:setvarblock name="system_msg">
<div id="msg-block">
<mt:if name="save_success">
<mtapp:statusmsg
id="saved-theme"
class="success">
<__trans phrase="Test1 Success">
</mtapp:statusmsg>
</mt:if>
</div>
</mt:setvarblock>
<mt:setvartemplate name="object_loop">
<table class="listing-table list-page last-child" id="page-table" border="1">
<mt:loop name="$loop_for">
<mt:if name="__first__">
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">Name</th>
<th style="text-align: center;">Type</th>
<th style="text-align: center;">Num</th>
<th style="text-align: center;">Kingaku</th>
</tr>
</mt:if>
<tr>
<td style="text-align: center;"><a href="<mt:var name="script_url">?__mode=revobjecttest03_edit&_type=edit&blog_id=<mt:var name="blog_id">&id=<mt:var name="id">"><mt:var name="id"></a></td>
<td style="text-align: center;"><mt:var name="name"></td>
<td style="text-align: center;"><mt:var name="type"></td>
<td style="text-align: center;"><mt:var name="num"></td>
<td style="text-align: center;"><mt:var name="kingaku"></td>
</tr>
<mt:if name="__last__">
</mt:if>
</mt:loop>
</table>
</mt:setvartemplate>
<mt:include name="include/header.tmpl">
<mt:setvar name="loop_for" value="list" /><mt:var name="object_loop">
<br />
<script type="text/javascript">
/* <![CDATA[ */
jQuery.mtCheckbox();
jQuery(function() {
});
<mt:var name="js_include_footer" />
/* ]]> */
</script>
<!-- フッター -->
<mt:include name="include/footer.tmpl">
tmpl/revobjecttest03_edit.tmpl
<mt:setvarblock name="page_title"><__trans phrase="_REVOBJECTTEST03_NAME_"></mt:setvarblock>
<mt:setvar name="export_webpage" value="1">
<mt:setvarblock name="html_head" append="1">
<script type="text/javascript" src="<mt:var name="static_uri">js/tc/client.js"></script>
<script type="text/javascript" src="<mt:var name="static_uri">js/dialog.js"></script>
</mt:setvarblock>
<mt:setvarblock name="system_msg">
<div id="msg-block">
<mt:if name="save_success">
<mtapp:statusmsg
id="saved-theme"
class="success">
<__trans phrase="Test1 Success">
</mtapp:statusmsg>
</mt:if>
</div>
</mt:setvarblock>
<mt:setvartemplate name="object_loop">
<table class="listing-table list-page last-child" id="page-table" border="1" style="width: 50%;">
<mt:loop name="$loop_for">
<mt:if name="__first__">
<tr>
<th style="text-align: center;">ID</th>
<th style="text-align: center;">CreateDate</th>
<th style="text-align: center;">description</th>
<th style="text-align: center;">Rev</th>
</tr>
</mt:if>
<tr>
<td style="text-align: center;"><mt:var name="id"></td>
<td style="text-align: center;"><mt:var name="created_date"></td>
<td style="text-align: center;"><mt:var name="description"></td>
<td style="text-align: center;"><a href="<mt:var name="script_url">?__mode=revobjecttest03_edit&_type=edit&blog_id=<mt:var name="blog_id">&id=<mt:var name="entry_id">&_r=<mt:var name="rev_number">"><mt:var name="rev_number"></a></td>
</tr>
<mt:if name="__last__">
</mt:if>
</mt:loop>
</table>
<hr />
</mt:setvartemplate>
<mt:include name="include/header.tmpl">
<mt:setvar name="loop_for" value="revobjecttest02_rev" /><mt:var name="object_loop">
<form id="webpage_settings" method="post" enctype="multipart/form-data" action="<mt:var name="script_url">">
<input type="hidden" name="__mode" value="revobjecttest03_save" />
<input type="hidden" name="_type" value="<mt:var name="_type">" />
<input type="hidden" name="blog_id" value="<mt:var name="blog_id">" />
<input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
<fieldset>
<mtapp:setting
id="revobjecttest03-id"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemId">">
<input type="text" name="revobjecttest03_id" id="revobjecttest03_id" class="text required" value="<mt:var name="revobjecttest03_id" escape="html">" />
</mtapp:setting>
<mtapp:setting
id="revobjecttest03-name"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemName">"
show_hint="1"
hint="<__trans phrase="_RevObjectTest03_ItemName Set">">
<input type="text" name="revobjecttest03_name" id="revobjecttest03_name" class="text required" value="<mt:var name="revobjecttest03_name" escape="html">" />
</mtapp:setting>
<mtapp:setting
id="revobjecttest03-type"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemType">"
show_hint="1"
hint="<__trans phrase="_RevObjectTest03_ItemType Set">">
<input type="text" name="revobjecttest03_type" id="revobjecttest03_type" class="text required" value="<mt:var name="revobjecttest03_type" escape="html">" />
</mtapp:setting>
<mtapp:setting
id="revobjecttest03-num"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemNum">"
show_hint="1"
hint="<__trans phrase="_RevObjectTest03_ItemNum Set">">
<input type="text" name="revobjecttest03_num" id="revobjecttest03_num" class="text required" value="<mt:var name="revobjecttest03_num" escape="html">" />
</mtapp:setting>
<mtapp:setting
id="revobjecttest03-kingaku"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemKingaku">"
show_hint="1"
hint="<__trans phrase="_RevObjectTest03_ItemKingaku Set">">
<input type="text" name="revobjecttest03_kingaku" id="revobjecttest03_kingaku" class="text required" value="<mt:var name="revobjecttest03_kingaku" escape="html">" />
</mtapp:setting>
<mtapp:setting
id="revobjecttest03-note"
required="1"
label="<__trans phrase="_RevObjectTest03_ItemNote">"
show_hint="1"
hint="<__trans phrase="_RevObjectTest03_ItemNote Set">">
<input type="text" name="revobjecttest03_note" id="revobjecttest03_note" class="text required" />
</mtapp:setting>
</fieldset>
<mt:setvarblock name="action_buttons">
<button
type="submit"
accesskey="s"
title="<__trans phrase="_RevObjectTest03_Save">"
class="export action button primary">
<__trans phrase="_RevObjectTest03_Save"></button>
</mt:setvarblock>
<mt:include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1" settings_bar="1">
</form>
<script type="text/javascript">
/* <![CDATA[ */
jQuery.mtCheckbox();
jQuery(function() {
});
<mt:var name="js_include_footer" />
/* ]]> */
</script>
<!-- フッター -->
<mt:include name="include/footer.tmpl">
結果
独自画面
最終更新:2012年02月26日 21:08