Module m_rsc

Model for resource data.

Copyright 2009-2014 Marc Worrell

Behaviours: gen_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

resource()

resource() = resource_id() | resource_name()

resource_id()

resource_id() = integer() | [digits()]

resource_name()

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

Function Index

common_properties/1Common properties, these are used by exporter and backup routines.
delete/2Delete a resource.
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.
get_raw_lock/2
get_visible/2Read a whole resource, check all properties for access rights.
insert/2Insert a new resource.
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_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.
media/2
merge_delete/3Merge 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
name_to_id_cat_check/3
name_to_id_check/2
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::#context{}) -> ok | {error, term()}

Delete a resource

duplicate/3

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

Duplicate a resource.

ensure_name/2

ensure_name(Id::integer(), Context::#context{}) -> ok

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

exists/2

exists(Id::resource(), Context::#context{}) -> boolean()

get/2

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

Read a whole resource

get_acl_props/2

get_acl_props(Id::resource(), Context::#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::#context{}) -> list()

Get the resource from the database, do not fetch the pivot fields.

get_raw_lock/2

get_raw_lock(Id, Context) -> any()

get_visible/2

get_visible(RId::resource(), Context::#context{}) -> list() | undefined

Read a whole resource, check all properties for access rights

insert/2

insert(Props, Context) -> {ok, Id} | {error, Reason}

Insert a new resource

is_a/2

is_a(Id::resource(), Context::#context{}) -> [atom()]

Return the categories and the inherited categories of the resource. Returns a list with category atoms

is_a/3

is_a(Id::int(), Cat::atom(), Context) -> bool()

Check if the resource is in a category.

is_a_id/2

is_a_id(Id::resource(), Context::#context{}) -> [atom()]

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::#context{}) -> boolean()

Check if the resource is exactly the category

is_deletable/2

is_deletable(Id::resource(), Context::#context{}) -> boolean()

is_editable/2

is_editable(Id::resource(), Context::#context{}) -> boolean()

is_linkable/2

is_linkable(Id::resource(), Context::#context{}) -> boolean()

is_me/2

is_me(Id::resource(), Context::#context{}) -> boolean()

is_visible/2

is_visible(Id::resource(), Context::#context{}) -> boolean()

m_find_value/3

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

Fetch the value for the key from a model source

m_to_list/2

m_to_list(M::#m{}, Context::#context{}) -> list()

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

m_value/2

m_value(M::#m{}, Context::#context{}) -> undefined | any()

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

media/2

media(Id::resource(), Context::#context{}) -> list()

merge_delete/3

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

Merge a resource with another, delete the loser.

name_lookup/2

name_lookup(Name::resource_name(), Context::#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::#context{}) -> {ok, resource_id()} | {error, string()}

Return the id of the resource with the name

name_to_id_cat/3

name_to_id_cat(Name::resource_name(), Cat::resource_name(), Context::any()) -> any()

name_to_id_cat_check/3

name_to_id_cat_check(Name, Cat, Context) -> any()

name_to_id_check/2

name_to_id_check(Name::resource_name(), Context::#context{}) -> resource_id()

o/2

o(Id::resource(), Context::#context{}) -> function()

Used for dereferencing object edges inside template expressions

o/3

o(Id::resource(), Predicate::atom(), Context::#context{}) -> list()

Return the list of objects with a certain predicate

o/4

o(Id::resource(), Predicate::atom(), N::pos_integer(), Context::#context{}) -> resource_id()

op/2

op(Id::resource(), Context::#context{}) -> list()

p/3

p(Id::resource(), Property::atom(), Context::#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, Context) -> any()

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, Context) -> any()

page_url_abs/2

page_url_abs(Id, Context) -> any()

rid/2

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

Fetch a resource id from any input

s/2

s(Id::resource(), Context::#context{}) -> function()

s/3

s(Id::resource(), Predicate::atom(), Context::#context{}) -> list()

s/4

s(Id::resource(), Predicate::atom(), N::pos_integer(), Context::#context{}) -> resource_id()

sp/2

sp(Id::resource(), Context::#context{}) -> list()

touch/2

touch(Id::resource(), Context::#context{}) -> {ok, resource_id()} | {error, Reason::string()}

"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::list(), Context::#context{}) -> {ok, resource()} | {error, term()}

Update a resource

update/4

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

uri_lookup/2

uri_lookup(Uri, Context) -> any()

Return the id of the resource with a certain uri. uri_lookup(string(), Context) -> int() | undefined


Generated by EDoc, Aug 28 2016, 21:06:00.