Skip to content

Commit

Permalink
Refactor Main donate class
Browse files Browse the repository at this point in the history
  • Loading branch information
Skouat committed Oct 6, 2024
1 parent 59400aa commit 5a7b5f9
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 198 deletions.
23 changes: 22 additions & 1 deletion actions/currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function get_default_currency_data(): array
* Formats the given value as currency based on the PHP intl extension, if available.
* Otherwise, a basic currency formatter is used.
*
* @param float $amount The amount to be formatted as currency.
* @param float $amount The amount to be formatted as currency.
* @return string The formatted currency string.
*/
public function format_currency(float $amount): string
Expand Down Expand Up @@ -128,6 +128,27 @@ public function build_currency_select_menu(int $config_value = 0): void
}
}

/**
* Build pull down menu options of available currency value
*
* @param string $dropbox_value Comma-separated list of currency values
* @param int $default_value Default selected value
* @return string HTML options for select menu
*/
public function build_currency_value_select_menu(string $dropbox_value, int $default_value): string
{
$values = array_filter(array_map('intval', explode(',', $dropbox_value)));
$options = '';

foreach ($values as $value)
{
$selected = ($value == $default_value) ? ' selected' : '';
$options .= '<option value="' . $value . '"' . $selected . '>' . $value . '</option>';
}

return $options;
}

/**
* Assign currency information to the template.
*
Expand Down
2 changes: 1 addition & 1 deletion controller/admin/paypal_features_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ protected function set_settings(): void

// Settings with dependencies are the last to be set.
$this->config->set('ppde_sandbox_address', $this->required_settings($this->request->variable('ppde_sandbox_address', ''), (bool) $this->config['ppde_sandbox_enable']));
$this->ppde_controller_main->ppde_actions_auth->set_guest_acl();
$this->ppde_controller_main->actions_auth->set_guest_acl();
}
}
39 changes: 19 additions & 20 deletions controller/main_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* PayPal Donation extension for the phpBB Forum Software package.
*
* @copyright (c) 2015-2020 Skouat
* @copyright (c) 2015-2024 Skouat
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
Expand All @@ -21,35 +21,34 @@

class main_controller
{
public $actions_auth;
protected $config;
protected $container;
protected $helper;
protected $language;
protected $ppde_actions_currency;
protected $actions_currency;
protected $request;
protected $template;
protected $user;
protected $user_loader;
protected $root_path;
protected $php_ext;

public $ppde_actions_auth;

/**
* Constructor
*
* @param config $config Config object
* @param ContainerInterface $container Service container interface
* @param helper $helper Controller helper object
* @param language $language Language user object
* @param \skouat\ppde\actions\auth $ppde_actions_auth PPDE auth actions object
* @param \skouat\ppde\actions\currency $ppde_actions_currency PPDE currency actions object
* @param request $request Request object
* @param template $template Template object
* @param user $user User object
* @param user_loader $user_loader User loader object
* @param string $root_path phpBB root path
* @param string $php_ext phpEx
* @param config $config Config object
* @param ContainerInterface $container Service container interface
* @param helper $helper Controller helper object
* @param language $language Language user object
* @param \skouat\ppde\actions\auth $actions_auth PPDE auth actions object
* @param \skouat\ppde\actions\currency $actions_currency PPDE currency actions object
* @param request $request Request object
* @param template $template Template object
* @param user $user User object
* @param user_loader $user_loader User loader object
* @param string $root_path phpBB root path
* @param string $php_ext phpEx
*
* @access public
*/
Expand All @@ -58,8 +57,8 @@ public function __construct(
ContainerInterface $container,
helper $helper,
language $language,
\skouat\ppde\actions\auth $ppde_actions_auth,
\skouat\ppde\actions\currency $ppde_actions_currency,
\skouat\ppde\actions\auth $actions_auth,
\skouat\ppde\actions\currency $actions_currency,
request $request,
template $template,
user $user,
Expand All @@ -72,8 +71,8 @@ public function __construct(
$this->container = $container;
$this->helper = $helper;
$this->language = $language;
$this->ppde_actions_auth = $ppde_actions_auth;
$this->ppde_actions_currency = $ppde_actions_currency;
$this->actions_auth = $actions_auth;
$this->actions_currency = $actions_currency;
$this->request = $request;
$this->template = $template;
$this->user = $user;
Expand Down
Loading

0 comments on commit 5a7b5f9

Please sign in to comment.