Passed
Push — developer ( d5cf61...0a1e92 )
by Radosław
18:21
created

Calendar_RepeatEvents_Handler::preStateChange()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 16
rs 9.5555
c 1
b 0
f 0
cc 5
nc 2
nop 1
1
<?php
2
/**
3
 * Select saving mode when event is repeat handler.
4
 *
5
 * @package Handler
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Adrian Kon <[email protected]>
10
 */
11
/**
12
 * Calendar_RepeatEvents_Handler class.
13
 */
14
class Calendar_RepeatEvents_Handler
15
{
16
	/**
17
	 * EditViewPreSave handler function.
18
	 *
19
	 * @param App\EventHandler $eventHandler
20
	 */
21
	public function editViewPreSave(App\EventHandler $eventHandler)
22
	{
23
		$response = ['result' => true];
24
		$recordModel = $eventHandler->getRecordModel();
25
		if ($recordModel->get('reapeat') && !isset($recordModel->ext['repeatType'])) {
26
			$response = [
27
				'result' => false,
28
				'type' => 'modal',
29
				'url' => "index.php?module=Calendar&view=RepeatEvents&record={$recordModel->getId()}",
30
			];
31
		}
32
		return $response;
33
	}
34
35
	/**
36
	 * Pre delete handler function.
37
	 *
38
	 * @param App\EventHandler $eventHandler
39
	 *
40
	 * @return array
41
	 */
42
	public function preDelete(App\EventHandler $eventHandler)
43
	{
44
		$response = ['result' => true];
45
		$recordModel = $eventHandler->getRecordModel();
46
		if ($recordModel->get('reapeat') && !isset($recordModel->ext['repeatType'])) {
47
			$response = [
48
				'result' => false,
49
				'type' => 'modal',
50
				'url' => "index.php?module=Calendar&view=RepeatEventsDelete&record={$recordModel->getId()}",
51
			];
52
		}
53
		return $response;
54
	}
55
56
	/**
57
	 * Register pre state change.
58
	 *
59
	 * @param App\EventHandler $eventHandler
60
	 *
61
	 * @return array
62
	 */
63
	public function preStateChange(App\EventHandler $eventHandler)
64
	{
65
		$responseData = ['result' => true];
66
		$recordModel = $eventHandler->getRecordModel();
67
		$repeatCondition = $recordModel->get('reapeat');
68
		$noRepeatType = !isset($recordModel->ext['repeatType']);
69
		$newStateExists = isset($recordModel->ext['newState']);
70
		$isTrashState = \App\Record::STATE_TRASH === $recordModel->ext['newState'];
71
		if ($repeatCondition && $noRepeatType && $newStateExists && $isTrashState) {
72
			$responseData = [
73
				'result' => false,
74
				'type' => 'modal',
75
				'url' => "index.php?module=Calendar&view=RepeatEventsDelete&record={$recordModel->getId()}",
76
			];
77
		}
78
		return $responseData;
79
	}
80
}
81