main::__construct()   A
last analyzed

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
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
/**
3
 *
4
 * @package phpBB Extension - tas2580 AJAX Notifications
5
 * @copyright (c) 2016 tas2580 (https://tas2580.net)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace tas2580\ajaxnotification\controller;
11
12
use Symfony\Component\HttpFoundation\JsonResponse;
13
use Symfony\Component\DependencyInjection\Container;
14
15
class main
16
{
17
	/** @var \phpbb\path_helper */
18
	protected $path_helper;
19
20
	/** @var Container */
21
	protected $phpbb_container;
22
23
	/** @var \phpbb\user */
24
	protected $user;
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param \phpbb\path_helper	$path_helper
30
	 * @param Container			$phpbb_container
31
	 * @param \phpbb\user			$user
32
33
	 */
34
	public function __construct(\phpbb\path_helper $path_helper, Container $phpbb_container, \phpbb\user $user)
35
	{
36
		$this->path_helper = $path_helper;
37
		$this->phpbb_container = $phpbb_container;
38
		$this->user = $user;
39
	}
40
41
	public function query()
42
	{
43
		$phpbb_notifications = $this->phpbb_container->get('notification_manager');
44
		$notifications = $phpbb_notifications->load_notifications(array(
45
			'user_id'		=> $this->user->data['user_id'],
46
			'all_unread'	=> true,
47
			'limit'			=> 5,
48
		));
49
50
		$result = array();
51
		foreach ($notifications['notifications'] as $notification)
52
		{
53
			$data = $notification->prepare_for_display();
54
			$data['U_MARK_READ'] = $this->path_helper->update_web_root_path($data['U_MARK_READ']);
55
			$data['URL'] = $this->path_helper->update_web_root_path($data['URL']);
56
			$data['L_MARK_READ'] = $this->user->lang['MARK_READ'];
57
			$result[] =$data;
58
		}
59
60
		return new JsonResponse($result);
61
	}
62
}
63