HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Komma/CustomerStories/Models/CustomerStory.php
<?php
/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\CustomerStories\Models;

use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Documents\Models\Document;
use App\Komma\Dynamic\Component\ComponentableInterface;
use App\Komma\Dynamic\Component\ComponentableTrait;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Languages\Models\Language;
use App\Komma\Products\Models\Product;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
 * Class CustomerStory
 *
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Languages\Models\Language[] $languages
 * @property-read \App\Komma\Sites\Models\Site $site
 * @property-read \App\Komma\CustomerStories\Models\CustomerStoryTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\CustomerStories\Models\CustomerStoryTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $site_id
 * @property int $active
 * @property string|null $code_name
 * @property int|null $lft
 * @property int|null $rgt
 * @property int|null $tree
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereCodeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereLft($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereRgt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereSiteId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereTree($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory whereUpdatedAt($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Dynamic\Component\Component[] $components
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\CustomerStories\Models\CustomerStory query()
 */
class CustomerStory extends AbstractTranslatableTreeModel implements DocumentableInterface, DisplayNameInterface, ComponentableInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;
    use ComponentableTrait;

    protected $table = 'customer_stories';

    protected $class = self::class;

    protected $fillable = ['site_id', 'lft', 'rgt', 'tree', 'name', 'slug', 'amount_of_employees', 'site_name', 'site_url'];

    /**
     * Gets the translation models for this model
     *
     * @return HasMany that resolves to AbstractTranslationModel instances
     */
    public function translations(): HasMany
    {
        return $this->hasMany(CustomerStoryTranslation::class);
    }

    public function languages(): BelongsToMany
    {
        return $this->belongsToMany(Language::class, 'customer_story_translations')
            ->withPivot('slug', 'name', 'description')
            ->withTimestamps();
    }

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class, 'customer_story_products');
    }

    /**
     * Get the images through documents belonging to this model
     *
     * @return \Illuminate\Database\Eloquent\Relations\hasMany
     */
    public function impression():MorphMany
    {
        return $this->morphMany(Document::class, 'documentable')
            ->where('mime_type', 'LIKE', 'image/%')
            ->where('key', '=', 'Documents-impression')
            ->orderBy('sort_order');
    }

    /**
     * Get the images through documents belonging to this model
     *
     * @return \Illuminate\Database\Eloquent\Relations\hasMany
     */
    public function logo():MorphMany
    {
        return $this->morphMany(Document::class, 'documentable')
            ->where('mime_type', 'LIKE', 'image/%')
            ->where('key', '=', 'Documents-logo')
            ->orderBy('sort_order');
    }

    public function __get($key)
    {
        if ($key == 'parent_id') {
            if ($this::find($this->id)) {
                return $this->getParentId();
            }
        }

        return parent::__get($key);
    }

    public function socialMediaImage()
    {
        // Check if loaded else load
        if (! isset($this->images)) {
            $this->load('images');
        }

        // Check that there are images
        if (! isset($this->images) || $this->images->isEmpty()) {
            return null;
        }

        // Then grab the translation images
        $socialMediaImage = $this->images->where('key', 'Documents-customerStoryTranslationSocial-'.\App::getLocale());

        // If there are translation images we return those
        if (isset($socialMediaImage) && $socialMediaImage->isNotEmpty()) {
            return $socialMediaImage->first();
        }

        return null;
    }
}