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

delete/2Delete a resource.
duplicate/3Duplicate a resource.
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_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_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
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/2
o/3
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.
uri_lookup/2Return the id of the resource with a certain uri.

Function Details

delete/2

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

Delete a resource

duplicate/3

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

Duplicate a resource.

exists/2

exists(Id, Context) -> any()

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

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

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::int(), Context) -> list()

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::int(), Context) -> list()

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

is_cat/3

is_cat(Id, Cat, Context) -> any()

Check if the resource is exactly the category

is_deletable/2

is_deletable(Id, Context) -> any()

is_editable/2

is_editable(Id, Context) -> any()

is_me/2

is_me(Id, Context) -> any()

is_visible/2

is_visible(Id, Context) -> any()

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

name_lookup/2

name_lookup(Name, Context) -> any()

Return the id of the resource with a certain unique name. name_lookup(Name, Context) -> int() | undefined

name_to_id/2

name_to_id(Name::NameString, Context) -> {ok, int()} | {error, Reason}

Return the id of the resource with the name

name_to_id_cat/3

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

o/2

o(Id, Context) -> any()

o/3

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

o/4

o(Id, Predicate, N, Context) -> any()

op/2

op(Id, Context) -> any()

p/3

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

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

Fetch a resource id from any input

s/2

s(Id, Context) -> any()

s/3

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

s/4

s(Id, Predicate, N, Context) -> any()

sp/2

sp(Id, Context) -> any()

touch/2

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

"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, Props, Context) -> {ok, Id} | {error, Reason}

Update a resource

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, Nov 26 2014, 15:39:35.