Achievement model. Achievement CRUD pages. Achievements at sidebar

This commit is contained in:
Korzinkayablok
2021-09-08 17:44:54 +03:00
parent 415d8e4ee9
commit 3885f8771b
14 changed files with 658 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "achievement".
*
* @property int $id
* @property string $slug
* @property string $title
* @property string $img
* @property string $description
* @property integer $status
*/
class Achievement extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_DISABLE = 2;
public static function getStatusLabel():array
{
return [
self::STATUS_ACTIVE => 'Активна',
self::STATUS_DISABLE => 'Не активна'
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'achievement';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'slug'], 'required'],
[['status'], 'integer'],
[['slug', 'title'], 'string', 'max' => 255],
[['description', 'img'], 'string'],
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'slug' => 'Slug',
'description' => 'Описание',
'status' => 'Статус',
'img' => 'Изображение',
];
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "user_card_accesses".
*
* @property int $id
* @property int $user_card_id
* @property int $achievement
*
* @property Accesses $accesses
* @property UserCard $userCard
*/
class AchievementUserCard extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'achievement_user_card';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_card_id', 'achievement_id'], 'integer'],
[['achievement_id'], 'exist', 'skipOnError' => true, 'targetClass' => Achievement::className(), 'targetAttribute' => ['achievement_id' => 'id']],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'achievement_id' => 'Achievement ID',
'user_card_id' => 'User Card ID',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAchievement()
{
return $this->hasOne(Achievement::className(), ['id' => 'achievement_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUserCard()
{
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
}
}