Articles

Articles Index

To get started with the articles first check the Articles model located at: app/Models/Article.php.

The Form component and it’s view are responsible for rendering the article main article form used to set article status, image, start/end date and to assign it to products/newspapers. app/Http/Livewire/Articles/Form.php
resources/views/livewire/articles/form.blade.php

The Page component and it’s view are responsible for rendering the main page for listing/navigating/filtering the current articles in the system
app/Http/Livewire/Articles/Page.php
resources/views/livewire/articles/page.blade.php

The Edit component and it’s view are responsible for rendering the editing view of the article (grapesjs editor, pdf cropping, ads tab, etc).
app/Http/Livewire/Articles/Edit.php
resources/views/livewire/articles/edit.blade.php

Statuses

Each article has a specific status which controls whether or not they’re being displayed in their integration. The field in database table is status and is numeric The list of statuses can be found in config/articles.php. The key of the array is the number of the status.

Currently available statuses:

    'statuses' => [
        1 => 'New',
        2 => 'W/A',
		3 => 'Done',
        4 => 'Online',
        5 => 'Expired'
    ],

To work with statuses in more convenient way we’re using the getStatus($statusLabel) method from the Article’s model. Example:

// get online status
$onlineStatus = Article::getStatus('online');
$expiredStatus = Article::getStatus('expired');

In order for the article to be seen in the integration it must be in status online.

Assigning to integration

Each article can assigned to multiple integrations through the table article_product in the database. However an article can also have a primary newspaper and primary integration. The fields for them are located in the article’s table and are called primary_newspaper_id for the main newspaper this article is created and primary_product_id for the main integration. However at the moment we’re also adding the primary product id also in the products table along with the secondary products (if any) to avoid missing a product when we implement logics.
We have defined the following eloquent relations to work properly with the products:

    /** 
    *  $article->products will hold all of the products the article is assigned to
     * Get the Products that belong to the Article.
     */
    public function products() {
        return $this->belongsToMany('App\Models\Product');
    }

    /**
     * $article->product will also have the first product the article is assigned to
     * Get the primary Product for the Article.
     */
    public function product() {
        return $this->products->sortBy('primary_key')->first();
    }

    /**
     * $article->newspaper will hold the newspaper the article is assigned to
     * 
     */
    public function newspaper() {
        return $this->belongsTo('App\Models\Newspaper', 'primary_newspaper_id');
    }


    /**
     * 
     * $article->primaryProduct will be the product which we have defined the primary_product_id field
     */ 
    public function primaryProduct() {
        return $this->belongsTo('App\Models\Product', 'primary_product_id');
    }

Images

Details of the image handling in the system here

The id of the image of the article is defined in hubpage_image_id field and the eloquent relation to access this image is

    public function hubpageImage() {
        return $this->belongsTo(Image::class, 'hubpage_image_id');
    }

This means that you can always access the image via

$article->hubpageImage->getUrl()

Whenever you need a thumbnail of the main image you will use getBlurredImageUrl() method, which is getting the url of the main image from the above relation and it’s passing it to our custom defined function createImageUrl defined in helpers/functions.php. Check the definition for more details.

    public function getBlurredImageUrl() {
        return $this->hubpageImage ? createImageUrl($this->hubpageImage->getUrl(), 'trmblurred', 'thumbnail') : null;
    }

HTML/CSS Contents

The main article content created in the editor is saved directly as a .html file. Those files are located in storage/app/articles/[article-id].html and the specific styling for the article (if any) is at: storage/app/articles/[article-id].css. The following method is used to get the html:

    public static function getHtml($articleId);

    //Example:
    Article::getHtml($article->id);