m_category (zotonic_core v1.0.0-rc.11)

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

Link to this section Summary

Functions

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 that all categories are present in the $category hierarchy. This appends any newly found categories to the end of the category tree.
Perform a function on all resource ids in a category. Order of the ids is unspecified.
Perform a function on all resource ids in a category. Order of the ids is unspecified.
Get the basic properties of a category
Return the path from a root to the category. Excluding the category itself, most specific last.

Return the name for a given category.

Return a random depiction of some resource with the given category.
Return the categories (as atoms) the category is part of, including the category itself (as last member).
Check if the id is within a category.
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).
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
Check if the category tree is dirty (e.g. resource pivot numbers are being updated)
Check if a category is actually in use.
Return the last modification date of the category. Returns false
Fetch the value for the key from a model source
Return the menu representation of the category tree.
Move a category after another category (on the same level).
Move a category below another category (or the root set if undefined)
Map a category name to an id, be flexible with the input
Given a list of category ids, return the list of numeric ranges they cover.
Start synchronizing all resources, so that the pivot_category_nr is in sync with the category hierarchy.
Resync all ids that have their pivot_category_nr changed.
Return the category trees below the category
Return the category tree from the category down, max children of children
Return the category tree from the category down, max children of children
Return the category tree, every entry is a proplist.
Return the category tree from the category down
Return the flattened category tree, every entry is a proplist. Used for select lists.
Return the flattened category tree, every entry is a proplist. Used for select lists.
Return the flattened category tree, every entry is a proplist. Used for select lists.

Link to this section Types

-type category() :: m_rsc:resource() | atom() | binary() | string() | {m_rsc:resource_id()}.

Link to this section Functions

Link to this function

delete(Id, TransferId, Context)

-spec delete(m_rsc:resource(), integer() | undefined, 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.
Link to this function

ensure_hierarchy(Context)

-spec ensure_hierarchy(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.
-spec flush(z:context()) -> ok.
Link to this function

fold(Category, F, Acc0, Context)

-spec fold(Category :: integer() | atom(), function(), term(), z:context()) -> term() | {error, term()}.
Perform a function on all resource ids in a category. Order of the ids is unspecified.
Link to this function

foreach(Category, F, Context)

-spec foreach(Category :: integer() | atom(), function(), z:context()) -> ok | {error, term()}.
Perform a function on all resource ids in a category. Order of the ids is unspecified.
Link to this function

get(Id, Context)

-spec get(m_rsc:resource(), z:context()) -> list() | undefined.
Get the basic properties of a category
Link to this function

get_by_name(Name, Context)

-spec get_by_name(category(), z:context()) -> list() | undefined.
Link to this function

get_path(Id, Context)

-spec get_path(category(), z:context()) -> [integer()].
Return the path from a root to the category. Excluding the category itself, most specific last.
Link to this function

get_range(Id, Context)

Link to this function

get_range_by_name(Name, Context)

Link to this function

id_to_name(Name, Context)

-spec id_to_name(category(), 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.
Link to this function

image(Cat, Context)

-spec image(category(), z:context()) -> integer() | undefined.
Return a random depiction of some resource with the given category.
Link to this function

insert(ParentId, Name, Props, Context)

-spec insert(undefined | integer(), binary() | atom() | string(), list(), z:context()) -> integer().
Link to this function

is_a(Id, Context)

-spec is_a(m_rsc:resource(), z:context()) -> [atom()].
Return the categories (as atoms) the category is part of, including the category itself (as last member).
Link to this function

is_a(Id, Cat, Context)

-spec is_a(category(), category(), z:context()) -> boolean().
Check if the id is within a category.
Link to this function

is_a_prim(CatId, Name, Context)

-spec is_a_prim(m_rsc:resource_id(), binary() | string() | atom(), 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).
Link to this function

is_meta(CatId, Context)

-spec is_meta(integer(), 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
Link to this function

is_tree_dirty(Context)

-spec is_tree_dirty(z:context()) -> boolean().
Check if the category tree is dirty (e.g. resource pivot numbers are being updated)
Link to this function

is_used(Category, Context)

Check if a category is actually in use.
Link to this function

last_modified(Cat, Context)

-spec last_modified(category(), z:context()) -> {ok, calendar:datetime()} | {error, term()}.
Return the last modification date of the category. Returns false
Link to this function

m_get(Rest, Msg, Context)

-spec m_get(list(), zotonic_model:opt_msg(), z:context()) -> zotonic_model:return().
Fetch the value for the key from a model source
Link to this function

move_after(Cat, After, Context)

-spec move_after(category(), category() | undefined, z:context()) -> ok | {error, notfound}.
Move a category after another category (on the same level).
Link to this function

move_below(Cat, Parent, Context)

-spec move_below(integer(), integer(), z:context()) -> ok | {error, notfound}.
Move a category below another category (or the root set if undefined)
Link to this function

name_to_id(Id, Context)

-spec name_to_id(category(), z:context()) ->
              {ok, m_rsc:resource_id()} | {error, {unknown_category, term()}}.
Map a category name to an id, be flexible with the input
Link to this function

ranges(Cat, Context)

-spec ranges(category() | [category()], z:context()) -> [{integer(), integer()}].
Given a list of category ids, return the list of numeric ranges they cover.
Link to this function

renumber(Context)

-spec renumber(z:context()) -> ok.
Start synchronizing all resources, so that the pivot_category_nr is in sync with the category hierarchy.
Link to this function

renumber_pivot_task(Context)

-spec renumber_pivot_task(z:context()) -> ok | {delay, integer()}.
Resync all ids that have their pivot_category_nr changed.
Link to this function

tree1(Cat, Context)

-spec tree1(category(), z:context()) -> list() | undefined.
Return the category trees below the category
-spec tree2(z:context()) -> list() | undefined.
Return the category tree from the category down, max children of children
Link to this function

tree2(Cat, Context)

-spec tree2(category(), z:context()) -> list() | undefined.
Return the category tree from the category down, max children of children
-spec tree(z:context()) -> [list()].
Return the category tree, every entry is a proplist.
Link to this function

tree(Cat, Context)

-spec tree(category(), z:context()) -> list() | undefined.
Return the category tree from the category down
Link to this function

tree_flat(Context)

-spec tree_flat(z:context()) -> [list()].
Return the flattened category tree, every entry is a proplist. Used for select lists.
Link to this function

tree_flat(CatId, Context)

-spec tree_flat(category(), z:context()) -> [list()].
Return the flattened category tree, every entry is a proplist. Used for select lists.
Link to this function

tree_flat_meta(Context)

-spec tree_flat_meta(z:context()) -> [list()].
Return the flattened category tree, every entry is a proplist. Used for select lists.