<?php

namespace App\Entities;

class ProductEntity extends BaseEntity
{
    protected $datamap = [];
    protected $dates   = ['created_at', 'updated_at', 'deleted_at'];
    protected $casts   = [];

    //기본기능
    public function getTitle(): string
    {
        return $this->attributes['name'];
    }
    //추가기능
    //이미지관련 Field전용
    final public function getFileImage($size = false, $field = "photo")
    {
        if (is_null($this->attributes[$field])) {
            return "";
        }
        $files = explode(DEFAULTS['DELIMITER_FILE'], $this->attributes[$field]);
        return sprintf(
            "<img src=\"/upload_images/%s%s\" alt=\"%s\">",
            $size ? $size . '_' : '',
            $files[1],
            $files[0]
        );
    }
}
