<<

NAME

MT::Category - Movable Type category record

SYNOPSIS

    use MT::Category;
    my $cat = MT::Category->new;
    $cat->blog_id($blog->id);
    $cat->label('My Category');
    my @children = $cat->children;
    $cat->save
        or die $cat->errstr;

DESCRIPTION

An MT::Category object represents a category in the Movable Type system. It is essentially a wrapper around the category label; by wrapping the label in an object with a numeric ID, we can use the ID as a "foreign key" when mapping entries into categories. Thus, if the category label changes, the mappings don't break. This object does not contain any information about the category-entry mappings--for those, look at the MT::Placement object.

USAGE

As a subclass of MT::Object, MT::Category inherits all of the data-management and -storage methods from that class; thus you should look at the MT::Object documentation for details about creating a new object, loading an existing object, saving an object, etc.

DATA ACCESS METHODS

The MT::Category object holds the following pieces of data. These fields can be accessed and set using the standard data access methods described in the MT::Object documentation.

  • id

    The numeric ID of the category.

  • blog_id

    The numeric ID of the blog to which this category belongs.

  • label

    The label of the category.

  • author_id

    The numeric ID of the author you created this category.

  • parent_category

    Returns a MT::Category object representing the immediate parent category. Returns undef if there is none.

  • parent_categories

    Returns an array of MT::Category objects representing the path from the category to the top level of categories, with the first member of the array being the immediate parent. Returns an empty array if the category is already at the top level.

  • children_categories

    Returns an array of MT::Category objects representing all of the immediate children of the category.

  • $subcat->is_descendant($parent)

    Returns a true value if the category is a descendant of $parent.

  • $subcat->is_ancestor($child)

    Returns a true value if the category is an ancestor of $child.

DATA LOOKUP

In addition to numeric ID lookup, you can look up or sort records by any combination of the following fields. See the load documentation in MT::Object for more information.

  • blog_id
  • label

NOTES

  • When you remove a category using MT::Category::remove, in addition to removing the category record, all of the entry-category mappings (MT::Placement objects) will be removed.

CLASS METHODS

  • MT::Category->top_level_categories($blog_id)

    Returns an array of MT::Category objects representing the top level of the category hierarchy in the blog identified by $blog_id.

AUTHOR & COPYRIGHTS

Please see the MT manpage for author, copyright, and license information.

<<