<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Testimonial extends Model {
	//

	const ACTIVE = 0;
	const IN_ACTIVE = 1;

	protected $fillable = [
		'image',
		'name',
		'content',
		'status',
		'created_at',
		'updated_at',
		'deleted_at',
		'address'
	];

	protected $dates = [
		'created_at',
		'updated_at',
		'deleted_at'
	];

	public function getStatusTextAttribute()
	{
		$type = $this->attributes['status'];

		if ($type == Testimonial::ACTIVE) {
			return '<label class="label label-success">Đã kích hoạt</label>';
		} else if ($type == Testimonial::IN_ACTIVE) {
			return '<label class="label label-danger">Không kích hoạt</label>';
		}
		return 'Chưa rõ';
	}

	public function getImageTextAttribute()
	{
		$item = $this->attributes['image'];

		if(!empty($item))
		{
			return '<img src="/files/'.$item.'" style="max-width: 100px"/>';
		}
		return '<img src="/frontend3/assets/img/placeholder.png" style="max-width: 100px" />';
	}

	public function scopePublish($q)
	{
		$q->where('status', Testimonial::ACTIVE);
	}
}
