Module m_rsc

Model for resource data.

Copyright © 2009-2020 Marc Worrell

Behaviours: zotonic_model.

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

Description

Model for resource data. Interfaces between zotonic, templates and the database.

Data Types

digits()

digits() = 48..57

props()

props() = map()

props_all()

props_all() = props() | props_legacy()

props_legacy()

props_legacy() = proplists:proplist()

resource()

resource() = resource_id() | [digits()] | resource_name() | undefined

resource_id()

resource_id() = integer()

resource_name()

resource_name() = string() | binary() | atom()

resource_uri()

resource_uri() = binary()

update_function()

update_function() = fun((resource() | insert_rsc, props(), z:context()) -> {ok, UpdateProps::props()} | {error, term()})

Function Index

common_properties/1Common properties, these are used by exporter and backup routines.
delete/2Delete a resource.
delete/3
duplicate/3Duplicate a resource.
ensure_name/2Ensure that a resource has a name, caller must have update rights.
exists/2
get/2Read a whole resource.
get_acl_props/2Get the ACL fields for the resource with the id.
get_raw/2Get the resource from the database, do not fetch the pivot fields and do not use the cached result.
get_raw_lock/2Same as get_raw/2 but also lock the resource for update.
insert/2Insert a new resource.
insert/3
is_a/2Return the categories and the inherited categories of the resource.
is_a/3Check if the resource is in a category.
is_a_id/2Return the categories and the inherited categories of the resource.
is_cat/3Check 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/3Fetch the value for the key from a model source.
media/2
merge_delete/3Merge a resource with another, delete the loser.
merge_delete/4Merge a resource with another, delete the loser.
name_lookup/2Return the id of the resource with a certain unique name.
name_to_id/2Return the id of the resource with the name.
name_to_id_cat/3
o/2Used for dereferencing object edges inside template expressions.
o/3Return the list of objects with a certain predicate.
o/4
op/2
p/3Fetch a property from a resource.
p/4
p_no_acl/3Fetch a property from a resource, no ACL check is done.
page_path_to_id/2Given a page path, return {ok, Id} with the id of the found resource.
page_url/2
page_url_abs/2
rid/2Fetch 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/3Update a resource.
update/4
uri_lookup/2Return the id of the resource with a certain uri.

Function Details

common_properties/1

common_properties(Context) -> any()

Common properties, these are used by exporter and backup routines.

delete/2

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

Delete a resource

delete/3

delete(Id::resource(), FollowUp::resource(), Context::z:context()) -> ok | {error, term()}

duplicate/3

duplicate(Id::resource(), Props::props_all(), Context::z:context()) -> {ok, NewId::resource_id()} | {error, Reason::string()}

Duplicate a resource.

ensure_name/2

ensure_name(Id::integer(), Context::z:context()) -> ok

Ensure that a resource has a name, caller must have update rights.

exists/2

exists(Id::resource(), Context::z:context()) -> boolean()

get/2

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/2

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/2

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/2

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/2

insert(Props::props_all(), Context::z:context()) -> {ok, resource_id()} | {error, term()}

Insert a new resource

insert/3

insert(Props::props_all(), Options::list(), Context::z:context()) -> {ok, resource_id()} | {error, term()}

is_a/2

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/3

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

Check if the resource is in a category.

is_a_id/2

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/3

is_cat(Id::resource(), Cat::atom(), Context::z:context()) -> boolean()

Check if the resource is exactly the category

is_deletable/2

is_deletable(Id::resource(), Context::z:context()) -> boolean()

is_editable/2

is_editable(Id::resource(), Context::z:context()) -> boolean()

is_linkable/2

is_linkable(Id::resource(), Context::z:context()) -> boolean()

is_me/2

is_me(Id::resource(), Context::z:context()) -> boolean()

is_visible/2

is_visible(Id::resource(), Context::z:context()) -> boolean()

m_delete/3

m_delete(X1, Msg, Context) -> any()

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

media/2

media(Id::resource(), Context::z:context()) -> list()

merge_delete/3

merge_delete(WinnerId::resource(), LoserId::resource(), Context::z:context()) -> ok | {error, term()}

Merge a resource with another, delete the loser.

merge_delete/4

merge_delete(WinnerId::resource(), LoserId::resource(), Options::list(), Context::z:context()) -> ok | {error, term()}

Merge a resource with another, delete the loser.

name_lookup/2

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/2

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/3

name_to_id_cat(Name::resource(), Cat::resource_name(), Context::z:context()) -> {ok, resource_id()} | {error, {unknown_rsc_cat, resource(), resource_name()}}

o/2

o(Id::resource(), Context::z:context()) -> function()

Used for dereferencing object edges inside template expressions

o/3

o(Id::resource(), Predicate::atom(), Context::z:context()) -> list()

Return the list of objects with a certain predicate

o/4

o(Id::resource(), Predicate::atom(), N::pos_integer(), Context::z:context()) -> resource_id() | undefined

op/2

op(Id::resource(), Context::z:context()) -> list()

p/3

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/4

p(Id, Property, DefaultValue, Context) -> any()

p_no_acl/3

p_no_acl(Id, Predicate, Context) -> any()

Fetch a property from a resource, no ACL check is done.

page_path_to_id/2

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/2

page_url(Id::resource(), Context::z:context()) -> iodata() | undefined

page_url_abs/2

page_url_abs(Id::resource(), Context::z:context()) -> iodata() | undefined

rid/2

rid(Id::resource() | #trans{}, Context::z:context()) -> resource_id() | undefined

Fetch a resource id from any input

s/2

s(Id::resource(), Context::z:context()) -> function()

s/3

s(Id::resource(), Predicate::atom(), Context::z:context()) -> list()

s/4

s(Id::resource(), Predicate::atom(), N::pos_integer(), Context::z:context()) -> resource_id() | undefined

sp/2

sp(Id::resource(), Context::z:context()) -> list()

touch/2

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/3

update(Id::resource(), Props::props_all() | update_function(), Context::z:context()) -> {ok, resource()} | {error, term()}

Update a resource

update/4

update(Id::resource(), Props::props_all() | update_function(), Options::list(), Context::z:context()) -> {ok, resource()} | {error, term()}

uri_lookup/2

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