Completed
Pull Request — devel (#144)
by Litera
03:43
created

BlockRepository::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Repositories;
4
5
use App\Entities\BlockEntity;
6
use App\Models\BlockModel;
7
use Nette\Database\Table\ActiveRow;
8
9
class BlockRepository
10
{
11
12
	/**
13
	 * @var BlockModel
14
	 */
15
	protected $blockModel;
16
17
	/**
18
	 * @param BlockModel $blockModel
19
	 */
20
	public function __construct(BlockModel $blockModel)
21
	{
22
		$this->setBlockModel($blockModel);
23
	}
24
25
	/**
26
	 * @param  int $meetingId
27
	 * @return self
28
	 */
29
	public function setMeetingId(int $meetingId): self
30
	{
31
		$this->getBlockModel()->setMeetingId($meetingId);
32
33
		return $this;
34
	}
35
36
	/**
37
	 * @return array
38
	 */
39
	public function all(): array
40
	{
41
		return $this->getBlockModel()->all();
42
	}
43
44
	/**
45
	 * @param  int $id
46
	 * @return \Nette\Database\Table\ActiveRow
47
	 */
48
	public function find(int $id): BlockEntity
49
	{
50
		return $this->getBlockModel()->find($id);
51
	}
52
53
	/**
54
	 * @param  string $meetingId
55
	 * @return array
56
	 */
57
	public function findByMeeting(string $meetingId): array
58
	{
59
		return $this->getBlockModel()->findBymeeting($meetingId);
60
	}
61
62
	/**
63
	 * @param $id
64
	 * @return \Nette\Database\Table\ActiveRow
65
	 */
66
	public function findTutor($id)
67
	{
68
		return $this->getBlockModel()->getTutor($id);
69
	}
70
71
	/**
72
	 * @param  $block
73
	 * @return \Nette\Database\Table\ActiveRow
74
	 */
75
	public function create($block)
76
	{
77
		unset($block->id);
78
79
		return $this->getBlockModel()
80
			->save(
81
				$this->populate($block)
82
			);
83
	}
84
85
	/**
86
	 * @param  $id
87
	 * @param  $block
88
	 * @return \Nette\Database\Table\ActiveRow
89
	 */
90
	public function update($id, $block)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
	{
92
		return $this->getBlockModel()
93
			->save(
94
				$this->populate($block)
95
			);
96
	}
97
98
	/**
99
	 * @param  $id
100
	 * @param  $block
101
	 * @return \Nette\Database\Table\ActiveRow
102
	 */
103
	public function save($block)
104
	{
105
		return $this->getBlockModel()
106
			->save(
107
				$this->populate($block)
108
			);
109
	}
110
111
	/**
112
	 * @param $id
113
	 * @return bool
114
	 */
115
	public function delete($id): bool
116
	{
117
		return $this->getBlockModel()->delete($id);
118
	}
119
120
	/**
121
	 * @param  array $values
122
	 * @return BlockEntity
123
	 */
124
	protected function populate($values): BlockEntity
125
	{
126
		$model = $this->getBlockModel();
127
		$block = $model->hydrate($values);
128
		$block = $model->transform($block);
129
130
		return $block;
131
	}
132
133
	/**
134
	 * @return BlockModel
135
	 */
136
	protected function getBlockModel()
137
	{
138
		return $this->blockModel;
139
	}
140
141
	/**
142
	 * @param  BlockModel $model
143
	 * @return $this
144
	 */
145
	protected function setBlockModel(BlockModel $model): self
146
	{
147
		$this->blockModel = $model;
148
149
		return $this;
150
	}
151
152
}
153