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