アルファサード株式会社 代表取締役 野田 純生のブログ


PHPerのための Movable Type 講座(その2)


公開日 : 2014-04-10 18:17:01


あーしんど(爆)

※続き書いた。

その2。

fetch_author

IDを指定するとユーザー(Authorオブジェクト)を返します。

$author = $mt->db()->fetch_author( 1 );

fetch_author_by_name

IDではなく、ユーザー名(ログイン名)を指定してユーザーをロードします。

$author = $mt->db()->fetch_author_by_name( 'junnama' );

fetch_authors

ユーザー(Authorオブジェクト)の配列を返します。 以下の例は、ブログ(ID1)に記事投稿のあるユーザーの配列を返します。その他$argsに指定できるのは、MTAuthorsテンプレートタグに指定できるモディファイアと同じと考えて良いです。

$args = array( 'blog_id' => $blog_id, 'need_entry' => 1 );
$authors = $mt->db()->fetch_authors( $args );

fetch_permission

パーミッション(権限=Permissionオブジェクト)の配列を返します。 以下の例では、blog_idに0を指定しているため、$author_idのユーザーのシステム権限が返ります。

$args = array( 'blog_id' => 0, 'id' => $author_id );
$perms = $mt->db()->fetch_permission( $args );
if ( !empty( $perms ) ) {
    $perms = $perms[ 0 ];
}

fetch_all_roles

すべてのロール(Roleオブジェクト)の配列を返します。

$roles = $mt->db()->fetch_all_roles();

fetch_association

Aassociationオブジェクトの配列を返します。Associationとは、ブログとユーザーとロールの関連づけ情報を格納しているオブジェクトです。 ユーザー(ID1)がブログ1に対してロール「ライター」(role_idが1の時)権限を持っている時、associationsにauthor_idが1のAssociationオブジェクトが含まれます。

$args = array( 'blog_id' => 1, 'role_id' => array( 1 ) );
$associations = $mt->db()->fetch_associations( $args );

fetch_tag

IDを指定すると、Tagオブジェクトを返します。

$tag_id = 1;
$tag = $mt->db()->fetch_tag( $tag_id );

fetch_tag_by_name

IDではなく、タグ名(文字列)を渡してTagオブジェクトをロードします。

$tag = $mt->db()->fetch_tag( 'MovableType' );

fetch_scores(fetch_score, fetch_sum_scores, fetch_avg_scores)

使ったことないので、よくわかりませんw(おい) 要するに、MTEntryScore等で使う、「スコア」(MT5から実装されたぽい)をロードすすようなもの?

$scores = $mt->db()->fetch_scores( $namespace, $obj_id, $datasource );
$score = $mt->db()->fetch_score( $namespace, $obj_id, $author_id, $datasource );

cache_permalinks(cache_category_links)

Entryオブジェクトの配列を渡すと(cache_category_linksの場合はCategoryオブジェクトの配列)、permalink をキャッシュします。内部的にパフォーマンスのために使うものです(fetch_entries等の中で使われています)。成功すると、TRUEが返ります。

cache_comment_counts

Entryオブジェクトの配列を渡すと各記事のコメント数をカウントしてキャッシュします。これも、高速化のために内部的に利用されます。

blog_entry_count

その名の通り、ブログの記事数を返します。

$args = array( 'blog_id' => 1 );
$count = $mt->db()->blog_entry_count( $args );

blog_comment_count(category_comment_count)

その名の通り、ブログ(カテゴリ)のコメント数を返します。

blog_ping_count

ブログのトラックバック数を返します。トラックバックは、もういいや。

tags_entry_count

何か、動かないっぽい(おい)

(追記)バグ見つけた。mtdb.base.php の 2706行目、andの前にスペースを入れると、動きます(おい)

$where .= "and entry_status = 2 and entry_class = '$class'";
//      ↓スペース追加
$where .= " and entry_status = 2 and entry_class = '$class'";

entry_comment_count

$entry_idを渡すと、コメント数を返します。

$count = $mt->db()->entry_comment_count( $entry_id );

asset_count

blog_idとtype(アイテムの種類)を指定して、アイテム数を返します。

$args = array( 'blog_id' => $blog_id, 'type' => 'image' );
$count = $mt->db()->asset_count( $args );

author_entry_count

ユーザーの記事数を返します。

$args = array( 'blog_id' => $blog_id, 'author_id' => $author_id );
$count = $mt->db()->author_entry_count( $args );

entry_ping_count(category_ping_count)

記事ID(カテゴリID)を渡すと、トラックバック数を返します。トラックバックはもう(ry

fetch_pings

トラックバックオブジェクトの配列を返します。引数$argsに、MTPingsテンプレートタグに指定するモディファイアの内容が指定可能です。トラックバックはもう(ry

fetch_assets

アイテム(Assetオブジェクト)の配列を返します。exclude_thumb 指定で、MTが生成したサムネイルを除外してロードします。

$args = array( 'blog_id' => $blog_id,
               'type' => 'image',
               'exclude_thumb' => 1 );
$assets = $mt->db()->fetch_assets( $args );

続く、かも。



このブログを書いている人
野田純生の写真
野田 純生 (のだ すみお)

大阪府出身。ウェブアクセシビリティエバンジェリスト。 アルファサード株式会社の代表取締役社長であり、現役のプログラマ。経営理念は「テクノロジーによって顧客とパートナーに寄り添い、ウェブを良くする」。 プロフィール詳細へ