Module m_category

Model for categories.

Copyright 2009-2015 Marc Worrell

Behaviours: gen_model.

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

Description

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

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_tree_dirty/1Check if the category tree is dirty (e.g.
last_modified/2Return the last modification date of the category.
m_find_value/3Fetch the value for the key from a model source.
m_to_list/2Transform a m_config value to a list, used for template loops.
m_value/2Transform a model value so that it can be formatted or piped through filters.
menu/1Return the menu representation of the category tree.
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.
name_to_id_check/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_meta/1Return the flattened category tree, every entry is a proplist.

Function Details

delete/3

delete(Id::integer(), TransferId::integer() | undefined, Context::#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::#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::#context{}) -> ok

fold/4

fold(Category::integer() | atom(), F::function(), Acc0::term(), Context::#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::#context{}) -> ok | {error, term()}

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

get/2

get(Id::integer() | binary() | list() | atom(), Context::#context{}) -> list() | undefined

Get the basic properties of a category

get_by_name/2

get_by_name(Name::integer() | binary() | list() | atom(), Context::#context{}) -> list() | undefined

get_path/2

get_path(Id::integer() | atom() | binary() | list(), Context::#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::integer() | atom() | binary() | list(), Context::#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::integer() | atom() | binary() | string(), Context::#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::#context{}) -> integer()

is_a/2

is_a(Id::integer() | binary() | string(), Context::#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::integer() | binary() | string(), Cat::atom(), Context::#context{}) -> boolean()

Check if the id is within a category.

is_tree_dirty/1

is_tree_dirty(Context::#context{}) -> boolean()

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

last_modified/2

last_modified(Cat::integer() | atom() | binary() | list(), Context::#context{}) -> {ok, calendar:datetime()} | {error, term()}

Return the last modification date of the category. Returns false

m_find_value/3

m_find_value(Index::Key, M::Source, Context) -> term()

Fetch the value for the key from a model source

m_to_list/2

m_to_list(M::Source, Context) -> List

Transform a m_config value to a list, used for template loops

m_value/2

m_value(M::Source, Context) -> term()

Transform a model value so that it can be formatted or piped through filters

menu/1

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

Return the menu representation of the category tree.

move_below/3

move_below(Cat::integer(), Parent::integer(), Context::#context{}) -> ok

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

name_to_id/2

name_to_id(Id::binary() | list() | integer() | {integer()}, Context::#context{}) -> {ok, integer()} | {error, {unknown_category, term()}}

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

name_to_id_check/2

name_to_id_check(Name::binary() | list() | integer() | {integer()}, Context::#context{}) -> integer()

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

ranges/2

ranges(Cat::atom() | integer() | binary() | string() | [atom() | integer() | binary() | string()], Context::#context{}) -> [{integer(), integer()}]

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

renumber/1

renumber(Context::#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::#context{}) -> ok | {delay, integer()}

Resync all ids that have their pivot_category_nr changed.

tree/1

tree(Context::#context{}) -> [list()]

Return the category tree, every entry is a proplist.

tree/2

tree(Cat::integer() | binary() | list() | atom(), Context::#context{}) -> list() | undefined

Return the category tree from the category down

tree1/2

tree1(Cat::integer() | binary() | list() | atom(), Context::#context{}) -> list() | undefined

Return the category trees below the category

tree2/1

tree2(Context::#context{}) -> list() | undefined

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

tree2/2

tree2(Cat::integer() | binary() | list() | atom(), Context::#context{}) -> list() | undefined

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

tree_flat/1

tree_flat(Context::#context{}) -> [list()]

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

tree_flat_meta/1

tree_flat_meta(Context::#context{}) -> [list()]

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


Generated by EDoc, Apr 23 2015, 13:12:01.