Passed
Push — master ( 146fdc...6e4ec6 )
by Dark❶
02:30
created

acp_main   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 21 2
1
<?php
2
/**
3
 *
4
 * Reduce Search Index [RSI]. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020, Dark❶, https://dark1.tech
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace dark1\reducesearchindex\controller;
12
13
/**
14
 * @ignore
15
 */
16
use phpbb\config\config;
17
use phpbb\template\template;
18
use phpbb\user;
19
use phpbb\language\language;
20
use phpbb\log\log;
21
use phpbb\request\request;
22
23
/**
24
 * Reduce Search Index [RSI] ACP controller Main.
25
 */
26
class acp_main extends acp_base
27
{
28
	/** @var \phpbb\config\config */
29
	protected $config;
30
31
	/**
32
	 * Constructor.
33
	 *
34
	 * @param \phpbb\language\language				$language		Language object
35
	 * @param \phpbb\log\log						$log			Log object
36
	 * @param \phpbb\request\request				$request		Request object
37
	 * @param \phpbb\template\template				$template		Template object
38
	 * @param \phpbb\user							$user			User object
39
	 * @param \phpbb\config\config					$config			Config object
40
	 */
41
	public function __construct(language $language, log $log, request $request, template $template, user $user, config $config)
42
	{
43
		parent::__construct($language, $log, $request, $template, $user);
44
45
		$this->config		= $config;
46
	}
47
48
	/**
49
	 * Display the options a user can configure for Main Mode.
50
	 *
51
	 * @return void
52
	 */
53
	public function handle()
54
	{
55
		// Is the form being submitted to us?
56
		if ($this->request->is_set_post('submit'))
57
		{
58
			$this->check_form_on_submit();
59
60
			// Set the options the user configured
61
			$this->config->set('dark1_rsi_enable', $this->request->variable('dark1_rsi_enable', 0));
62
			$this->config->set('dark1_rsi_time', strtotime($this->request->variable('dark1_rsi_time', '0', true)));
63
			$this->config->set('dark1_rsi_interval', ($this->request->variable('dark1_rsi_interval', 0)) * 86400);
64
65
			$this->success_form_on_submit();
66
		}
67
68
		// Set output variables for display in the template
69
		$this->template->assign_vars([
70
			'RSI_ENABLE'		=> $this->config['dark1_rsi_enable'],
71
			'RSI_INTERVAL'		=> ($this->config['dark1_rsi_interval'] / 86400),
72
			'RSI_TIME'			=> $this->user->format_date($this->config['dark1_rsi_time'], 'Y-m-d h:i:s A P', true),
73
			'RSI_CURR_TIME'		=> $this->user->format_date(time(), 'Y-m-d h:i:s A P', true),
74
		]);
75
	}
76
}
77