%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/diaspora/api_internal/app/Models/
Upload File :
Create Path :
Current File : /var/www/html/diaspora/api_internal/app/Models/Country.php

<?php

namespace App\Models;

use Dimsav\Translatable\Translatable;

/**
 * @property integer id
 * @property string iso_2
 * @property boolean is_enabled
 * @property string name
 * @property string travel_precaution
 * @property mixed sections
 * @property boolean has_notifications
 */
class Country extends BaseModel
{
    use Translatable;

    const DO_NOT_TRAVEL = 'DO_NOT_TRAVEL';
    const HIGH_CAUTION = 'HIGH_CAUTION';
    const NORMAL_PRECAUTION = 'NORMAL_PRECAUTION';

    public $timestamps           = false;
    public $translatedAttributes = [
        'name',
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'iso_2',
        'travel_precaution',
        'is_enabled',
    ];

    protected $casts = [
        'id'                => 'integer',
        'iso_2'             => 'string',
        'travel_precaution' => 'string',
        'is_enabled'        => 'boolean',
    ];

    /**
     * @return $this
     */
    public function enable()
    {
        $this->is_enabled = true;
        $this->save();
        return $this;
    }

    /**
     * @return $this
     */
    public function disable()
    {
        $this->is_enabled = false;
        $this->save();
        return $this;
    }

    public function appSections()
    {
        return $this->sections()
                    ->where('is_visible', true)
                    ->get();
    }

    public function sections()
    {
        return $this->hasMany(Section::class)
                    ->orderBy('order');
    }

    public function canBeEnabled()
    {
        return $this->travel_precaution && $this->sections()
                                                ->where('is_visible', true)
                                                ->has('translations', 2)
                                                ->exists();
    }

    public function hasConfiguration($uuid)
    {
        /** @var Device $device */
        $device = Device::query()
                        ->where("uuid", $uuid)
                        ->first();
        if (!$device) {
            return false;
        }
        return $device->configurations()
                      ->where('country_id', $this->id)
                      ->exists();
    }

}



Zerion Mini Shell 1.0