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 / FormTaxonomies / ViewModels / FormTaxonomyViewModel.php

FormTaxonomyViewModel.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/FormTaxonomies/ViewModels/FormTaxonomyViewModel.php

105 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\FormTaxonomies\ViewModels;
4
5 /**
6 * @since 3.16.0
7 */
8 class FormTaxonomyViewModel
9 {
10 /**
11 * @since 3.16.0
12 * @var int
13 */
14 protected $formId;
15
16 /**
17 * @since 3.16.0
18 * @var array
19 */
20 protected $settings;
21
22 /**
23 * @since 3.16.0
24 */
25 public function __construct(int $formId, array $settings)
26 {
27 $this->formId = $formId;
28 $this->settings = $settings;
29 }
30
31 /**
32 * @since 3.16.0
33 */
34 public function isFormTagsEnabled(): bool
35 {
36 return give_is_setting_enabled($this->settings['tags']);
37 }
38
39 /**
40 * @since 3.16.0
41 */
42 public function isFormCategoriesEnabled(): bool
43 {
44 return give_is_setting_enabled($this->settings['categories']);
45 }
46
47 /**
48 * @since 3.16.0
49 */
50 public function getSelectedFormTags(): array
51 {
52 if(!$this->isFormTagsEnabled()) {
53 return [];
54 }
55
56 $terms = wp_get_post_terms($this->formId, 'give_forms_tag');
57
58 return array_map(function ($term) {
59 return [
60 'id' => $term->term_id,
61 'value' => $term->name,
62 ];
63 }, $terms) ?? [];
64 }
65
66 /**
67 * @since 3.16.0
68 */
69 public function getFormCategories(): array
70 {
71 if(!$this->isFormCategoriesEnabled()) {
72 return [];
73 }
74
75 $terms = get_terms([
76 'taxonomy' => 'give_forms_category',
77 'hide_empty' => false,
78 ]);
79
80 return array_map(function ($term) {
81 return [
82 'id' => $term->term_id,
83 'name' => $term->name,
84 'parent' => $term->parent,
85 ];
86 }, $terms) ?? [];
87 }
88
89 /**
90 * @since 3.16.0
91 */
92 public function getSelectedFormCategories(): array
93 {
94 if(!$this->isFormCategoriesEnabled()) {
95 return [];
96 }
97
98 $terms = wp_get_post_terms($this->formId, 'give_forms_category');
99
100 return array_map(function ($term) {
101 return $term->term_id;
102 }, $terms) ?? [];
103 }
104 }
105