Skip to content
Andrey Kharanenka edited this page Dec 16, 2019 · 4 revisions

Components

ArticlePage component

It allows working with the ArticleItem class objects.

The ArticlePage class is extended from the ElementPage class.

Usage example:

[ArticlePage]
slug = "{{ :slug }}"
slug_required = 1
==

{# Get an article item #}
{% set obArticle = ArticlePage.get() %}
<div data-id="{{ obArticle.id }}">
    <h1>{{ obArticle.title }}</h1>
    <span>{{ obArticle.published_start.format('F d, Y') }}</span>
    {% if obArticle.preview_image is not empty %}
        <img src="{{ obArticle.preview_image.path }}" title="{{ obArticle.preview_image.title }}" alt="{{ obArticle.preview_image.description }}">
    {% endif %}
    <div>{{ obArticle.content|raw }}</div>
</div>

ArticleData component

It allows working with the ArticleItem class objects.

The ArticleData class is extended from ElementData class.

Usage example:

{# Get an article item with ID = 10 #}
{% set obArticle = ArticleData.get(10) %}
{% if obArticle.isNotEmpty() %}
    <div data-id="{{ obArticle.id }}">
        <h2>{{ obArticle.title }}</h2>
        <span>{{ obArticle.published_start.format('F d, Y') }}</span>
        {% if obArticle.preview_image is not empty %}
            <img src="{{ obArticle.preview_image.path }}" title="{{ obArticle.preview_image.title }}" alt="{{ obArticle.preview_image.description }}">
        {% endif %}
        <div>{{ obArticle.content|raw }}</div>
    </div>
{% endif %}

ArticleList component

It allows working with the ArticleCollection class objects.

Method list

make($arElementIDList = null)

Usage example (render article list):

Get a collection of articles, apply sorting + filter by published status.

{% set obArticleList = ArticleList.make().sort('publish|desc').published() %}
{% if obArticleList.isNotEmpty() %}
    <div class="article-list-wrapper">
        {% for obArticle in obArticleList %}
            <div data-id="{{ obArticle.id }}">
                <h2>{{ obArticle.title }}</h2>
                <span>{{ obArticle.published_start.format('F d, Y') }}</span>
                {% if obArticle.preview_image is not empty %}
                    <img src="{{ obArticle.preview_image.path }}" title="{{ obArticle.preview_image.title }}" alt="{{ obArticle.preview_image.description }}">
                {% endif %}
                <div>{{ obArticle.preview_text }}</div>
            </div>
        {% endfor %}
    </div>
{% endif %}

Get an article collection, apply sorting + filter by published status + Pagination component.

{# Get an article collection #}
{% set obArticleList = ArticleList.make().sort('publish|desc').published() %}

{# Get an array with pagination buttons #}
{% set iPage = Pagination.getPageFromRequest() %}
{% set arPaginationList = Pagination.get(iPage, obArticleList.count()) %}

{# Apply a pagination to the article collection and get an array with article items #}
{% set arArticleList = obArticleList.page(iPage, Pagination.getCountPerPage()) %}

{% if arArticleList is not empty %}

    {# Render the article list #}
    <div class="article-list-wrapper">
        {% for obArticle in arArticleList %}
            <div data-id="{{ obArticle.id }}">
                <h2>{{ obArticle.title }}</h2>
                <span>{{ obArticle.published_start.format('F d, Y') }}</span>
                {% if obArticle.preview_image is not empty %}
                    <img src="{{ obArticle.preview_image.path }}" title="{{ obArticle.preview_image.title }}" alt="{{ obArticle.preview_image.description }}">
                {% endif %}
                <div>{{ obArticle.preview_text }}</div>
            </div>
        {% endfor %}
    </div>
    
    {# Render the pagination buttons #}
    {% if arPaginationList is not empty %}
        {% for arPagination in arPaginationList %}
            <a href="/{{ arPagination.value }}" class="{{ arPagination.class }}">{{ arPagination.name }}</a>
        {% endfor %}
    {% endif %}
{% endif %}

ArticleCategoryPage component

It allows working with the CategoryItem class objects.

The ArticleCategoryPage class is extended from the ElementPage class.

Usage example:

[ArticleCategoryPage]
slug = "{{ :slug }}"
slug_required = 1
==

{# Get a category item #}
{% set obCategory = ArticleCategoryPage.get() %}
<div data-id="{{ obCategory.id }}">
    <h1>{{ obCategory.name }}</h1>
    {% if obCategory.preview_image is not empty %}
        <img src="{{ obCategory.preview_image.path }}" title="{{ obCategory.preview_image.title }}" alt="{{ obCategory.preview_image.description }}">
    {% endif %}
    <div>{{ obCategory.description|raw }}</div>
    {% if obCategory.children.isNotEmpty() %}
        <ul>
            {% for obChildCategory in obCategory.children %}
                <li>{{ obChildCategory.name }}</li>
            {% endfor %}
        </ul>
    {% endif %}
</div>

ArticleCategoryData component

It allows working with the CategoryItem class objects.

The ArticleCategoryData class is extended from the ElementData class.

Usage example:

{# Get a category item with ID = 10 #}
{% set obCategory = ArticleCategoryData.get(10) %}
{% if obCategory.isNotEmpty() %}
    <div data-id="{{ obCategory.id }}">
        <h2>{{ obCategory.name }}</h2>
        {% if obCategory.preview_image is not empty %}
            <img src="{{ obCategory.preview_image.path }}" title="{{ obCategory.preview_image.title }}" alt="{{ obCategory.preview_image.description }}">
        {% endif %}
        <div>{{ obCategory.description|raw }}</div>
        {% if obCategory.children.isNotEmpty() %}
            <ul>
                {% for obChildCategory in obCategory.children %}
                    <li>{{ obChildCategory.name }}</li>
                {% endfor %}
            </ul>
        {% endif %}
    </div>
{% endif %}

ArticleCategoryList component

It allows working with the CategoryCollection class objects.

Method list

make($arElementIDList = null)

Usage example (render of the category list):

Get a tree of categories. An example is used in the render of the category menu.

{% set obCategoryList = ArticleCategoryList.make().tree() %}
{% if obCategoryList.isNotEmpty() %}
    <ul class="category-menu-wrapper">
        {% for obCategory in obCategoryList %}
            <li data-id="{{ obCategory.id }}">{{ obCategory.name }}
                {% if obCategory.children.isNotEmpty() %}
                    <ul class="category-child-menu-wrapper">
                        {% for obChildCategory in obCategory.children %}
                            <li>{{ obChildCategory.name }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endif %}

ArticleCollection class

It allows working with a cached list of articles.

The ArticleCollection class is extended from the ElementCollection class and returns arrays of the ArticleItem class objects.

Method list

sort($sSorting)

It sorts the elements of a collection by the $sSorting values:

  • no β€” by ID (default);
  • publish|asc β€” by publishing date (ascending);
  • publish|desc β€” by publishing date (descending);
  • view|asc β€” by number of views (ascending);
  • view|desc β€” by number of views (descending).

Usage example:

    $obList = ArticleCollection::make([1,2,10,15])->sort('publish|desc');

published()

It applies a filter by publishing status and publish the date for the elements of a collection.

Usage example:

    $obList = ArticleCollection::make([1,2,10,15])->published();

category($iCategoryID, $bWithChildren = false)

It applies a filter by the $iCategoryID values:

  • $iCategoryID β€” article category ID or array with IDs of the categories;
  • $bWithChildren β€” flag, if equals true, then method returns the list of the articles for category with $iCategoryID + articles of children categories.

Usage examples:

    $obList = ArticleCollection::make()->category(2);
    $obList = ArticleCollection::make()->category(2, true);
    $obList = ArticleCollection::make()->category([2, 5, 6]);
    $obList = ArticleCollection::make()->category([2, 5, 6], true);

CategoryCollection class

It allows working with a cached list of the categories.

The CategoryCollection class is extended from ElementCollection class and returns arrays of the CategoryItem class objects.

Method list

tree()

It returns the category list of the top level (only active categories).

Usage example:

    $obList = CategoryCollection::make()->tree();

active()

It applies a filter to the field active in the state true for the elements of a collection.

Usage example:

    $obList = CategoryCollection::make([1,2,10,15])->active();

ArticleItem class

It allows working with a cached data array of the Article model.

The ArticleItem class is extended from the ElementItem class.

Field list

  • (int) id
  • (string) status_id
  • (string) title
  • (string) slug
  • (\October\Rain\Argon\Argon) published_start
  • (\October\Rain\Argon\Argon) published_stop
  • (\October\Rain\Argon\Argon) created_at
  • (\October\Rain\Argon\Argon) updated_at
  • (string) preview_text
  • \System\Models\File preview_image
  • (string) content
  • \System\Models\File[] images
  • (int) view_count
  • (int) category_id
  • CategoryItem category β€” object of parent category

CategoryItem class

It allows working with a cached data array of the Category model.

The CategoryItem class is extended from the ElementItem class.

Field list

  • (int) id
  • (string) name
  • (string) slug
  • (string) code
  • (string) preview_text
  • \System\Models\File preview_image
  • (string) description
  • \System\Models\File[] images
  • (int) nest_depth
  • (int) parent_id
  • CategoryItem parent β€” object of the parent category
  • (array) children_id_list β€” array with the active children category ID list
  • CategoryCollection children β€” collection with the active children category