PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Campaigns / Blocks / CampaignDonations / CampaignDonationsBlockViewModel.php

CampaignDonationsBlockViewModel.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Campaigns/Blocks/CampaignDonations/CampaignDonationsBlockViewModel.php

75 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Campaigns\Blocks\CampaignDonations;
4
5 use Give\Campaigns\Models\Campaign;
6 use Give\Framework\Support\ValueObjects\Money;
7 use Give\Framework\Views\View;
8
9 /**
10 * @since 4.0.0
11 */
12 class CampaignDonationsBlockViewModel
13 {
14 /**
15 * @var Campaign $campaign
16 */
17 private $campaign;
18
19 /**
20 * @var array
21 */
22 private $donations;
23
24 /**
25 * @var array $attributes
26 */
27 private $attributes;
28
29 /**
30 * @since 4.0.0
31 */
32 public function __construct(Campaign $campaign, array $donations, array $attributes)
33 {
34 $this->attributes = $attributes;
35 $this->campaign = $campaign;
36 $this->donations = $donations;
37 }
38
39 /**
40 * @since 4.0.0
41 */
42 public function render(): void
43 {
44 View::render('Campaigns/Blocks/CampaignDonations.render', [
45 'campaign' => $this->campaign,
46 'donations' => $this->formatDonationsData($this->donations),
47 'attributes' => $this->attributes,
48 ]);
49 }
50
51
52 /**
53 * @since 4.16.9 Added additional sanitization to donor data.
54 * @since 4.14.0 add avatar URL to donations data
55 * @since 4.0.0
56 */
57 private function formatDonationsData(array $donations): array
58 {
59 return array_map(static function ($entry) {
60 $entry->donorName = give_strip_shortcodes_deep($entry->donorName ?? '');
61 $entry->date = human_time_diff(strtotime($entry->date));
62 $entry->amount = Money::fromDecimal($entry->amount, give_get_currency());
63
64 if ($entry->isAnonymous) {
65 $entry->donorAvatarUrl = get_avatar_url(0, ['size' => 80]);
66 } else {
67 $entry->donorAvatarUrl = (int) $entry->donorAvatarId > 0
68 ? wp_get_attachment_image_url($entry->donorAvatarId, ['width' => '80', 'height' => '80'])
69 : get_avatar_url($entry->email, ['size' => 80]);
70 }
71 return $entry;
72 }, $donations);
73 }
74 }
75