| Current Path : /var/www/html/biosecurity/backend/modules/cryptoaverage/models/ |
| Current File : /var/www/html/biosecurity/backend/modules/cryptoaverage/models/CryptoParameter.php |
<?php
namespace backend\modules\cryptoaverage\models;
use Yii;
/**
* This is the model class for table "crypto_parameter".
*
* @property int $id
* @property int $userid
* @property string $name
* @property string $code
* @property string $key
* @property string $value
* @property int $status
* @property int $multiple
*/
class CryptoParameter extends \yii\db\ActiveRecord
{
/**
* Type of parameter
* @var array
*/
public $type = [
'API_KEY' => 'API KEY',
'API_SECRET' => 'API SECRET',
'SYMBOL' => 'SYMBOL',
];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'crypto_parameter';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['userid', 'status', 'multiple'], 'integer'],
[['name', 'code', 'value'], 'required'],
[['name', 'code'], 'string', 'max' => 250],
[['key', 'value'], 'string', 'max' => 500],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'userid' => Yii::t('app', 'Userid'),
'name' => Yii::t('app', 'Name'),
'code' => Yii::t('app', 'Code'),
'key' => Yii::t('app', 'Key'),
'value' => Yii::t('app', 'Value'),
'status' => Yii::t('app', 'Status'),
'multiple' => Yii::t('app', 'Multiple'),
];
}
/**
* Get all symbol
*
* @return array|\yii\db\ActiveRecord[]
*/
public static function getSymbol()
{
$symbolArr = [];
$symbol = self::find()->where([
'code' => 'SYMBOL'
])
->asArray()
->all();
array_walk($symbol, function ($v) use (&$symbolArr) {
$symbolArr[$v['key']] = $v['value'];
});
return $symbolArr;
}
/**
* {@inheritDoc}
* @see \yii\db\BaseActiveRecord::beforeSave()
*/
public function beforeSave($insert) {
$this->userid = Yii::$app->user->id;
if(empty($this->key)) {
$this->key = $this->code;
}
if($this->code != 'SYMBOL') {
$this->multiple = 0;
} else {
$this->multiple = 1;
}
return parent::beforeSave($insert);
}
}