Copyright © 2009-2020 Marc Worrell
Behaviours: zotonic_model.
Authors: Marc Worrell (marc@worrell.nl).
digits() = 48..57
props() = map()
props_all() = props() | props_legacy()
props_legacy() = proplists:proplist()
resource() = resource_id() | [digits()] | resource_name() | undefined
resource_id() = integer()
resource_name() = string() | binary() | atom()
resource_uri() = binary()
update_function() = fun((resource() | insert_rsc, props(), z:context()) -> {ok, UpdateProps::props()} | {error, term()})
common_properties/1 | Common properties, these are used by exporter and backup routines. |
delete/2 | Delete a resource. |
delete/3 | |
duplicate/3 | Duplicate a resource. |
ensure_name/2 | Ensure that a resource has a name, caller must have update rights. |
exists/2 | |
get/2 | Read a whole resource. |
get_acl_props/2 | Get the ACL fields for the resource with the id. |
get_raw/2 | Get the resource from the database, do not fetch the pivot fields and do not use the cached result. |
get_raw_lock/2 | Same as get_raw/2 but also lock the resource for update. |
insert/2 | Insert a new resource. |
insert/3 | |
is_a/2 | Return the categories and the inherited categories of the resource. |
is_a/3 | Check if the resource is in a category. |
is_a_id/2 | Return the categories and the inherited categories of the resource. |
is_cat/3 | Check if the resource is exactly the category. |
is_deletable/2 | |
is_editable/2 | |
is_linkable/2 | |
is_me/2 | |
is_visible/2 | |
m_delete/3 | |
m_get/3 | Fetch the value for the key from a model source. |
media/2 | |
merge_delete/3 | Merge a resource with another, delete the loser. |
merge_delete/4 | Merge a resource with another, delete the loser. |
name_lookup/2 | Return the id of the resource with a certain unique name. |
name_to_id/2 | Return the id of the resource with the name. |
name_to_id_cat/3 | |
o/2 | Used for dereferencing object edges inside template expressions. |
o/3 | Return the list of objects with a certain predicate. |
o/4 | |
op/2 | |
p/3 | Fetch a property from a resource. |
p/4 | |
p_no_acl/3 | Fetch a property from a resource, no ACL check is done. |
page_path_to_id/2 | Given a page path, return {ok, Id} with the id of the found resource. |
page_url/2 | |
page_url_abs/2 | |
rid/2 | Fetch a resource id from any input. |
s/2 | |
s/3 | |
s/4 | |
sp/2 | |
touch/2 | "Touch" the rsc, incrementing the version nr and the modification date/ modifier_id. |
update/3 | Update a resource. |
update/4 | |
uri_lookup/2 | Return the id of the resource with a certain uri. |
common_properties(Context) -> any()
Common properties, these are used by exporter and backup routines.
delete(Id::resource(), Context::z:context()) -> ok | {error, term()}
Delete a resource
delete(Id::resource(), FollowUp::resource(), Context::z:context()) -> ok | {error, term()}
duplicate(Id::resource(), Props::props_all(), Context::z:context()) -> {ok, NewId::resource_id()} | {error, Reason::string()}
Duplicate a resource.
ensure_name(Id::integer(), Context::z:context()) -> ok
Ensure that a resource has a name, caller must have update rights.
exists(Id::resource(), Context::z:context()) -> boolean()
get(Id::resource(), Context::z:context()) -> map() | undefined
Read a whole resource. Return 'undefined' if the resource was not found, crash on database errors. The properties are filtered by the ACL.
get_acl_props(Id::resource(), Context::z:context()) -> #acl_props{}
Get the ACL fields for the resource with the id. Will always return a valid record, even if the resource does not exist.
get_raw(Id::resource(), Context::z:context()) -> {ok, map()} | {error, term()}
Get the resource from the database, do not fetch the pivot fields and do not use the cached result. The properties are NOT filtered by the ACL.
get_raw_lock(Id::resource(), Context::z:context()) -> {ok, map()} | {error, term()}
Same as get_raw/2 but also lock the resource for update. The properties are NOT filtered by the ACL.
insert(Props::props_all(), Context::z:context()) -> {ok, resource_id()} | {error, term()}
Insert a new resource
insert(Props::props_all(), Options::list(), Context::z:context()) -> {ok, resource_id()} | {error, term()}
is_a(Id::resource(), Context::z:context()) -> [atom()]
Return the categories and the inherited categories of the resource. Returns a list with category atoms
is_a(Id::resource(), Cat::m_category:category(), Context::z:context()) -> boolean()
Check if the resource is in a category.
is_a_id(Id::resource(), Context::z:context()) -> [pos_integer()]
Return the categories and the inherited categories of the resource. Returns a list with category ids
is_cat(Id::resource(), Cat::atom(), Context::z:context()) -> boolean()
Check if the resource is exactly the category
is_deletable(Id::resource(), Context::z:context()) -> boolean()
is_editable(Id::resource(), Context::z:context()) -> boolean()
is_linkable(Id::resource(), Context::z:context()) -> boolean()
is_me(Id::resource(), Context::z:context()) -> boolean()
is_visible(Id::resource(), Context::z:context()) -> boolean()
m_delete(X1, Msg, Context) -> any()
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
media(Id::resource(), Context::z:context()) -> list()
merge_delete(WinnerId::resource(), LoserId::resource(), Context::z:context()) -> ok | {error, term()}
Merge a resource with another, delete the loser.
merge_delete(WinnerId::resource(), LoserId::resource(), Options::list(), Context::z:context()) -> ok | {error, term()}
Merge a resource with another, delete the loser.
name_lookup(Name::resource_name(), Context::z:context()) -> resource_id() | undefined
Return the id of the resource with a certain unique name.
name_to_id(Name::resource_name(), Context::z:context()) -> {ok, resource_id()} | {error, {unknown_rsc, resource_name()}}
Return the id of the resource with the name
name_to_id_cat(Name::resource(), Cat::resource_name(), Context::z:context()) -> {ok, resource_id()} | {error, {unknown_rsc_cat, resource(), resource_name()}}
o(Id::resource(), Context::z:context()) -> function()
Used for dereferencing object edges inside template expressions
o(Id::resource(), Predicate::atom(), Context::z:context()) -> list()
Return the list of objects with a certain predicate
o(Id::resource(), Predicate::atom(), N::pos_integer(), Context::z:context()) -> resource_id() | undefined
op(Id::resource(), Context::z:context()) -> list()
p(Id::resource(), Property::atom() | binary() | string(), Context::z:context()) -> term() | undefined
Fetch a property from a resource. When the rsc does not exist, the property does not exist or the user does not have access rights to the property then return 'undefined'.
p(Id, Property, DefaultValue, Context) -> any()
p_no_acl(Id, Predicate, Context) -> any()
Fetch a property from a resource, no ACL check is done.
page_path_to_id(Path::binary() | string(), Context::z:context()) -> {ok, resource_id()} | {redirect, resource_id()} | {error, {unknown_path, binary()}} | {error, {illegal_page_path, binary(), length | unicode}}
Given a page path, return {ok, Id} with the id of the found resource. When the resource does not have the page path, but did so once, this function will return {redirect, Id} to indicate that the page path was found but is no longer the current page path for the resource.
page_url(Id::resource(), Context::z:context()) -> iodata() | undefined
page_url_abs(Id::resource(), Context::z:context()) -> iodata() | undefined
rid(Id::resource() | #trans{}, Context::z:context()) -> resource_id() | undefined
Fetch a resource id from any input
s(Id::resource(), Context::z:context()) -> function()
s(Id::resource(), Predicate::atom(), Context::z:context()) -> list()
s(Id::resource(), Predicate::atom(), N::pos_integer(), Context::z:context()) -> resource_id() | undefined
sp(Id::resource(), Context::z:context()) -> list()
touch(Id::resource(), Context::z:context()) -> {ok, resource_id()} | {error, enoent}
"Touch" the rsc, incrementing the version nr and the modification date/ modifier_id. This should be called as part of another update or transaction and does not resync the caches, and does not check the ACL. After "touching" the resource will be re-pivoted.
update(Id::resource(), Props::props_all() | update_function(), Context::z:context()) -> {ok, resource()} | {error, term()}
Update a resource
update(Id::resource(), Props::props_all() | update_function(), Options::list(), Context::z:context()) -> {ok, resource()} | {error, term()}
uri_lookup(Uri::resource_uri() | string(), Context::z:context()) -> resource_id() | undefined
Return the id of the resource with a certain uri.
Generated by EDoc