<?php
namespace app\models\galleries;
use Yii;
use app\models\galleries\GalleryImages;
class Gallery extends \yii\db\ActiveRecord
{
const STATUS_INACTIVE = 0; // неактивный / в пуле
const STATUS_ACTIVE = 10; // активный
const STATUS_PROCESS = 20; // в процессе обработки.
const STATUS_ERROR = 50; // ошибка.
const STATUS_IMPORTED = 80; // импортирован
const STATUS_DELETED = 90; // удален
public static function tableName()
{
return 'gallery';
}
public function rules()
{
return [
[['created_by', 'studio', 'mix', 'images_count', 'status'], 'integer'],
[['created_at', 'published_at'], 'safe'],
[['hash'], 'string', 'max' => 32],
[['title'], 'string', 'max' => 255],
];
}
public function attributeLabels()
{
return [
'g_id' => 'G ID',
'created_by' => 'Created By',
'hash' => 'Hash',
'title' => 'Title',
'studio' => 'Studio',
'mix' => 'Mix',
'images_count' => 'Images Count',
'published_at' => 'Published At',
'created_at' => 'Created At',
];
}
public function getHasImages()
{
return !empty($this->images);
}
public function getImages()
{
return $this->hasMany(GalleryImages::className(), ['g_id' => 'g_id']);
}
public static function getStatuses()
{
return [
self::STATUS_INACTIVE => 'Не активно',
self::STATUS_ACTIVE => 'Активно',
self::STATUS_PROCESS => 'В обработке',
self::STATUS_ERROR => 'Ошибка',
self::STATUS_IMPORTED => 'Импортировано',
self::STATUS_DELETED => 'Удалено',
];
}
public function getColoredStatus()
{
$statuses = [
self::STATUS_INACTIVE => '<span class="text-status brown">Не активно</span>',
self::STATUS_ACTIVE => '<span class="text-status green">Активно</span>',
self::STATUS_PROCESS => '<span class="text-status purple">В обработке</span>',
self::STATUS_ERROR => '<span class="text-status brown">Ошибка</span>',
self::STATUS_IMPORTED => '<span class="text-status orange">Импортировано</span>',
self::STATUS_DELETED => '<span class="text-status brown">Удалено</span>',
];
return isset($statuses[$this->status]) ? $statuses[$this->status] : 'unknown';
}
}