Module m_category

Model for categories.

Copyright © 2009-2015 Marc Worrell

Behaviours: zotonic_model.

Authors: Marc Worrell (marc@worrell.nl).

Description

Model for categories. Add, change and re-order categories.

Data Types

category()

category() = m_rsc:resource_id() | atom() | binary() | string()

Function Index

delete/3Delete the category, move referring pages to another category.
ensure_hierarchy/1Ensure that all categories are present in the $category hierarchy.
flush/1
fold/4Perform a function on all resource ids in a category.
foreach/3Perform a function on all resource ids in a category.
get/2Get the basic properties of a category.
get_by_name/2
get_path/2Return the path from a root to the category.
get_range/2
get_range_by_name/2
id_to_name/2Return the name for a given category.
image/2Return a random depiction of some resource with the given category.
insert/4
is_a/2Return the categories (as atoms) the category is part of, including the category itself (as last member).
is_a/3Check if the id is within a category.
is_a_prim/3Check if a category is within another category.
is_meta/2Check if a category is a meta category.
is_tree_dirty/1Check if the category tree is dirty (e.g.
is_used/2Check if a category is actually in use.
last_modified/2Return the last modification date of the category.
m_get/3Fetch the value for the key from a model source.
menu/1Return the menu representation of the category tree.
move_after/3Move a category after another category (on the same level).
move_below/3Move a category below another category (or the root set if undefined).
name_to_id/2Map a category name to an id, be flexible with the input.
ranges/2Given a list of category ids, return the list of numeric ranges they cover.
renumber/1Start synchronizing all resources, so that the pivot_category_nr is in sync with the category hierarchy.
renumber_pivot_task/1Resync all ids that have their pivot_category_nr changed.
tree/1Return the category tree, every entry is a proplist.
tree/2Return the category tree from the category down.
tree1/2Return the category trees below the category.
tree2/1Return the category tree from the category down, max children of children.
tree2/2Return the category tree from the category down, max children of children.
tree_flat/1Return the flattened category tree, every entry is a proplist.
tree_flat/2Return the flattened category tree, every entry is a proplist.
tree_flat_meta/1Return the flattened category tree, every entry is a proplist.

Function Details

delete/3

delete(Id::m_rsc:resource(), TransferId::integer() | undefined, Context::z:context()) -> ok | {error, term()}

Delete the category, move referring pages to another category. After this routine the caches are dirty and child-categories might need renumbering if a TransferId was defined and there were sub-categories.

ensure_hierarchy/1

ensure_hierarchy(Context::z:context()) -> ok | {error, renumbering}

Ensure that all categories are present in the $category hierarchy. This appends any newly found categories to the end of the category tree.

flush/1

flush(Context::z:context()) -> ok

fold/4

fold(Category::integer() | atom(), F::function(), Acc0::term(), Context::z:context()) -> term() | {error, term()}

Perform a function on all resource ids in a category. Order of the ids is unspecified.

foreach/3

foreach(Category::integer() | atom(), F::function(), Context::z:context()) -> ok | {error, term()}

Perform a function on all resource ids in a category. Order of the ids is unspecified.

get/2

get(Id::m_rsc:resource(), Context::z:context()) -> list() | undefined

Get the basic properties of a category

get_by_name/2

get_by_name(Name::category(), Context::z:context()) -> list() | undefined

get_path/2

get_path(Id::category(), Context::z:context()) -> [integer()]

Return the path from a root to the category. Excluding the category itself, most specific last.

get_range/2

get_range(Id, Context) -> any()

get_range_by_name/2

get_range_by_name(Name, Context) -> any()

id_to_name/2

id_to_name(Name::category(), Context::z:context()) -> atom() | undefined

Return the name for a given category.

If the category does not have a unique name will result in undefined. If the lookup is made by name, the name is checked for existence, and if not found, results in undefined.

image/2

image(Cat::category(), Context::z:context()) -> integer() | undefined

Return a random depiction of some resource with the given category.

insert/4

insert(ParentId::undefined | integer(), Name::binary() | atom() | string(), Props::list(), Context::z:context()) -> integer()

is_a/2

is_a(Id::m_rsc:resource(), Context::z:context()) -> [atom()]

Return the categories (as atoms) the category is part of, including the category itself (as last member).

is_a/3

is_a(Id::category(), Cat::category(), Context::z:context()) -> boolean()

Check if the id is within a category.

is_a_prim/3

is_a_prim(CatId::integer(), Name::binary() | string() | atom(), Context::z:context()) -> boolean()

Check if a category is within another category. This can be used within primitive rsc routines that are not able to use the rsc caching (due to recursion).

is_meta/2

is_meta(CatId::integer(), Context::z:context()) -> boolean()

Check if a category is a meta category. This can't use the m_rsc routines as it is also used to determine the default content group during the m_rsc:get/2

is_tree_dirty/1

is_tree_dirty(Context::z:context()) -> boolean()

Check if the category tree is dirty (e.g. resource pivot numbers are being updated)

is_used/2

is_used(Category, Context) -> any()

Check if a category is actually in use.

last_modified/2

last_modified(Cat::category(), Context::z:context()) -> {ok, calendar:datetime()} | {error, term()}

Return the last modification date of the category. Returns false

m_get/3

m_get(Rest::list(), Msg::zotonic_model:opt_msg(), Context::z:context()) -> zotonic_model:return()

Fetch the value for the key from a model source

menu/1

menu(Context::z:context()) -> [{integer(), list()}]

Return the menu representation of the category tree.

move_after/3

move_after(Cat::category(), After::category() | undefined, Context::z:context()) -> ok | {error, notfound}

Move a category after another category (on the same level).

move_below/3

move_below(Cat::integer(), Parent::integer(), Context::z:context()) -> ok | {error, notfound}

Move a category below another category (or the root set if undefined)

name_to_id/2

name_to_id(Id::m_rsc:resource() | {m_rsc:resource_id()}, Context::z:context()) -> {ok, m_rsc:resource_id()} | {error, {unknown_category, term()}}

Map a category name to an id, be flexible with the input

ranges/2

ranges(Cat::category() | [category()], Context::z:context()) -> [{integer(), integer()}]

Given a list of category ids, return the list of numeric ranges they cover.

renumber/1

renumber(Context::z:context()) -> ok

Start synchronizing all resources, so that the pivot_category_nr is in sync with the category hierarchy.

renumber_pivot_task/1

renumber_pivot_task(Context::z:context()) -> ok | {delay, integer()}

Resync all ids that have their pivot_category_nr changed.

tree/1

tree(Context::z:context()) -> [list()]

Return the category tree, every entry is a proplist.

tree/2

tree(Cat::category(), Context::z:context()) -> list() | undefined

Return the category tree from the category down

tree1/2

tree1(Cat::category(), Context::z:context()) -> list() | undefined

Return the category trees below the category

tree2/1

tree2(Context::z:context()) -> list() | undefined

Return the category tree from the category down, max children of children

tree2/2

tree2(Cat::category(), Context::z:context()) -> list() | undefined

Return the category tree from the category down, max children of children

tree_flat/1

tree_flat(Context::z:context()) -> [list()]

Return the flattened category tree, every entry is a proplist. Used for select lists.

tree_flat/2

tree_flat(CatId::category(), Context::z:context()) -> [list()]

Return the flattened category tree, every entry is a proplist. Used for select lists.

tree_flat_meta/1

tree_flat_meta(Context::z:context()) -> [list()]

Return the flattened category tree, every entry is a proplist. Used for select lists.


Generated by EDoc