add basic event objects
This commit is contained in:
79
common/models/EventType.php
Normal file
79
common/models/EventType.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "event_type".
|
||||
*
|
||||
* @property integer $id
|
||||
* @property string $name
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class EventType extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'event_type';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'required'],
|
||||
[['name'], 'unique'],
|
||||
[['name'], 'string', 'max' => 255]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => Yii::t('event-type', 'ID'),
|
||||
'name' => Yii::t('event-type', 'Name'),
|
||||
'created_at' => Yii::t('event-type', 'Created At'),
|
||||
'updated_at' => Yii::t('event-type', 'Updated At'),
|
||||
];
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function(){ return date('Y-m-d H:i:s' ); }
|
||||
]
|
||||
],
|
||||
parent::behaviors());
|
||||
}
|
||||
|
||||
public function asOptions(){
|
||||
$items = ArrayHelper::map(EventType::find()->all(),'id','name');
|
||||
return ArrayHelper::merge(['' => \Yii::t('event-type','All')],$items);
|
||||
}
|
||||
|
||||
public static function eventTypeOptions($all = false, $emptyString = false){
|
||||
$items = ArrayHelper::map(EventType::find()->all(),'id','name');
|
||||
$extra = [];
|
||||
if ( $all ) {
|
||||
$extra = ['' => \Yii::t('event-type','All')];
|
||||
}
|
||||
if ( $emptyString ) {
|
||||
$extra = ['' => '' ];
|
||||
}
|
||||
return ArrayHelper::merge($extra,$items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user