-
-
Save anonymous/643db60d229b9488257e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Form\Invoice; | |
use Achse\NetteDatabase\EntityAlreadyExistsException; | |
use App\Exceptions\NoActivitiesException; | |
use App\Exceptions\SignatureFileNotFoundException; | |
use App\Facade\InvoicePresenterFacade; | |
use App\Form; | |
use App\Model\UserRepository; | |
use Nette\InvalidStateException; | |
use Nette\Security\User; | |
use Nette\Utils\DateTime; | |
class ApplyInvoiceForm extends Form\FormControl { | |
/** @var callable[] */ | |
public $onSignatureFileNotFound = []; | |
/** @var callable[] */ | |
public $onNoActivities = []; | |
/** @var callable[] */ | |
public $onEntityAlreadyExists = []; | |
/** @var callable[] */ | |
public $onInvalidState = []; | |
/** @var callable[] */ | |
public $onSuccess; | |
protected $limit; | |
/** @var User */ | |
protected $user; | |
/** @var InvoicePresenterFacade */ | |
protected $invoicePresenterFacade; | |
function __construct(User $user, InvoicePresenterFacade $invoicePresenterFacade) { | |
$this->user = $user; | |
$this->invoicePresenterFacade = $invoicePresenterFacade; | |
} | |
/** | |
* @param $parent | |
* @param $name | |
* @return Form | |
*/ | |
public function createComponentForm($parent, $name) { | |
$form = new Form($parent, $name); | |
// $form->... | |
$form->addSubmit("send", "Potvrdit"); | |
$this->onSuccess[] = $this->process; | |
$form->onSuccess = $this->onSuccess; | |
$form->setDefaults(array(/** preset **/)); | |
return $form; | |
} | |
public function process(ApplyInvoiceForm $form) { | |
if ($form->isValid()) { | |
$values = $form->getValues(); | |
try { | |
$this->invoicePresenterFacade->applyInvoice($values, $this->user, $this->limit); | |
} catch (SignatureFileNotFoundException $e) { | |
$form->onSignatureFileNotFound($e); | |
} catch (NoActivitiesException $e) { | |
$this->onNoActivities($e); | |
} catch (EntityAlreadyExistsException $e) { | |
$this->onEntityAlreadyExists($e); | |
} catch (InvalidStateException $e) { | |
$this->onInvalidState($e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment