Last active
November 24, 2015 05:20
-
-
Save hideki-a/96a12cdb7a1be98ce060 to your computer and use it in GitHub Desktop.
MTカスタムフィールドの研究
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
| # 基礎 | |
| # /Users/Shared/Sites/mt6/htdocs/mt/lib/MT/Template/Tags/Entry.pm | |
| # $typeの中身 | |
| # { | |
| # 'name' => 'field.data_int_number_of_employees', | |
| # 'pkg' => 'MT::Entry', | |
| # 'type' => 'vinteger_idx', | |
| # 'type_id' => '5' | |
| # } | |
| my $col = 'data_aircraft_type'; | |
| my $class = MT->model('entry'); | |
| my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
| my @entries = MT::Entry->load( | |
| { | |
| blog_id => 1, | |
| status => MT::Entry::RELEASE() | |
| }, | |
| { | |
| join => [ | |
| $class->meta_pkg, | |
| undef, | |
| { | |
| 'entry_id' => \'= entry_id', | |
| type => 'field.' . $col, | |
| $type->{type} => 'B787' | |
| } | |
| ], | |
| sort => 'authored_on', | |
| direction => 'descend', | |
| limit => 10 | |
| } | |
| ); | |
| # 応用-1 | |
| # 基礎と重複なので削除 | |
| # 応用-2 | |
| # これはできない | |
| my $col = 'checkbox01'; | |
| my $class = MT->model('entry'); | |
| my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
| my @entries = MT::Entry->load( | |
| { | |
| blog_id => 1, | |
| status => MT::Entry::RELEASE() | |
| }, | |
| { | |
| join => [ | |
| $class->meta_pkg, | |
| undef, | |
| { | |
| type => { not => ('field.' . $col) } | |
| }, | |
| { | |
| type => 'left', | |
| condition => { | |
| 'entry_id' => \'= entry_id' | |
| } | |
| } | |
| ], | |
| sort => 'authored_on', | |
| direction => 'descend', | |
| limit => 10 | |
| } | |
| ); | |
| # 応用-3 | |
| # http://weeeblog.net/blog/2009/05/25_1556.php | |
| my $col = 'data_aircraft_type'; | |
| my $class = MT->model('entry'); | |
| my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
| my @conditions = ('B787', 'A350'); | |
| my @entries = MT::Entry->load( | |
| { | |
| blog_id => 1, | |
| status => MT::Entry::RELEASE() | |
| }, | |
| { | |
| join => [ | |
| $class->meta_pkg, | |
| undef, | |
| { | |
| 'entry_id' => \'= entry_id', | |
| type => 'field.' . $col, | |
| $type->{type} => \@conditions | |
| } | |
| ], | |
| sort => 'authored_on', | |
| direction => 'descend', | |
| limit => 10 | |
| } | |
| ); | |
| # 応用-4 | |
| # MTDevGuide | |
| my $col = 'data_aircraft_type'; | |
| my $class = MT->model('entry'); | |
| my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
| my @conditions = ({ 'like' => 'B%' }); | |
| my @entries = MT::Entry->load( | |
| { | |
| blog_id => 1, | |
| status => MT::Entry::RELEASE() | |
| }, | |
| { | |
| join => [ | |
| $class->meta_pkg, | |
| undef, | |
| { | |
| 'entry_id' => \'= entry_id', | |
| type => 'field.' . $col, | |
| $type->{type} => \@conditions | |
| } | |
| ], | |
| sort => 'authored_on', | |
| direction => 'descend', | |
| limit => 10 | |
| } | |
| ); | |
| # 応用-5 | |
| # https://movabletype.org/documentation/developer/custom-custom-field-types.html | |
| # https://github.com/alfasado/mt-plugin-numeric-fields/tree/c99d36849847fce5710764cdd768ec16e1b0949b | |
| my $col = 'data_int_number_of_employees'; | |
| my $class = MT->model('entry'); | |
| my $type = MT::Meta->metadata_by_name($class, 'field.' . $col); | |
| my @entries = MT::Entry->load( | |
| { | |
| blog_id => 1, | |
| status => MT::Entry::RELEASE() | |
| }, | |
| { | |
| join => [ | |
| $class->meta_pkg, | |
| undef, | |
| { | |
| 'entry_id' => \'= entry_id', | |
| type => 'field.' . $col, | |
| $type->{type} => { '>=' => 10000 } | |
| } | |
| ], | |
| sort => 'authored_on', | |
| direction => 'descend', | |
| limit => 10 | |
| } | |
| ); |
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
| # SQL | |
| SELECT `entry_id` FROM `mt_entry` | |
| WHERE NOT EXISTS (SELECT `entry_meta_type` FROM `mt_entry_meta` WHERE `mt_entry`.`entry_id` = `mt_entry_meta`.`entry_meta_entry_id` | |
| AND `entry_meta_type` = "field.data_only_monoclass") | |
| ORDER BY `mt_entry`.`entry_id` DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment