Completed
Pull Request — master (#63)
by Jakub
09:20
created

view_controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\controller;
12
13
/**
14
 * View controller
15
 */
16
class view_controller
17
{
18
	/** @var \phpbb\ads\ad\manager */
19
	protected $manager;
20
21
	/** @var \phpbb\request\request */
22
	protected $request;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * @param \phpbb\ads\ad\manager    $manager Advertisement manager object
28
	 * @param \phpbb\request\request   $request	Request object
29
	 */
30
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\request\request $request)
31
	{
32
		$this->manager = $manager;
33
		$this->request = $request;
34
	}
35
36
	/**
37
	 * Increment views for ads
38
	 *
39
	 * @return	\Symfony\Component\HttpFoundation\JsonResponse	A Symfony JsonResponse object
40
	 */
41
	public function increment_views()
42
	{
43
		if ($this->request->is_ajax() && $this->request->is_set_post('ad_ids'))
44
		{
45
			$this->manager->increment_ads_views($this->request->variable('ad_ids', array(0)));
46
47
			return new \Symfony\Component\HttpFoundation\JsonResponse();
48
		}
49
50
		throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
51
	}
52
}
53