Completed
Push — master ( 0adf65...fea2cb )
by Litera
16s
created

RegistrationPresenter::renderNew()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace App\Presenters;
4
5
use DateTime;
6
use App\Entities\VisitorEntity;
7
use App\Models\MeetingModel;
8
use App\Models\VisitorModel;
9
use App\Models\ProgramModel;
10
use App\Models\MealModel;
11
use App\Services\SkautIS\UserService;
12
use App\Services\Emailer;
13
use App\Services\VisitorService;
14
use App\Services\ProgramService;
15
use Tracy\Debugger;
16
use App\Components\Forms\RegistrationForm;
17
use App\Components\Forms\Factories\IRegistrationFormFactory;
18
use App\Services\SkautIS\EventService;
19
use Skautis\Wsdl\WsdlException;
20
use App\Models\SettingsModel;
21
22
/**
23
 * Registration controller
24
 *
25
 * This file handles the registration of visitors
26
 *
27
 * @author Tomas Litera
28
 * @copyright 2013-06-12 <[email protected]>
29
 * @package srazvs
30
 */
31
class RegistrationPresenter extends VisitorPresenter
32
{
33
34
	/**
35
	 * @var VisitorModel
36
	 */
37
	private $visitorModel;
38
39
	/**
40
	 * @var ProgramModel
41
	 */
42
	private $programModel;
43
44
	/**
45
	 * @var UserService
46
	 */
47
	private $userService;
48
49
	/**
50
	 * @var ProgramService
51
	 */
52
	private $programService;
53
54
	/**
55
	 * @var SettingsModel
56
	 */
57
	protected $settingsModel;
58
59
	/**
60
	 * @var boolean
61
	 */
62
	private $disabled = false;
63
64
	/**
65
	 * @var IRegistrationFormFactory
66
	 */
67
	private $registrationFormFactory;
68
69
	/**
70
	 * @var EventService
71
	 */
72
	protected $skautisEventService;
73
74
	/**
75
	 * @param MeetingModel   $meetingModel
76
	 * @param UserService    $userService
77
	 * @param VisitorModel   $visitorModel
78
	 * @param MealModel      $mealModel
79
	 * @param ProgramModel   $programModel
80
	 * @param VisitorService $visitorService
81
	 * @param SettingsModel  $settingsModel
82
	 */
83
	public function __construct(
84
		MeetingModel $meetingModel,
85
		UserService $userService,
86
		VisitorModel $visitorModel,
87
		MealModel $mealModel,
88
		ProgramModel $programModel,
89
		Emailer $emailer,
90
		VisitorService $visitorService,
91
		ProgramService $programService,
92
		EventService $skautisEvent,
93
		SettingsModel $settingsModel
94
	) {
95
		$this->setMeetingModel($meetingModel);
96
		$this->setUserService($userService);
97
		$this->setVisitorModel($visitorModel);
98
		$this->setMealModel($mealModel);
99
		$this->setProgramModel($programModel);
100
		$this->setEmailer($emailer);
101
		$this->setVisitorService($visitorService);
102
		$this->setProgramService($programService);
103
		$this->setEventService($skautisEvent);
104
		$this->setSettingsModel($settingsModel);
105
	}
106
107
	/**
108
	 * @return IRegistrationFormFactory
109
	 */
110
	public function getRegistrationFormFactory(): IRegistrationFormFactory
111
	{
112
		return $this->registrationFormFactory;
113
	}
114
115
	/**
116
	 * Injector
117
	 *
118
	 * @param  IRegistrationFormFactory $factory
119
	 */
120
121
	protected $error = FALSE;
122
123
	protected $hash = NULL;
124
	private $item;
125
	private $mealData;
126
	private $user;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
127
	private $event;
128
129
	public function injectRegistrationFormFactory(IRegistrationFormFactory $factory)
130
	{
131
		$this->registrationFormFactory = $factory;
132
	}
133
134
	/**
135
	 * @return void
136
	 */
137
	public function startup()
138
	{
139
		parent::startup();
140
141
		$this->getMeetingModel()->setMeetingId($this->getMeetingId());
142
143
		if($this->getDebugMode() || $this->getSettingsModel()->findDebugRegime()) {
144
			$this->getMeetingModel()->setRegistrationHandlers(1);
145
			$this->setMeetingId(1);
146
		} else {
147
			$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId());
148
		}
149
150
		//$this->user = $this->container->getService('userService');
151
		//$this->event = $this->container->getService('eventService');
152
153
		$template = $this->getTemplate();
154
155
		$template->page_title = "Registrace srazu VS";
0 ignored issues
show
Bug introduced by
Accessing page_title 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...
156
		$template->meeting_heading = $this->getMeetingModel()->getRegHeading();
0 ignored issues
show
Bug introduced by
Accessing meeting_heading 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...
157
		$template->isRegistrationOpen = $this->getMeetingModel()->isRegOpen($this->getDebugMode());
0 ignored issues
show
Bug introduced by
Accessing isRegistrationOpen 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...
158
	}
159
160
	/**
161
	 * Process data from form
162
	 *
163
	 * @return void
164
	 */
165 View Code Duplication
	public function actionCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
	{
167
		try {
168
			$postData = $this->getHttpRequest()->getPost();
169
			$postData['meeting'] = $this->getMeetingId();
170
171
			$guid = $this->getVisitorService()->create($postData);
172
			$result = $this->sendRegistrationSummary($postData, $guid);
173
174
			$this->logInfo('Creation of registration(%s) successfull, result: %s', [
175
				$guid,
176
				json_encode($result),
177
			]);
178
			$this->flashSuccess("Registrace({$guid}) byla úspěšně založena.");
179
		} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
180
			$this->logError('Creation of registration(%s) failed, result: %s', [
181
				$guid,
0 ignored issues
show
Bug introduced by
The variable $guid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
182
				$e->getMessage(),
183
			]);
184
			$this->flashError('Creation of registration failed, result: ' . $e->getMessage());
185
		}
186
187
		$this->redirect('Registration:check', $guid);
188
	}
189
190
	/**
191
	 * @param  string  $guid
192
	 * @return void
193
	 */
194 View Code Duplication
	public function actionUpdate($guid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
195
	{
196
		try {
197
			$postData = $this->getHttpRequest()->getPost();
198
199
			$result = $this->getVisitorService()->update($guid, $postData);
200
			$result = $this->sendRegistrationSummary($postData, $guid);
201
202
			$this->logInfo('Modification of registration(%s) successfull, result: %s', [
203
				$guid,
204
				json_encode($result),
205
			]);
206
			$this->flashSuccess("Registrace({$guid}) byla úspěšně upravena.");
207
		} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
208
			$this->logError('Modification of registration(%s) failed, result: %s', [
209
				$guid,
210
				$e->getMessage(),
211
			]);
212
			$this->flashError("Modification of registration({$guid}) failed, result: " . $e->getMessage());
213
		}
214
215
		$this->redirect('Registration:check', $guid);
216
	}
217
218
	/**
219
	 * Renders default template
220
	 */
221
	public function renderDefault()
222
	{
223
		$template = $this->getTemplate();
224
		$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
225
		$template->disabled = $disabled;
0 ignored issues
show
Bug introduced by
Accessing disabled 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...
226
		$template->loggedIn = $this->getUserService()->isLoggedIn();
0 ignored issues
show
Bug introduced by
Accessing loggedIn 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...
227
228
		if($this->getUserService()->isLoggedIn()) {
229
			$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray());
230
		}
231
	}
232
233
	/**
234
	 * Renders new template
235
	 */
236
	public function renderNew()
237
	{
238
		$template = $this->getTemplate();
239
		$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
240
		$template->disabled = $disabled;
0 ignored issues
show
Bug introduced by
Accessing disabled 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...
241
		$template->loggedIn = false;
0 ignored issues
show
Bug introduced by
Accessing loggedIn 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...
242
	}
243
244
	/**
245
	 * @param  string  $guid
246
	 * @return void
247
	 */
248
	public function renderCheck($guid)
249
	{
250
		$visitor = $this->getVisitorModel()->findByGuid($guid);
251
252
		$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting);
253
254
		$template = $this->getTemplate();
255
		$template->guid = $guid;
0 ignored issues
show
Bug introduced by
Accessing guid 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...
256
		$template->visitor = $visitor;
0 ignored issues
show
Bug introduced by
Accessing visitor 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...
257
		$template->meetingId = $visitor->meeting;
0 ignored issues
show
Bug introduced by
Accessing meetingId 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...
258
		$template->meals = $this->getMealModel()->findByVisitorId($visitor->id);
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...
259
		$template->province = $this->getMeetingModel()->getProvinceNameById($visitor->province);
0 ignored issues
show
Bug introduced by
Accessing province 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...
260
		$template->programs = $this->getProgramModel()->findByVisitorId($visitor->id);
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...
261
	}
262
263
	/**
264
	 * @param  string $guid
265
	 * @return void
266
	 */
267
	public function renderEdit($guid)
268
	{
269
		$visitor = $this->getVisitorService()->findByGuid($guid);
270
		$meetingId = $visitor['meeting'];
271
272
		$this->getMeetingModel()->setRegistrationHandlers($meetingId);
273
274
		$template = $this->getTemplate();
275
		$template->guid = $guid;
0 ignored issues
show
Bug introduced by
Accessing guid 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...
276
		$template->meetingId = $meetingId;
0 ignored issues
show
Bug introduced by
Accessing meetingId 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...
277
		$template->loggedIn = $this->getUserService()->isLoggedIn();
0 ignored issues
show
Bug introduced by
Accessing loggedIn 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...
278
		$template->disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
0 ignored issues
show
Bug introduced by
Accessing disabled 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...
279
280
		$this['registrationForm']->setDefaults($visitor);
281
	}
282
283
	/**
284
	 * @return RegistrationFormControl
285
	 */
286
	protected function createComponentRegistrationForm(): RegistrationForm
287
	{
288
		$control = $this->registrationFormFactory->create();
289
		$control->setMeetingId($this->getMeetingId());
290
		$control->onRegistrationSave[] = function(RegistrationForm $control, $newVisitor) {
291
			try {
292
				$guid = $this->getParameter('guid');
293
294
				if($guid) {
295
					$guid = $this->getVisitorService()->update($guid, (array) $newVisitor);
296
				} else {
297
					$guid = $this->getVisitorService()->create((array) $newVisitor);
298
				}
299
/*
300
				if($this->getUserService()->isLoggedIn() && $this->getMeetingModel()->findCourseId()) {
301
					$this->getEventService()->insertEnroll(
302
						$this->getUserService()->getSkautis()->getUser()->getLoginId(),
303
						$this->getMeetingModel()->findCourseId(),
304
						// TODO: get real phone number
305
						'123456789'
306
					);
307
				}
308
*/
309
				$result = $this->sendRegistrationSummary((array) $newVisitor, $guid);
310
311
				$this->logInfo('Storage of visitor(%s) successfull, result: %s', [
312
					$guid,
313
					json_encode($result),
314
				]);
315
				$this->flashSuccess("Účastník({$guid}) byl úspěšně uložen.");
316
			} catch(WsdlException $e) {
317
				$this->logWarning('Storage of visitor(%s) failed, result: %s', [
318
					$guid,
319
					$e->getMessage(),
320
				]);
321
				$this->flashError("Uložení účastníka ({$guid}) selhalo. Účastník je již zaregistrován.");
322
			} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
323
				$this->logError('Storage of visitor(%s) failed, result: %s', [
324
					$guid,
325
					$e->getMessage(),
326
				]);
327
				$this->flashError('Uložení účastníka selhalo, chyba: ' . $e->getMessage());
328
			}
329
330
			$this->redirect('Registration:check', $guid);
331
		};
332
333
		return $control;
334
	}
335
336
	/**
337
	 * @return VisitorEntity
338
	 */
339
	protected function useLoggedVisitor(): VisitorEntity
340
	{
341
		$userDetail = $this->getUserService()->getUserDetail();
342
		$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person);
343
		$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person);
344
345
		if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) {
346
			$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0];
347
		} else {
348
			$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit);
349
		}
350
351
		$visitor = new VisitorEntity;
352
		$visitor->name = $skautisUser->FirstName;
353
		$visitor->surname = $skautisUser->LastName;
354
		$visitor->nick = $skautisUser->NickName;
355
		$visitor->email = $skautisUser->Email;
356
		$visitor->street = $skautisUser->Street;
357
		$visitor->city = $skautisUser->City;
358
		$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode);
359
		$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y');
360
		$visitor->group_name = $skautisUserUnit->DisplayName;
361
		$visitor->group_num = $skautisUserUnit->RegistrationNumber;
362
		if(isset($membership->Unit)) {
363
			$visitor->troop_name = $membership->Unit;
364
		}
365
366
		return $visitor;
367
	}
368
369
	/**
370
	 * @return MealModel
371
	 */
372
	protected function getMealModel()
373
	{
374
		return $this->mealModel;
375
	}
376
377
	/**
378
	 * @param  MealModel $model
379
	 * @return $this
380
	 */
381
	protected function setMealModel(MealModel $model)
382
	{
383
		$this->mealModel = $model;
384
385
		return $this;
386
	}
387
388
	/**
389
	 * @return MeetingModel
390
	 */
391
	protected function getMeetingModel()
392
	{
393
		return $this->meetingModel;
394
	}
395
396
	/**
397
	 * @param  MeetingModel $model
398
	 * @return $this
399
	 */
400
	protected function setMeetingModel(MeetingModel $model)
401
	{
402
		$this->meetingModel = $model;
403
404
		return $this;
405
	}
406
407
	/**
408
	 * @return VisitorModel
409
	 */
410
	protected function getVisitorModel()
411
	{
412
		return $this->visitorModel;
413
	}
414
415
	/**
416
	 * @param  VisitorModel $model
417
	 * @return $this
418
	 */
419
	protected function setVisitorModel(VisitorModel $model)
420
	{
421
		$this->visitorModel = $model;
422
423
		return $this;
424
	}
425
426
	/**
427
	 * @return ProgramModel
428
	 */
429
	protected function getProgramModel()
430
	{
431
		return $this->programModel;
432
	}
433
434
	/**
435
	 * @param  ProgramModel $model
436
	 * @return $this
437
	 */
438
	protected function setProgramModel(ProgramModel $model)
439
	{
440
		$this->programModel = $model;
441
442
		return $this;
443
	}
444
445
	/**
446
	 * @return UserService
447
	 */
448
	protected function getUserService()
449
	{
450
		return $this->userService;
451
	}
452
453
	/**
454
	 * @param  UserService $service
455
	 * @return $this
456
	 */
457
	protected function setUserService(UserService $service)
458
	{
459
		$this->userService = $service;
460
461
		return $this;
462
	}
463
464
	/**
465
	 * @return ProgramService
466
	 */
467
	protected function getProgramService()
468
	{
469
		return $this->programService;
470
	}
471
472
	/**
473
	 * @param  ProgramService $service
474
	 * @return $this
475
	 */
476
	protected function setProgramService(ProgramService $service)
477
	{
478
		$this->programService = $service;
479
480
		return $this;
481
	}
482
483
	/**
484
	 * @return EventService
485
	 */
486
	protected function getEventService(): EventService
487
	{
488
		return $this->skautisEventService;
489
	}
490
491
	/**
492
	 * @param EventService $skautisEvent
0 ignored issues
show
Bug introduced by
There is no parameter named $skautisEvent. 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...
493
	 *
494
	 * @return self
495
	 */
496
	protected function setEventService(EventService $service): self
497
	{
498
		$this->skautisEventService = $service;
499
500
		return $this;
501
	}
502
503
504
	/**
505
	 * @return SettingsModel
506
	 */
507
	public function getSettingsModel()
508
	{
509
		return $this->settingsModel;
510
	}
511
512
	/**
513
	 * @param SettingsModel $model
514
	 *
515
	 * @return self
516
	 */
517
	public function setSettingsModel(SettingsModel $model): self
518
	{
519
		$this->settingsModel = $model;
520
521
		return $this;
522
	}
523
524
}
525