Passed
Pull Request — develop-3.2.x (#69)
by Mario
02:19
created

paypal_features_controller::display_settings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nc 2
nop 0
dl 0
loc 36
rs 9.568
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * PayPal Donation extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015 Skouat
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace skouat\ppde\controller\admin;
12
13
use phpbb\config\config;
14
use phpbb\language\language;
15
use phpbb\log\log;
16
use phpbb\request\request;
17
use phpbb\template\template;
18
use phpbb\user;
19
use skouat\ppde\controller\ipn_paypal;
20
use skouat\ppde\controller\main_controller;
21
22
/**
23
 * @property config   config             Config object
24
 * @property string   id_prefix_name     Prefix name for identifier in the URL
25
 * @property string   lang_key_prefix    Prefix for the messages thrown by exceptions
26
 * @property language language           Language object
27
 * @property log      log                The phpBB log system
28
 * @property string   module_name        Name of the module currently used
29
 * @property request  request            Request object
30
 * @property bool     submit             State of submit $_POST variable
31
 * @property template template           Template object
32
 * @property string   u_action           Action URL
33
 * @property user     user               User object
34
 */
35
class paypal_features_controller extends admin_main
36
{
37
	protected $ppde_controller_main;
38
	protected $ppde_ipn_paypal;
39
40
	/**
41
	 * Constructor
42
	 *
43
	 * @param config          $config               Config object
44
	 * @param language        $language             Language object
45
	 * @param log             $log                  The phpBB log system
46
	 * @param main_controller $ppde_controller_main Main controller object
47
	 * @param ipn_paypal      $ppde_ipn_paypal      IPN PayPal object
48
	 * @param request         $request              Request object
49
	 * @param template        $template             Template object
50
	 * @param user            $user                 User object
51
	 *
52
	 * @access public
53
	 */
54
	public function __construct(
55
		config $config,
56
		language $language,
57
		log $log,
58
		main_controller $ppde_controller_main,
59
		ipn_paypal $ppde_ipn_paypal,
60
		request $request,
61
		template $template,
62
		user $user
63
	)
64
	{
65
		$this->config = $config;
66
		$this->language = $language;
67
		$this->log = $log;
68
		$this->ppde_controller_main = $ppde_controller_main;
69
		$this->ppde_ipn_paypal = $ppde_ipn_paypal;
70
		$this->request = $request;
71
		$this->template = $template;
72
		$this->user = $user;
73
		parent::__construct(
74
			'paypal_features',
75
			'PPDE_PAYPAL_FEATURES',
76
			''
77
		);
78
	}
79
80
	/**
81
	 * Display the settings a user can configure for this extension
82
	 *
83
	 * @return void
84
	 * @access public
85
	 */
86
	public function display_settings()
87
	{
88
		if ($this->config['ppde_first_start'])
89
		{
90
			$this->ppde_ipn_paypal->set_curl_info();
91
			$this->ppde_ipn_paypal->set_remote_detected();
92
			$this->ppde_ipn_paypal->check_tls();
93
			$this->config->set('ppde_first_start', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of phpbb\config\config::set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
			$this->config->set('ppde_first_start', /** @scrutinizer ignore-type */ false);
Loading history...
94
		}
95
96
		// Define the name of the form for use as a form key
97
		add_form_key('ppde_paypal_features');
98
99
		// Create an array to collect errors that will be output to the user
100
		$errors = array();
101
102
		$this->submit_settings();
103
104
		// Set output vars for display in the template
105
		$this->s_error_assign_template_vars($errors);
106
		$this->u_action_assign_template_vars();
107
		$this->template->assign_vars(array(
108
			// PayPal IPN vars
109
			'PPDE_IPN_AG_MIN_BEFORE_GROUP'   => $this->check_config($this->config['ppde_ipn_min_before_group'], 'integer', 0),
110
			'S_PPDE_IPN_AG_ENABLE'           => $this->check_config($this->config['ppde_ipn_autogroup_enable']),
111
			'S_PPDE_IPN_AG_GROUP_AS_DEFAULT' => $this->check_config($this->config['ppde_ipn_group_as_default']),
112
			'S_PPDE_IPN_DL_ENABLE'           => $this->check_config($this->config['ppde_ipn_donorlist_enable']),
113
			'S_PPDE_IPN_ENABLE'              => $this->check_config($this->config['ppde_ipn_enable']),
114
			'S_PPDE_IPN_GROUP_OPTIONS'       => group_select_options($this->config['ppde_ipn_group_id']),
0 ignored issues
show
Bug introduced by
$this->config['ppde_ipn_group_id'] of type string is incompatible with the type integer expected by parameter $group_id of group_select_options(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

114
			'S_PPDE_IPN_GROUP_OPTIONS'       => group_select_options(/** @scrutinizer ignore-type */ $this->config['ppde_ipn_group_id']),
Loading history...
115
			'S_PPDE_IPN_LOGGING'             => $this->check_config($this->config['ppde_ipn_logging']),
116
			'S_PPDE_IPN_NOTIFICATION_ENABLE' => $this->check_config($this->config['ppde_ipn_notification_enable']),
117
118
			// Sandbox Settings vars
119
			'PPDE_SANDBOX_ADDRESS'           => $this->check_config($this->config['ppde_sandbox_address'], 'string', ''),
120
			'S_PPDE_SANDBOX_ENABLE'          => $this->check_config($this->config['ppde_sandbox_enable']),
121
			'S_PPDE_SANDBOX_FOUNDER_ENABLE'  => $this->check_config($this->config['ppde_sandbox_founder_enable']),
122
		));
123
	}
124
125
	/**
126
	 * Set the options a user can configure
127
	 *
128
	 * @return void
129
	 * @access protected
130
	 */
131
	protected function set_settings()
132
	{
133
		// Set options for PayPal IPN
134
		$this->config->set('ppde_ipn_autogroup_enable', $this->request->variable('ppde_ipn_autogroup_enable', false));
135
		$this->config->set('ppde_ipn_donorlist_enable', $this->request->variable('ppde_ipn_donorlist_enable', false));
136
		$this->config->set('ppde_ipn_enable', $this->request->variable('ppde_ipn_enable', false));
137
		$this->config->set('ppde_ipn_group_as_default', $this->request->variable('ppde_ipn_group_as_default', false));
138
		$this->config->set('ppde_ipn_group_id', $this->request->variable('ppde_ipn_group_id', 0));
139
		$this->config->set('ppde_ipn_logging', $this->request->variable('ppde_ipn_logging', false));
140
		$this->config->set('ppde_ipn_min_before_group', $this->request->variable('ppde_ipn_min_before_group', 0));
141
		$this->config->set('ppde_ipn_notification_enable', $this->request->variable('ppde_ipn_notification_enable', false));
142
143
		// Set options for Sandbox Settings
144
		$this->config->set('ppde_sandbox_enable', $this->request->variable('ppde_sandbox_enable', false));
145
		$this->config->set('ppde_sandbox_founder_enable', $this->request->variable('ppde_sandbox_founder_enable', true));
146
147
		// Set misc settings
148
		$this->ppde_ipn_paypal->set_curl_info();
149
		$this->ppde_ipn_paypal->set_remote_detected();
150
		$this->ppde_ipn_paypal->check_tls();
151
		if (!$this->ppde_controller_main->is_ipn_requirement_satisfied())
152
		{
153
			$this->config->set('ppde_ipn_enable', false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $value of phpbb\config\config::set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

153
			$this->config->set('ppde_ipn_enable', /** @scrutinizer ignore-type */ false);
Loading history...
154
			trigger_error($this->language->lang($this->lang_key_prefix . '_NOT_ENABLEABLE') . adm_back_link($this->u_action), E_USER_WARNING);
155
		};
156
157
		// Settings with dependencies are the last to be set.
158
		$this->config->set('ppde_sandbox_address', $this->required_settings($this->request->variable('ppde_sandbox_address', ''), $this->depend_on('ppde_sandbox_enable')));
159
	}
160
}
161