TimestampBehavior::className(), 'value' => function(){ return date('Y-m-d H:i:s' ); } ] ]; } /** * @inheritdoc */ public function rules() { return [ [['name', 'type'], 'required'], [['name', ], 'unique'], [['status', 'type'], 'integer'], [['name'], 'string', 'max' => 64] ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id_account' => Yii::t('common/account', 'Id Account'), 'name' => Yii::t('common/account', 'Name'), 'status' => Yii::t('common/account', 'Status'), 'type' => Yii::t('common/account', 'Type'), 'created_at' => Yii::t('common/account', 'Created At'), 'updated_at' => Yii::t('common/account', 'Updated At'), ]; } static function statuses() { return [ self::STATUS_ACTIVE => Yii::t('common/account', 'Active'), self::STATUS_DELETED => Yii::t('common/account', 'Inactive'), ]; } public function getStatusHuman(){ $result = null; $s = self::statuses($this->status); if ( array_key_exists($this->status, $s)){ $result = $s[$this->status]; } return $result; } static function types() { return [ self::TYPE_ALL => Yii::t('common/account', 'Visible for all'), self::TYPE_VALUE_HIDDEN => Yii::t('common/account', 'Only the name is visible'), ]; } public function getTypeHuman(){ $result = null; $s = self::types($this->type); if ( array_key_exists($this->type, $s)){ $result = $s[$this->type]; } return $result; } public function isInactive(){ return $this->status == self::STATUS_DELETED; } /** * $param int $forceIncludeAccount id account, that should be included in list, even if it is inactive * */ public static function readAccounts($forceIncludeAccount = null){ $accounts = null; if ( $forceIncludeAccount == null){ $accounts = Account::find()->andWhere(['status' => Account::STATUS_ACTIVE])->all(); }else{ $accounts = Account::find()->andWhere( ['or', ['status' => Account::STATUS_ACTIVE], ['id_account' => $forceIncludeAccount ] ])->all(); } return $accounts; } }