Completed
Pull Request — master (#102)
by Litera
10:11 queued 01:46
created

RegistrationForm::fetchMeals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
1
<?php
2
3
namespace App\Components\Forms;
4
5
use DateTime;
6
use App\Components\BaseControl;
7
use App\Models\ProvinceModel;
8
use App\Models\ProgramModel;
9
use App\Models\BlockModel;
10
use App\Models\MealModel;
11
use App\Models\MeetingModel;
12
use Nette\Application\UI\Form;
13
use Nette\Forms\Controls;
14
use App\Services\UserService;
15
16
class RegistrationForm extends BaseForm
17
{
18
19
	const TEMPLATE_NAME = 'RegistrationForm';
20
21
	const MESSAGE_REQUIRED = 'Hodnota musí být vyplněna!';
22
	const MESSAGE_MAX_LENGTH = '%label nesmí mít více jak %d znaků!';
23
24
	/**
25
	 * @var Closure
26
	 */
27
	public $onRegistrationSave;
28
29
	/**
30
	 * @var ProvinceModel
31
	 */
32
	protected $provinceModel;
33
34
	/**
35
	 * @var ProgramModel
36
	 */
37
	protected $programModel;
38
39
	/**
40
	 * @var BlockModel
41
	 */
42
	protected $blockModel;
43
44
	/**
45
	 * @var  MeetingModel
46
	 */
47
	protected $meetingModel;
48
49
	/**
50
	 * @var array
51
	 */
52
	protected $mealFields = [];
53
54
	/**
55
	 * @var array
56
	 */
57
	protected $programFields = [];
58
59
	/**
60
	 * @var UserService
61
	 */
62
	protected $userService;
63
64
	/**
65
	 * @param ProvinceModel $model
0 ignored issues
show
Bug introduced by
There is no parameter named $model. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
66
	 */
67
	public function __construct(
68
		ProvinceModel $province,
69
		ProgramModel $program,
70
		BlockModel $block,
71
		MeetingModel $meeting,
72
		UserService $user
73
	) {
74
		$this->setProvinceModel($province);
75
		$this->setProgramModel($program);
76
		$this->setBlockModel($block);
77
		$this->setMeetingModel($meeting);
78
		$this->setUserService($user);
79
	}
80
81
	/**
82
	 * @return void
83
	 */
84
	public function render()
85
	{
86
		$this->setMealFields();
87
		$this->setProgramFields();
88
89
		$template = $this->getTemplate();
90
		$template->setFile($this->buildTemplatePath());
91
		$template->meals = $this->getMealFields();
0 ignored issues
show
Bug introduced by
Accessing meals on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
92
		$template->programs = $this->getProgramFields();
0 ignored issues
show
Bug introduced by
Accessing programs on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
93
		$template->render();
94
	}
95
96
	/**
97
	 * @param  array $defaults
98
	 * @return RegistrationForm
99
	 */
100
	public function setDefaults(array $defaults = []): RegistrationForm
101
	{
102
		$this['registrationForm']->setDefaults($defaults);
103
104
		return $this;
105
	}
106
107
	/**
108
	 * @return Form
109
	 */
110
	public function createComponentRegistrationForm(): Form
111
	{
112
		$provinces = $this->getProvinceModel()->all();
113
114
		$form = new Form;
115
116
		$form->addText('name', 'Jméno:')
117
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
118
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
119
			->getLabelPrototype()->setAttribute('class', 'required');
120
		$form->addText('surname', 'Příjmení:')
121
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
122
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
123
			->getLabelPrototype()->setAttribute('class', 'required');
124
		$form->addText('nick', 'Přezdívka:')
125
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
126
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20)
127
			->getLabelPrototype()->setAttribute('class', 'required');
128
		$form->addEmail('email', 'E-mail:')
129
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
130
			->getLabelPrototype()->setAttribute('class', 'required');
131
		$form->addTbDatePicker('birthday', 'Datum narození:', null, 16)
132
			->setRequired(static::MESSAGE_REQUIRED)
133
			->setFormat('d. m. Y')
134
			->setAttribute('placeholder', 'dd. mm. rrrr')
135
			->getLabelPrototype()->setAttribute('class', 'required');
136
		$form->addText('street', 'Ulice:')
137
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
138
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30)
139
			->getLabelPrototype()->setAttribute('class', 'required');
140
		$form->addText('city', 'Město:')
141
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64)
143
			->getLabelPrototype()->setAttribute('class', 'required');
144
		$form->addText('postal_code', 'PSČ:')
145
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
146
			->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}')
147
			->setAttribute('placeholder', '12345')
0 ignored issues
show
Documentation introduced by
'12345' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
148
			->getLabelPrototype()->setAttribute('class', 'required');
149
		$form->addText('group_num', 'Číslo středika/přístavu:')
150
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
151
			->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnn.nn!', '[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}')
152
			->setAttribute('placeholder', '214.02')
0 ignored issues
show
Documentation introduced by
'214.02' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
153
			->getLabelPrototype()->setAttribute('class', 'required');
154
		$form->addText('group_name', 'Název střediska/přístavu:')
155
			->setRequired(static::MESSAGE_REQUIRED)
0 ignored issues
show
Documentation introduced by
static::MESSAGE_REQUIRED is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
156
			->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50)
157
			->setAttribute('placeholder', '2. přístav Poutníci Kolín')
0 ignored issues
show
Documentation introduced by
'2. přístav Poutníci Kolín' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
			->getLabelPrototype()->setAttribute('class', 'required');
159
		$form->addText('troop_name', 'Název oddílu:')
160
			->setAttribute('placeholder', '22. oddíl Galeje')
0 ignored issues
show
Documentation introduced by
'22. oddíl Galeje' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
			->addCondition(Form::FILLED, true)
162
				->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50);
163
164
		$form->addSelect('province', 'Kraj:', $provinces)
165
			->setPrompt('Zvolte kraj');
166
167
		$form = $this->buildMealSwitcher($form);
168
169
		$form->addTextArea('arrival', 'Informace o příjezdu:')
170
			->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) přijedete na místo srazu.');
171
		$form->addTextArea('departure', 'Informace o odjezdu:')
172
			->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) sraz opustíte.');
173
		$form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:');
174
		$form->addTextArea('question', 'Vaše nabídka:')
175
			->setAttribute('placeholder', 'Vaše nabídka na sdílení dobré praxe (co u vás umíte dobře a jste ochotni se o to podělit)');
176
		$form->addTextArea('question2', 'Počet a typy lodí:')
177
			->setAttribute('placeholder', 'Počet a typy lodí, které sebou přivezete (vyplňte pokud ano)');
178
179
		$form = $this->buildProgramSwitcher($form);
180
181
		$form->addHidden('mid', $this->getMeetingId());
182
		$form->addHidden('bill', 0);
183
		$form->addHidden('cost', $this->getMeetingModel()->getPrice('cost'));
184
185
		$form->addSubmit('save', 'Uložit')
186
			->setAttribute('class', 'btn-primary');
187
		$form->addSubmit('reset', 'storno')
188
			->setAttribute('class', 'btn-reset');
189
190
		$form = $this->setupRendering($form);
191
192
		$form->onSuccess[] = [$this, 'processForm'];
193
194
		return $form;
195
	}
196
197
	/**
198
	 * @param  Form $form
199
	 * @return void
200
	 */
201
	public function processForm(Form $form)
202
	{
203
		$registration = $form->getValues();
204
		$registration['meeting'] = $this->getMeetingId();
205
206
		$this->onRegistrationSave($this, $registration);
0 ignored issues
show
Documentation Bug introduced by
The method onRegistrationSave does not exist on object<App\Components\Forms\RegistrationForm>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
207
	}
208
209
	/**
210
	 * @param  Form   $form
211
	 * @return Form
212
	 */
213
	protected function setupRendering(Form $form): Form
214
	{
215
		// setup form rendering
216
		$renderer = $form->getRenderer();
217
		$renderer->wrappers['controls']['container'] = NULL;
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
218
		$renderer->wrappers['pair']['.error'] = 'has-error';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
219
		$renderer->wrappers['control']['description'] = 'span class=help-block';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
220
		$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
0 ignored issues
show
Bug introduced by
Accessing wrappers on the interface Nette\Forms\IFormRenderer suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
221
222
		// make form and controls compatible with Twitter Bootstrap
223
		$form->getElementPrototype()->class('form-horizontal');
224
		foreach ($form->getControls() as $control) {
225
			if ($control instanceof Controls\Button) {
226
				$control->getControlPrototype()
227
					->addClass(empty($usedPrimary) ? 'btn btn-default' : '');
228
				$usedPrimary = TRUE;
229
			} elseif (
230
				$control instanceof Controls\TextBase ||
231
				$control instanceof Controls\SelectBox ||
232
				$control instanceof Controls\MultiSelectBox
233
			) {
234
				$control->getControlPrototype()
235
					->addClass('form-control');
236
			} elseif (
237
				$control instanceof Controls\Checkbox ||
238
				$control instanceof Controls\CheckboxList ||
239
				$control instanceof Controls\RadioList
240
			) {
241
				$control->getSeparatorPrototype()
242
					->setName('div')
243
					->addClass($control->getControlPrototype()->type);
244
			}
245
		}
246
247
		return $form;
248
	}
249
250
	/**
251
	 * @param  Form   $form
252
	 * @return Form
253
	 */
254
	protected function buildProgramSwitcher(Form $form): Form
255
	{
256
		$programBlocks = $this->fetchProgramBlocks();
257
258
		foreach ($programBlocks as $block) {
259
260
			$programsInBlock = $this->getProgramModel()->findByBlockId($block->id);
261
262
			$programs = [
263
				0 => 'Nebudu přítomen'
264
			];
265
266
			foreach ($programsInBlock as $program) {
267
				$programs[$program->id] = $program->name;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Nette\Database\IRow suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing name on the interface Nette\Database\IRow suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
268
			}
269
270
			$form->addRadioList('blck_' . $block->id, $block->day . ', ' . $block->from .' - ' . $block->to .' : ' . $block->name, $programs)
271
				->setDefaultValue(0);
272
		}
273
274
		return $form;
275
	}
276
277
	/**
278
	 * @param  Form   $form
279
	 * @return Form
280
	 */
281
	protected function buildMealSwitcher(Form $form): Form
282
	{
283
		$yesNoArray = [
284
			'ne'  => 'ne',
285
			'ano' => 'ano',
286
		];
287
288
		foreach ($this->fetchMeals() as $name => $label) {
289
			$this->setMealField($name);
290
			$form->addSelect($name, $label . ':', $yesNoArray);
291
		}
292
293
		return $form;
294
	}
295
296
	/**
297
	 * @return ProvinceModel
298
	 */
299
	protected function getProvinceModel(): ProvinceModel
300
	{
301
		return $this->provinceModel;
302
	}
303
304
	/**
305
	 * @param  ProvinceModel $model
306
	 * @return RegistrationFormFactory
307
	 */
308
	protected function setProvinceModel(ProvinceModel $model): RegistrationForm
309
	{
310
		$this->provinceModel = $model;
311
312
		return $this;
313
	}
314
315
	/**
316
	 * @return ProgramModel
317
	 */
318
	protected function getProgramModel(): ProgramModel
319
	{
320
		return $this->programModel;
321
	}
322
323
	/**
324
	 * @param  ProgramModel $model
325
	 * @return RegistrationFormFactory
326
	 */
327
	protected function setProgramModel(ProgramModel $model): RegistrationForm
328
	{
329
		$this->programModel = $model;
330
331
		return $this;
332
	}
333
334
	/**
335
	 * @return BlockModel
336
	 */
337
	protected function getBlockModel(): BlockModel
338
	{
339
		return $this->blockModel;
340
	}
341
342
	/**
343
	 * @param  BlockModel $model
344
	 * @return RegistrationForm
345
	 */
346
	protected function setBlockModel(BlockModel $model): RegistrationForm
347
	{
348
		$this->blockModel = $model;
349
350
		return $this;
351
	}
352
353
	/**
354
	 * @return MeetingModel
355
	 */
356
	protected function getMeetingModel(): MeetingModel
357
	{
358
		return $this->meetingModel;
359
	}
360
361
	/**
362
	 * @param  MeetingModel $model
363
	 * @return RegistrationForm
364
	 */
365
	protected function setMeetingModel(MeetingModel $model): RegistrationForm
366
	{
367
		$this->meetingModel = $model;
368
369
		return $this;
370
	}
371
372
	/**
373
	 * @return array
374
	 */
375
	protected function getMealFields(): array
376
	{
377
		return $this->mealFields;
378
	}
379
380
	/**
381
	 * @param  string $meal
382
	 * @return RegistrationForm
383
	 */
384
	protected function setMealField(string $meal): RegistrationForm
385
	{
386
		if(!in_array($meal, $this->mealFields)) {
387
			$this->mealFields[] = $meal;
388
		}
389
390
		return $this;
391
	}
392
393
	/**
394
	 * @return array
395
	 */
396
	protected function getProgramFields(): array
397
	{
398
		return $this->programFields;
399
	}
400
401
	/**
402
	 * @param  string $program
403
	 * @return RegistrationForm
404
	 */
405
	protected function setProgramField(string $program): RegistrationForm
406
	{
407
		$this->programFields[] = $program;
408
409
		return $this;
410
	}
411
412
	/**
413
	 * @return RegistrationForm
414
	 */
415
	protected function setProgramFields(): RegistrationForm
416
	{
417
		$programBlocks = $this->fetchProgramBlocks();
418
419
		foreach ($programBlocks as $block) {
420
			$programFieldName = 'blck_' . $block->id;
421
			$this->setProgramField($programFieldName);
422
		}
423
424
		return $this;
425
	}
426
427
	/**
428
	 * @return  RegistrationForm
429
	 */
430
	protected function setMealFields(): RegistrationForm
431
	{
432
		$meals = $this->fetchMeals();
433
434
		foreach ($meals as $name => $label) {
435
			$this->setMealField($name);
436
		}
437
438
		return $this;
439
	}
440
441
	protected function fetchProgramBlocks()
442
	{
443
		return $this->getBlockModel()->getProgramBlocks($this->getMeetingId());
444
	}
445
446
	protected function fetchMeals()
447
	{
448
		return MealModel::$meals;
449
	}
450
451
	/**
452
	 * @return UserService
453
	 */
454
	protected function getUserService()
455
	{
456
		return $this->userService;
457
	}
458
459
	/**
460
	 * @param  UserService $service
461
	 * @return $this
462
	 */
463
	protected function setUserService(UserService $service)
464
	{
465
		$this->userService = $service;
466
467
		return $this;
468
	}
469
470
}
471