Passed
Pull Request — master (#48)
by
unknown
02:31
created

getAllowedCountriesSerialized()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
4
class WC_Pagantis_Config
5
{
6
7
8
    /**
9
     * @param      $key
10
     * @param bool $unSerialized
11
     *
12
     * @return mixed
13
     */
14
    public static function getValueOfKey($key, $unSerialized = false)
15
    {
16
        include_once('class-wc-pagantis-logger.php');
17
        $config = self::getExtraConfig();
18
        $value  = $config[$key];
19
        if ($unSerialized === true) {
20
            return unserialize($value);
21
        } else {
22
            return $value;
23
        }
24
    }
25
26
    /**
27
     * @return array
28
     */
29
30
    public static function getDefaultConfig()
31
    {
32
        return  array(
33
        'PAGANTIS_TITLE'                           => 'Pago en cuotas',
34
        'PAGANTIS_SIMULATOR_DISPLAY_TYPE'          => 'sdk.simulator.types.PRODUCT_PAGE',
35
        'PAGANTIS_SIMULATOR_DISPLAY_TYPE_CHECKOUT' => 'sdk.simulator.types.CHECKOUT_PAGE',
36
        'PAGANTIS_SIMULATOR_DISPLAY_SKIN'          => 'sdk.simulator.skins.BLUE',
37
        'PAGANTIS_SIMULATOR_DISPLAY_POSITION'      => 'hookDisplayProductButtons',
38
        'PAGANTIS_SIMULATOR_START_INSTALLMENTS'    => 3,
39
        'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'      => 12,
40
        'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR' => 'default',
41
        'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'  => 'sdk.simulator.positions.INNER',
42
        'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'    => 'a:3:{i:0;s:48:"div.summary *:not(del)>.woocommerce-Price-amount";i:1;s:54:"div.entry-summary *:not(del)>.woocommerce-Price-amount";i:2;s:36:"*:not(del)>.woocommerce-Price-amount";}',
43
        'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR' => 'a:2:{i:0;s:22:"div.quantity input.qty";i:1;s:18:"div.quantity>input";}',
44
        'PAGANTIS_FORM_DISPLAY_TYPE'               => 0,
45
        'PAGANTIS_DISPLAY_MIN_AMOUNT'              => 1,
46
        'PAGANTIS_DISPLAY_MAX_AMOUNT'              => 0,
47
        'PAGANTIS_URL_OK'                          => '',
48
        'PAGANTIS_URL_KO'                          => '',
49
        'PAGANTIS_ALLOWED_COUNTRIES'               => 'a:3:{i:0;s:2:"es";i:1;s:2:"it";i:2;s:2:"fr";}',
50
        'PAGANTIS_PROMOTION_EXTRA'                 => '<p>Finance this product <span class="pg-no-interest">without interest!</span></p>',
51
        'PAGANTIS_SIMULATOR_THOUSANDS_SEPARATOR'   => '.',
52
        'PAGANTIS_SIMULATOR_DECIMAL_SEPARATOR'     => ',',
53
        'PAGANTIS_SIMULATOR_DISPLAY_SITUATION'     => 'default',
54
        'PAGANTIS_SIMULATOR_SELECTOR_VARIATION'    => 'default'
55
        );
56
    }
57
    /**
58
     * Get extra config from WP DB
59
     * @global wpdb $wpdb WordPress database abstraction object.
60
     * @return array
61
     */
62
    public static function getExtraConfig()
63
    {
64
        global $wpdb;
65
        $tableName = $wpdb->prefix . PAGANTIS_CONFIG_TABLE;
66
        $response  = array();
67
        $dbResult  = $wpdb->get_results("select config, value from $tableName", ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
68
        foreach ($dbResult as $value) {
69
            $response[$value['config']] = $value['value'];
70
        }
71
72
        return $response;
73
    }
74
75
    /**
76
     * @return mixed
77
     */
78
    public static function getAllowedCountriesSerialized()
79
    {
80
        $allowedCountries = WC_Pagantis_Config::getValueOfKey('PAGANTIS_ALLOWED_COUNTRIES', true);
81
82
        return $allowedCountries;
83
    }
84
}
85