ScalesCms.Cms.CmsPages
(scales_cms v0.2.0)
Copy Markdown
The Cms context.
Summary
Functions
Applies sorting to a query based on the given column and order.
Returns an %Ecto.Changeset{} for tracking cms_page changes.
Counts pages with optional query and status filters. Used for pagination calculation.
Counts pages for a directory with optional query and status filters. Used for pagination calculation.
Creates a cms_page.
Deletes a cms_page.
Fetches pages with optional query, status filters, and sorting. Used for root-level page listing.
Fetches pages for a directory with optional query, status filters, and sorting.
Fetches a slice of directory pages using offset/limit. Used by CmsListing for combined pagination.
Fetches a slice of root pages using offset/limit. Used by CmsListing for combined pagination.
Fetches paginated pages with optional query, status filters, and sorting. Used for root-level page listing with pagination.
Fetches paginated pages for a directory with optional query, status filters, and sorting.
Gets a single cms_page.
Returns the list of cms_pages.
Returns the list of cms_pages filtered by status.
Returns the list of cms_pages within a directory.
Returns the list of cms_pages within a directory filtered by status.
Returns the list of all paginated cms_pages.
Returns the list of paginated cms_pages.
Checks if a page is published (has at least one published variant).
Returns the root list of searched pages.
Returns the list of searched pages filtered by status.
Returns the list of cms_pages within a directory.
Returns the list of cms_pages within a directory filtered by search and status.
Updates a cms_page.
Functions
Applies sorting to a query based on the given column and order.
Parameters
query- The Ecto query to sortsort_by- Column to sort by: "created", "views", or "status"sort_order- Sort direction: "asc" or "desc" (default: "asc")
Examples
iex> apply_sorting(query, "created", "desc")
#Ecto.Query<...>
Returns an %Ecto.Changeset{} for tracking cms_page changes.
Examples
iex> change_cms_page(cms_page)
%Ecto.Changeset{data: %CmsPage{}}
Counts pages with optional query and status filters. Used for pagination calculation.
Examples
iex> count_pages("", "")
42
Counts pages for a directory with optional query and status filters. Used for pagination calculation.
Examples
iex> count_pages_for_directory(123, "", "")
15
Creates a cms_page.
Examples
iex> create_cms_page(%{field: value})
{:ok, %CmsPage{}}
iex> create_cms_page(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Deletes a cms_page.
Examples
iex> delete_cms_page(cms_page)
{:ok, %CmsPage{}}
iex> delete_cms_page(cms_page)
{:error, %Ecto.Changeset{}}
Fetches pages with optional query, status filters, and sorting. Used for root-level page listing.
Options
:sort_by- Column to sort by: "created", "views", or "status":sort_order- Sort direction: "asc" or "desc" (default: "asc")
Examples
iex> fetch_pages("", "")
[%CmsPage{}, ...]
iex> fetch_pages("search term", "published", sort_by: "views", sort_order: "desc")
[%CmsPage{}, ...]
Fetches pages for a directory with optional query, status filters, and sorting.
Options
:sort_by- Column to sort by: "created", "views", or "status":sort_order- Sort direction: "asc" or "desc" (default: "asc")
Examples
iex> fetch_pages_for_directory(123, "", "")
[%CmsPage{}, ...]
iex> fetch_pages_for_directory(123, "search term", "published", sort_by: "created", sort_order: "asc")
[%CmsPage{}, ...]
Fetches a slice of directory pages using offset/limit. Used by CmsListing for combined pagination.
Fetches a slice of root pages using offset/limit. Used by CmsListing for combined pagination.
Fetches paginated pages with optional query, status filters, and sorting. Used for root-level page listing with pagination.
Options
:sort_by- Column to sort by: "created", "views", or "status":sort_order- Sort direction: "asc" or "desc" (default: "asc")
Examples
iex> fetch_paginated_pages("", "", 1, 20)
[%CmsPage{}, ...]
Fetches paginated pages for a directory with optional query, status filters, and sorting.
Options
:sort_by- Column to sort by: "created", "views", or "status":sort_order- Sort direction: "asc" or "desc" (default: "asc")
Examples
iex> fetch_paginated_pages_for_directory(123, "", "", 1, 20)
[%CmsPage{}, ...]
Gets a single cms_page.
Raises Ecto.NoResultsError if the Cms page does not exist.
Examples
iex> get_cms_page!(123)
%CmsPage{}
iex> get_cms_page!(456)
** (Ecto.NoResultsError)
Returns the list of cms_pages.
Examples
iex> list_cms_pages()
[%CmsPage{}, ...]
Returns the list of cms_pages filtered by status.
Examples
iex> list_cms_pages("published")
[%CmsPage{}, ...]
Returns the list of cms_pages within a directory.
Examples
iex> list_pages_for_directory_id(23)
[%CmsPage{}, ...]
Returns the list of cms_pages within a directory filtered by status.
Examples
iex> list_pages_for_directory_id(23, "published")
[%CmsPage{}, ...]
Returns the list of all paginated cms_pages.
Examples
iex> list_paginated_cms_pages(1, 25)
[%CmsPage{}, ...]
Returns the list of paginated cms_pages.
Examples
iex> list_paginated_cms_pages(1, 25)
[%CmsPage{}, ...]
Checks if a page is published (has at least one published variant).
Returns the root list of searched pages.
Examples
iex> list_pages_for_directory_id("Page title")
[%CmsPage{}, ...]
Returns the list of searched pages filtered by status.
Examples
iex> search_cms_pages("Page title", "published")
[%CmsPage{}, ...]
Returns the list of cms_pages within a directory.
Examples
iex> search_cms_pages_for_directory_id(23, "search term")
[%CmsPage{}, ...]
Returns the list of cms_pages within a directory filtered by search and status.
Examples
iex> search_cms_pages_for_directory_id(23, "Page title", "published")
[%CmsPage{}, ...]
Updates a cms_page.
Examples
iex> update_cms_page(cms_page, %{field: new_value})
{:ok, %CmsPage{}}
iex> update_cms_page(cms_page, %{field: bad_value})
{:error, %Ecto.Changeset{}}