<?php
namespace frontend\components;

use yii\base\Behavior;
use yii\web\Controller;
use common\models\Account;

class DefaultAccountBehavior extends Behavior
{
	// ...

	public function events()
	{
		return [
				Controller::EVENT_BEFORE_ACTION => 'validateDefaultAccount',
		];
	}

	public function validateDefaultAccount($event){
		
		$account = Account::readDefault();
		if ( !isset($account) ){
			$this->owner->redirect([ 'account/select' ]);
			\Yii::$app->session->setFlash ( 'error', 'Válassz kasszát!!');
			$event->isValid = false;
			$event->handled = true;
			return false;
		}
	}
}