aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/report/report_reason_list_provider.php
blob: 388a61d577bec8bedbd35fe8221cf05517676e3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

namespace phpbb\report;

class report_reason_list_provider
{
	/**
	 * @var \phpbb\db\driver\driver_interface
	 */
	protected $db;

	/**
	 * @var \phpbb\template\template
	 */
	protected $template;

	/**
	 * @var \phpbb\user
	 */
	protected $user;

	/**
	 * Constructor
	 *
	 * @param \phpbb\db\driver\driver_interface	$db
	 * @param \phpbb\template\template			$template
	 * @param \phpbb\user						$user
	 */
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user)
	{
		$this->db		= $db;
		$this->template	= $template;
		$this->user		= $user;
	}

	/**
	 * Sets template variables to render report reasons select HTML input
	 *
	 * @param int	$reason_id
	 * @return null
	 */
	public function display_reasons($reason_id = 0)
	{
		$sql = 'SELECT *
			FROM ' . REPORTS_REASONS_TABLE . '
			ORDER BY reason_order ASC';
		$result = $this->db->sql_query($sql);

		while ($row = $this->db->sql_fetchrow($result))
		{
			// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
			if (isset($this->user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($this->user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
			{
				$row['reason_description'] = $this->user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
				$row['reason_title'] = $this->user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
			}

			$this->template->assign_block_vars('reason', array(
				'ID'			=> $row['reason_id'],
				'TITLE'			=> $row['reason_title'],
				'DESCRIPTION'	=> $row['reason_description'],
				'S_SELECTED'	=> ($row['reason_id'] == $reason_id) ? true : false,
			));
		}
		$this->db->sql_freeresult($result);
	}
}