Completed
Pull Request — master (#45)
by Matt
53:10 queued 18:15
created

click_controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 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
* Front controller
15
*/
16
class click_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 clicks for an ad
38
	*
39
	* @param	int	$ad_id	Advertisement ID
40
	* @return	\Symfony\Component\HttpFoundation\JsonResponse	A Symfony JsonResponse object
41
	*/
42
	public function increment_clicks($ad_id)
43
	{
44
		if ($this->request->is_ajax() && !empty($ad_id))
45
		{
46
			$this->manager->increment_ad_clicks($ad_id);
47
48
			return new \Symfony\Component\HttpFoundation\JsonResponse();
49
		}
50
51
		throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
52
	}
53
}
54