Completed
Push — develop ( 7a7d04...968c4b )
by Daniel
20:22
created

navbar::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2020 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\controller;
12
13
use Symfony\Component\HttpFoundation\Response;
14
15
class navbar
16
{
17
	/** @var \phpbb\auth\auth */
18
	protected $auth;
19
20
	/** @var \phpbb\symfony_request */
21
	protected $symfony_request;
22
23
	/** @var \phpbb\language\language */
24
	protected $translator;
25
26
	/** @var \blitze\sitemaker\services\navbar */
27
	protected $navbar;
28
29
	/**
30
	 * Constructor
31
	 *
32
	 * @param \phpbb\auth\auth							$auth					Auth object
33
	 * @param \phpbb\symfony_request					$symfony_request		Symfony Request object
34
	 * @param \phpbb\language\language					$translator				Language object
35
	 * @param \blitze\sitemaker\services\navbar			$navbar					Navbar object
36
	 */
37
	public function __construct(\phpbb\auth\auth $auth, \phpbb\symfony_request $symfony_request, \phpbb\language\language $translator, \blitze\sitemaker\services\navbar $navbar)
38
	{
39
		$this->auth = $auth;
40
		$this->symfony_request = $symfony_request;
41
		$this->translator = $translator;
42
		$this->navbar = $navbar;
43
	}
44
45
	/**
46
	 * @return \Symfony\Component\HttpFoundation\Response
47
	 */
48
	public function css($style)
49
	{
50
		$response = new Response();
51
		$response->headers->set('Content-Type', 'text/css');
52
53
		$response->setPublic();
54
		$response->setETag($style . '-' . $this->navbar->get_last_modified());
55
		$response->setLastModified(new \DateTime('@' . $this->navbar->get_last_modified() ?? null));
56
57
		if ($response->isNotModified($this->symfony_request))
58
		{
59
			return $response;
60
		}
61
62
		$response->setContent($this->navbar->get_css($style));
63
64
		return $response;
65
	}
66
67
	/**
68
	 * @return \Symfony\Component\HttpFoundation\Response
69
	 */
70
	public function save($style)
71
	{
72
		$data = array('message' => '');
73
74
		if (!$this->symfony_request->isXmlHttpRequest() || !$this->auth->acl_get('a_sm_manage_blocks'))
75
		{
76
			$data['message'] = $this->translator->lang('NOT_AUTHORISED');
77
			$status = 401;
78
		}
79
		else
80
		{
81
			$this->navbar->save($style);
82
			$status = 200;
83
		}
84
85
		$response = new Response(json_encode($data), $status);
86
		$response->headers->set('Content-Type', 'application/json');
87
88
		return $response;
89
	}
90
}
91