Completed
Branch GDPR/privacy-policy-content (f954f3)
by
unknown
60:17 queued 46:07
created

PrivacyPolicy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\services\admin\privacy\policy;
4
5
use EEH_Template;
6
use EEM_Payment_Method;
7
use EventEspresso\core\domain\values\session\SessionLifespan;
8
use EventEspresso\core\services\privacy\policy\PrivacyPolicyInterface;
9
10
/**
11
 * Class PrivacyPolicy
12
 * Class describes the Event Espresso core plugin's privacy policy.
13
 *
14
 * @package        Event Espresso
15
 * @author         Mike Nelson
16
 * @since          $VID:$
17
 */
18
class PrivacyPolicy implements PrivacyPolicyInterface
19
{
20
21
    /**
22
     * @var EEM_Payment_Method
23
     */
24
    protected $payment_method_model;
25
26
    /**
27
     * @var SessionLifespan
28
     */
29
    protected $session_lifespan;
30
31
    /**
32
     * PrivacyPolicy constructor.
33
     *
34
     * @param EEM_Payment_Method $payment_method_model
35
     */
36
    public function __construct(EEM_Payment_Method $payment_method_model, SessionLifespan $session_lifespan)
37
    {
38
        $this->payment_method_model = $payment_method_model;
39
        $this->session_lifespan = $session_lifespan;
40
    }
41
42
43
    /**
44
     * Returns the name of the plugin and will be shown in the privacy policy's postbox header
45
     *
46
     * @return string
47
     */
48
    public function getName()
49
    {
50
        return esc_html__('Event Espresso', 'event_espresso');
51
    }
52
53
54
    /**
55
     * Gets the HTML for the privacy policy. May be dynamic
56
     *
57
     * @return string
58
     */
59
    public function getContent()
60
    {
61
        // do they have any offsite payment methods? or onsite payment methods?
62
        $active_payment_methods = $this->payment_method_model->get_all_active(EEM_Payment_Method::scope_cart);
63
        $active_onsite_pms = false;
64
        $active_offsite_pms = false;
65
        foreach ($active_payment_methods as $payment_method) {
66
            if ($payment_method->type_obj() instanceof \EE_PMT_Base) {
67
                if ($payment_method->type_obj()->get_gateway() instanceof \EE_Onsite_Gateway) {
68
                    $active_onsite_pms[] = $payment_method->name();
69
                } elseif ($payment_method->type_obj()->get_gateway() instanceof \EE_Offsite_Gateway) {
70
                    $active_offsite_pms[] = $payment_method->name();
71
                }
72
            }
73
        }
74
        $session_lifespan_in_hours = round($this->session_lifespan->inSeconds() / HOUR_IN_SECONDS);
75
        return (string) EEH_Template::display_template(
76
            __DIR__ . '/privacy_policy.template.php',
77
            array(
78
                'active_onsite_payment_methods' => $active_onsite_pms,
79
                'active_offsite_payment_methods' => $active_offsite_pms,
80
                'session_lifespan' => sprintf(
81
                    _n(
82
                        '%1$s hour',
83
                        '%1$s hours',
84
                        $session_lifespan_in_hours,
85
                        'event_espresso'
86
                    ),
87
                    $session_lifespan_in_hours
88
                )
89
            ),
90
            true
91
        );
92
    }
93
}
94
// End of file PrivacyPolicy.php
95
// Location: EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy.php
96