aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/install/module/obtain_data/task/obtain_board_data.php
blob: ff2a0a2f8696b19019b4ebc6028652738cbe9754 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?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\install\module\obtain_data\task;

use phpbb\install\exception\user_interaction_required_exception;

/**
 * This class obtains default data from the user related to board (Board name, Board descritpion, etc...)
 */
class obtain_board_data extends \phpbb\install\task_base implements \phpbb\install\task_interface
{
	/**
	 * @var \phpbb\install\helper\config
	 */
	protected $install_config;

	/**
	 * @var \phpbb\install\helper\iohandler\iohandler_interface
	 */
	protected $io_handler;

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

	/**
	 * Constructor
	 *
	 * @param \phpbb\install\helper\config							$config			Installer's config
	 * @param \phpbb\install\helper\iohandler\iohandler_interface	$iohandler		Installer's input-output handler
	 * @param \phpbb\language\language_file_helper					$lang_helper	Language file helper
	 */
	public function __construct(\phpbb\install\helper\config $config,
								\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
								\phpbb\language\language_file_helper $lang_helper)
	{
		$this->install_config	= $config;
		$this->io_handler		= $iohandler;
		$this->language_helper	= $lang_helper;

		parent::__construct(true);
	}

	/**
	 * {@inheritdoc}
	 */
	public function run()
	{
		// Check if data is sent
		if ($this->io_handler->get_input('submit_board', false))
		{
			$this->process_form();
		}
		else
		{
			$this->request_form_data();
		}
	}

	/**
	 * Process form data
	 */
	protected function process_form()
	{
		// Board data
		$default_lang	= $this->io_handler->get_input('default_lang', '');
		$board_name		= $this->io_handler->get_input('board_name', '', true);
		$board_desc		= $this->io_handler->get_input('board_description', '', true);

		// Check default lang
		$langs = $this->language_helper->get_available_languages();
		$lang_valid = false;

		foreach ($langs as $lang)
		{
			if ($lang['iso'] === $default_lang)
			{
				$lang_valid = true;
				break;
			}
		}

		$this->install_config->set('board_name', $board_name);
		$this->install_config->set('board_description', $board_desc);

		if ($lang_valid)
		{
			$this->install_config->set('default_lang', $default_lang);
		}
		else
		{
			$this->request_form_data(true);
		}
	}

	/**
	 * Request data from the user
	 *
	 * @param bool $use_request_data Whether to use submited data
	 *
	 * @throws \phpbb\install\exception\user_interaction_required_exception When the user is required to provide data
	 */
	protected function request_form_data($use_request_data = false)
	{
		if ($use_request_data)
		{
			$board_name		= $this->io_handler->get_input('board_name', '', true);
			$board_desc		= $this->io_handler->get_input('board_description', '', true);
		}
		else
		{
			$board_name		= '{L_CONFIG_SITENAME}';
			$board_desc		= '{L_CONFIG_SITE_DESC}';
		}

		// Use language because we only check this to be valid
		$default_lang	= $this->install_config->get('user_language', 'en');

		$langs = $this->language_helper->get_available_languages();
		$lang_options = array();

		foreach ($langs as $lang)
		{
			$lang_options[] = array(
				'value'		=> $lang['iso'],
				'label'		=> $lang['local_name'],
				'selected'	=> ($default_lang === $lang['iso']),
			);
		}

		$board_form = array(
			'default_lang' => array(
				'label'		=> 'DEFAULT_LANGUAGE',
				'type'		=> 'select',
				'options'	=> $lang_options,
			),
			'board_name' => array(
				'label'		=> 'BOARD_NAME',
				'type'		=> 'text',
				'default'	=> $board_name,
			),
			'board_description' => array(
				'label'		=> 'BOARD_DESCRIPTION',
				'type'		=> 'text',
				'default'	=> $board_desc,
			),
			'submit_board'	=> array(
				'label'	=> 'SUBMIT',
				'type'	=> 'submit',
			),
		);

		$this->io_handler->add_user_form_group('BOARD_CONFIG', $board_form);

		throw new user_interaction_required_exception();
	}

	/**
	 * {@inheritdoc}
	 */
	static public function get_step_count()
	{
		return 0;
	}

	/**
	 * {@inheritdoc}
	 */
	public function get_task_lang_name()
	{
		return '';
	}
}