1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76:
<?php
declare(strict_types=1);
namespace App\IqrfAppModule\Forms;
use App\Forms\FormFactory;
use App\IqrfAppModule\Model\IqrfNetManager;
use Nette;
use Nette\Application\UI\Form;
class IqrfNetDiscoveryFormFactory {
use Nette\SmartObject;
private $manager;
private $factory;
public function __construct(FormFactory $factory, IqrfNetManager $manager) {
$this->factory = $factory;
$this->manager = $manager;
}
public function create() {
$form = $this->factory->create();
$form->addInteger('txPower', 'TX Power')->setDefaultValue(6)
->addRule(Form::RANGE, 'TX Power have to be integer from 0 to 7.', [0,7])
->setRequired();
$form->addInteger('maxNode', 'Max. Node Address')->setDefaultValue(239)
->addRule(Form::RANGE, 'Max. Node Address have to be integer form 0 to 239.', [0,239])
->setRequired();
$form->addSubmit('send', 'Discovery');
$form->addProtection('Timeout expired, resubmit the form.');
$form->onSuccess[] = function (Form $form, $values) {
$this->manager->discovery($values['txPower'], $values['maxNode']);
};
return $form;
}
}