Completed
Push — develop ( 9087a8...c9b4ef )
by Greg
16:31 queued 05:44
created

EditGedcomRecordController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A editRaw() 0 14 3
A editRawAction() 0 13 3
1
<?php
2
/**
3
 * webtrees: online genealogy
4
 * Copyright (C) 2018 webtrees development team
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 * GNU General Public License for more details.
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
 */
16
declare(strict_types=1);
17
18
namespace Fisharebest\Webtrees\Http\Controllers;
19
20
use Fisharebest\Webtrees\GedcomRecord;
21
use Fisharebest\Webtrees\Tree;
22
use Symfony\Component\HttpFoundation\RedirectResponse;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpFoundation\Response;
25
26
/**
27
 * Controller for edit forms and responses.
28
 */
29
class EditGedcomRecordController extends BaseController {
30
	/**
31
	 * @param Request $request
32
	 *
33
	 * @return Response
34
	 */
35
	public function editRaw(Request $request): Response {
36
		/** @var Tree $tree */
37
		$tree   = $request->attributes->get('tree');
38
		$xref   = $request->get('xref');
39
		$record = GedcomRecord::getInstance($xref, $tree);
40
41
		if ($record === null) {
42
			return $this->recordNotFound();
43
		} elseif (!$record->canEdit()) {
44
			return $this->recordNotAllowed();
45
		}
46
47
		return $this->viewResponse('', [
48
			'record' => $record,
49
		]);
50
	}
51
52
	/**
53
	 * @param Request $request
54
	 *
55
	 * @return Response
56
	 */
57
	public function editRawAction(Request $request): Response {
58
		/** @var Tree $tree */
59
		$tree   = $request->attributes->get('tree');
60
		$xref   = $request->get('xref');
61
		$record = GedcomRecord::getInstance($xref, $tree);
62
63
		if ($record === null) {
64
			return $this->recordNotFound();
65
		} elseif (!$record->canEdit()) {
66
			return $this->recordNotAllowed();
67
		}
68
69
		return new RedirectResponse($record->url());
70
	}
71
}
72