Passed
Push — develop-3.2.x-2.2 ( c69971...0ffaad )
by Mario
02:29
created

donation::set_config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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\notification;
12
13
/**
14
 * PayPal Donation notifications class
15
 * This class handles notifications for Admin received donation
16
 */
17
abstract class donation extends \phpbb\notification\type\base
18
{
19
	/**
20
	 * {@inheritdoc}
21
	 */
22
	public static $notification_option = [];
23
	/** @var \phpbb\config\config */
24
	protected $config;
25
	/** @var \phpbb\user_loader */
26
	protected $user_loader;
27
28
	/**
29
	 * {@inheritdoc}
30
	 */
31
	public static function get_item_id($data)
32
	{
33
		return (int) $data['transaction_id'];
34
	}
35
36
	/**
37
	 * {@inheritdoc}
38
	 */
39
	public static function get_item_parent_id($data)
40
	{
41
		// No parent
42
		return 0;
43
	}
44
45
	/**
46
	 * {@inheritdoc}
47
	 */
48
	public function get_type()
49
	{
50
		return '';
51
	}
52
53
	public function set_config(\phpbb\config\config $config)
54
	{
55
		$this->config = $config;
56
	}
57
58
	public function set_user_loader(\phpbb\user_loader $user_loader)
59
	{
60
		$this->user_loader = $user_loader;
61
	}
62
63
	/**
64
	 * {@inheritdoc}
65
	 */
66
	public function get_avatar()
67
	{
68
		return $this->user_loader->get_avatar($this->get_data('user_from'), false, true);
69
	}
70
71
	/**
72
	 * {@inheritdoc}
73
	 */
74
	public function get_email_template_variables()
75
	{
76
		return [
77
			'MC_GROSS'       => html_entity_decode($this->get_data('mc_gross'), ENT_COMPAT | ENT_HTML5, 'UTF-8'),
78
			'NET_AMOUNT'     => html_entity_decode($this->get_data('net_amount'), ENT_COMPAT | ENT_HTML5, 'UTF-8'),
79
			'PAYER_EMAIL'    => htmlspecialchars_decode($this->get_data('payer_email')),
80
			'PAYER_USERNAME' => $this->get_data('payer_username'),
81
			'SETTLE_AMOUNT'  => html_entity_decode($this->get_data('settle_amount'), ENT_COMPAT | ENT_HTML5, 'UTF-8'),
82
			'TXN_ID'         => $this->get_data('txn_id'),
83
		];
84
	}
85
86
	/**
87
	 * {@inheritdoc}
88
	 */
89
	public function get_url()
90
	{
91
		return '';
92
	}
93
94
	/**
95
	 * {@inheritdoc}
96
	 */
97
	public function find_users_for_notification($data, $options = [])
98
	{
99
		$options = array_merge([
100
			'ignore_users' => [],
101
		], $options);
102
103
		// Grab admins that have permission to administer extension.
104
		$admin_ary = $this->auth->acl_get_list(false, 'a_ppde_manage', false);
105
		$users = (!empty($admin_ary[0]['a_ppde_manage'])) ? $admin_ary[0]['a_ppde_manage'] : [];
106
107
		if (empty($users))
108
		{
109
			return [];
110
		}
111
112
		sort($users);
113
114
		return $this->check_user_notification_options($users, $options);
115
	}
116
117
	/**
118
	 * {@inheritdoc}
119
	 */
120
	public function users_to_query()
121
	{
122
		return [$this->get_data('user_from')];
123
	}
124
125
	/**
126
	 * {@inheritdoc}
127
	 */
128
	public function create_insert_array($data, $pre_create_data = [])
129
	{
130
		$this->set_data('mc_gross', $data['mc_gross']);
131
		$this->set_data('net_amount', $data['net_amount']);
132
		$this->set_data('payer_email', $data['payer_email']);
133
		$this->set_data('payer_username', $data['payer_username']);
134
		$this->set_data('settle_amount', $data['settle_amount']);
135
		$this->set_data('transaction_id', $data['transaction_id']);
136
		$this->set_data('txn_id', $data['txn_id']);
137
		$this->set_data('user_from', $data['user_from']);
138
139
		parent::create_insert_array($data, $pre_create_data);
140
	}
141
}
142