<?php
namespace Modules\Admin\Config\Balances\Numbers;

class Controller extends \App\Mvc\Controller\Form\WindowAbstract
{


	protected function getDefaultFormData($R)
	{
		$formData = [];

		$balanceNumberObj = \App\Config\BalanceNumber::getInstance();
		$originalConfigs = $balanceNumberObj->getAll();

		$formData['criteria']		= $originalConfigs['criteria'];
		$formData['numberLength']	= $originalConfigs['numberLength'];
		$formData['prefix']			= $originalConfigs['prefix'];
		$formData['suffix']			= $originalConfigs['suffix'];

		return $formData;
	}


	protected function processFormData(Array $R, \App\MessagesCollector $msgs)
	{
		try {

			$balanceNumberObj = \App\Config\BalanceNumber::getAdmin();
			// collect data for the saving
			$balanceNumberObj->set('criteria',		$R['criteria']);
			$balanceNumberObj->set('numberLength', 	$R['numberLength']);
			$balanceNumberObj->set('prefix',		$R['prefix']);
			$balanceNumberObj->set('suffix',		$R['suffix']);

			// actual save
			$balanceNumberObj->save();

			// success message
			$msgs->addSuccess($this->lang['process']['messages']['success']);

		} catch (\App\Config\MessageException $e) {

			$msgs->addWarning(sprintf($this->lang['process']['messages']['error'], $e->getMessage()));

		}

	}

}