PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
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 / Donors / CustomFields / Views / DonorDetailsView.php

DonorDetailsView.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Donors/CustomFields/Views/DonorDetailsView.php

107 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donors\CustomFields\Views;
4
5 use Give\Donors\Models\Donor;
6 use Give\Framework\FieldsAPI\Field;
7 use Give\Framework\FieldsAPI\Types;
8
9 /**
10 * @since 3.0.0
11 */
12 class DonorDetailsView
13 {
14 /** @var Donor */
15 protected $donor;
16
17 /** @var Field[] */
18 protected $fields;
19
20 /**
21 * @since 3.0.0
22 *
23 * @param Donor $donor
24 * @param Field[] $fields
25 */
26 public function __construct(Donor $donor, array $fields)
27 {
28 $this->donor = $donor;
29 $this->fields = $fields;
30 }
31
32 /**
33 * @since 3.0.0
34 *
35 * @return string
36 */
37 public function render(): string
38 {
39 return "<h3>{$this->getTitle()}</h3>
40 <table class='wp-list-table widefat striped donations'>
41 <thead>
42 <tr>
43 <th scope='col'>Field</th>
44 <th scope='col'>Value</th>
45 </tr>
46 </thead>
47 <tbody>
48 {$this->getTableRows()}
49 </tbody>
50 </table>";
51 }
52
53 /**
54 * @since 3.0.0
55 *
56 * @return string
57 */
58 protected function getTitle(): string
59 {
60 return __('Custom Fields', 'give');
61 }
62
63 /**
64 * @since 3.0.0
65 *
66 * @return string
67 */
68 protected function getTableRows(): string
69 {
70 return array_reduce($this->fields, function($output, Field $field) {
71 $value = $this->getFieldValue($field);
72 $label = method_exists($field, 'getLabel') ? $field->getLabel() : $field->getName();
73
74 if (empty($value)) {
75 return $output;
76 }
77
78 return $output . "
79 <tr>
80 <td>{$label}</td>
81 <td>{$value}</td>
82 </tr>
83 ";
84 }, '');
85 }
86
87 /**
88 * @since 3.0.0
89 *
90 * @return mixed
91 */
92 protected function getFieldValue(Field $field)
93 {
94 $metaValue = give()->donor_meta->get_meta($this->donor->id, $field->getName(), true);
95
96 if (empty($metaValue)) {
97 return '';
98 }
99
100 if ($field->getType() === Types::FILE) {
101 return wp_get_attachment_link($metaValue);
102 }
103
104 return $metaValue;
105 }
106 }
107