aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/help/manager.php
blob: 1637c58a611cd9655d908a91ce5274d9a38e8caf (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?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\help;

/**
 * Class help page manager
 */
class manager
{
	/** @var \phpbb\event\dispatcher_interface */
	protected $dispatcher;

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

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

	/** @var bool */
	protected $switched_column;

	/**
	 * Constructor
	 *
	 * @param \phpbb\event\dispatcher_interface $dispatcher
	 * @param \phpbb\language\language $language
	 * @param \phpbb\template\template $template
	 */
	public function __construct(\phpbb\event\dispatcher_interface $dispatcher, \phpbb\language\language $language, \phpbb\template\template $template)
	{
		$this->dispatcher = $dispatcher;
		$this->language = $language;
		$this->template = $template;
	}

	/**
	 * Add a new faq block
	 *
	 * @param string $block_name	Name or language key with the name of the block
	 * @param bool $switch_column	Switch the column of the menu
	 * @param array $questions		Array of frequently asked questions
	 */
	public function add_block($block_name, $switch_column = false, $questions = array())
	{
		/**
		 * You can use this event to add a block before the current one.
		 *
		 * @event core.help_manager_add_block_before
		 * @var	string	block_name		Language key of the block headline
		 * @var	bool	switch_column	Should we switch the menu column before this headline
		 * @var	array	questions		Array with questions
		 * @since 3.2.0-a1
		 */
		$vars = array('block_name', 'switch_column', 'questions');
		extract($this->dispatcher->trigger_event('core.help_manager_add_block_before', compact($vars)));

		$this->template->assign_block_vars('faq_block', array(
			'BLOCK_TITLE'		=> $this->language->lang($block_name),
			'SWITCH_COLUMN'		=> !$this->switched_column && $switch_column,
		));

		foreach ($questions as $question => $answer)
		{
			$this->add_question($question, $answer);
		}

		$this->switched_column = $this->switched_column || $switch_column;

		/**
		 * You can use this event to add a block after the current one.
		 *
		 * @event core.help_manager_add_block_after
		 * @var	string	block_name		Language key of the block headline
		 * @var	bool	switch_column	Should we switch the menu column before this headline
		 * @var	array	questions		Array with questions
		 * @since 3.2.0-a1
		 */
		$vars = array('block_name', 'switch_column', 'questions');
		extract($this->dispatcher->trigger_event('core.help_manager_add_block_after', compact($vars)));
	}

	/**
	 * Add a new faq question
	 *
	 * @param string $question	Question or language key with the question of the block
	 * @param string $answer	Answer or language key with the answer of the block
	 */
	public function add_question($question, $answer)
	{
		/**
		 * You can use this event to add a question before the current one.
		 *
		 * @event core.help_manager_add_question_before
		 * @var	string	question	Language key of the question
		 * @var	string	answer		Language key of the answer
		 * @since 3.2.0-a1
		 */
		$vars = array('question', 'answer');
		extract($this->dispatcher->trigger_event('core.help_manager_add_question_before', compact($vars)));

		$this->template->assign_block_vars('faq_block.faq_row', array(
			'FAQ_QUESTION'		=> $this->language->lang($question),
			'FAQ_ANSWER'		=> $this->language->lang($answer),
		));

		/**
		 * You can use this event to add a question after the current one.
		 *
		 * @event core.help_manager_add_question_after
		 * @var	string	question	Language key of the question
		 * @var	string	answer		Language key of the answer
		 * @since 3.2.0-a1
		 */
		$vars = array('question', 'answer');
		extract($this->dispatcher->trigger_event('core.help_manager_add_question_after', compact($vars)));
	}

	/**
	 * Returns whether the block titles switched side
	 * @return bool
	 */
	public function switched_column()
	{
		return $this->switched_column;
	}
}