<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

class Mailbox extends ActiveRecord
{


	public static function tableName()
	{
		return 'mailbox';
	}

	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		
		return array(
			[['username','password','local_part'], 'required'],
			//[['quota'],'number'],
			[['name','maildir','domain','created','modified','password_expiry','active'],'safe'],
			//[[username, name, maildir, quota, local_part, domain], 'safe', 'on'=>'search'],
		);

	}

	public function beforeSave( $insert )
	{

		if (!parent::beforeSave($insert)) {
        return false;
	    }

		if( empty($this->modified) ) $this->modified = $this->created;
		if( $this->name==null ) 	 $this->name = "";
		if( empty($this->quota) ) 	 $this->quota = 1024 * 1000000;

		return true;
	}

	public function afterFind()
	{
		//unset($this->password);
		unset($this->name);
		unset($this->quota);
		unset($this->quota_usage);
		unset($this->quota_usage_date);
		unset($this->local_part);
	}
	
}

?>