PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Helpers/EntitySelectHelper.php +226 -0 10.1.0 → 11.1.0 View file →
@@ -1,0 +1,226 @@
1 +<?php
2 +
3 +namespace AcyMailing\Helpers;
4 +
5 +use AcyMailing\Core\AcymObject;
6 +
7 +class EntitySelectHelper extends AcymObject
8 +{
9 + private array $columnsHeaderNotToDisplay;
10 +
11 + public function __construct()
12 + {
13 + parent::__construct();
14 + $this->columnsHeaderNotToDisplay = ['color'];
15 + }
16 +
17 + public function entitySelect(array $options): string
18 + {
19 + $options['columnsToDisplay'] = $options['columnsToDisplay'] ?? ['name'];
20 + $options['buttonSubmit'] = $options['buttonSubmit'] ?? [
21 + 'text' => '',
22 + 'action' => '',
23 + 'class' => '',
24 + ];
25 + $options['displaySelected'] = $options['displaySelected'] ?? true;
26 + $options['displayedName'] = $options['displayedName'] ?? '';
27 +
28 + $columnJoin = '';
29 + if (!empty($options['columnsToDisplay']['join'])) {
30 + $columnJoin = explode('.', $options['columnsToDisplay']['join']);
31 + }
32 +
33 + unset($options['columnsToDisplay']['join']);
34 +
35 + if (empty($options['display'])) {
36 + ob_start();
37 + }
38 +
39 + echo '<div
40 + style="display: none;"
41 + id="acym__entity_select"
42 + class="acym__entity_select cell grid-x"
43 + data-display-selected="'.($options['displaySelected'] ? 'true' : 'false').'"
44 + data-entity="'.esc_attr($options['entity']).'"
45 + data-type="select"
46 + data-columns="'.esc_attr(implode(',', array_keys($options['columnsToDisplay']))).'"
47 + data-columns-class="'.esc_attr(json_encode($options['columnsToDisplay'])).'"
48 + data-join="'.esc_attr($options['entityParams']['join'] ?? '').'" ';
49 +
50 + if (!empty($columnJoin)) {
51 + echo ' data-column-join="'.esc_attr($columnJoin[1]).'" data-table-join="'.esc_attr($columnJoin[0]).'"';
52 + }
53 + echo '>';
54 +
55 + $this->displayListing('available', 'select', $options['entity'], $options['columnsToDisplay'], $options['displayedName']);
56 + echo '<div class="cell medium-shrink text-center grid-x acym_vcenter"><i class="acymicon-arrows-h cell"></i></div>';
57 + $this->displayListing('selected', 'unselect', $options['entity'], $options['columnsToDisplay'], $options['displayedName']);
58 +
59 + // Callable rendering extra content
60 + if (!empty($options['additionalData']) && !is_string($options['additionalData']) && is_callable($options['additionalData'])) {
61 + $options['additionalData']();
62 + }
63 +
64 + if (!empty($options['buttonSubmit']['text'])) {
65 + $class = !empty($options['buttonSubmit']['action']) ? 'acy_button_submit' : 'acym__entity_select__button__close';
66 + if (!empty($options['buttonSubmit']['class'])) {
67 + $class .= ' '.$options['buttonSubmit']['class'];
68 + }
69 + echo '<div class="cell grid-x align-center margin-top-1">';
70 + echo '<button
71 + type="button"
72 + id="acym__entity_select__button__submit"
73 + class="cell shrink grid-x '.esc_attr($class).' button" ';
74 + if (!empty($options['buttonSubmit']['action'])) {
75 + echo ' data-task="'.esc_attr($options['buttonSubmit']['action']).'"';
76 + }
77 + echo '>';
78 + echo esc_html($options['buttonSubmit']['text']);
79 + echo '</button>';
80 + echo '</div>';
81 + }
82 +
83 + echo '<input type="hidden" class="acym__entity_select__selected" name="acym__entity_select__selected" value="">';
84 + echo '<input type="hidden" class="acym__entity_select__unselected" name="acym__entity_select__unselected" value="">';
85 + echo '</div>';
86 +
87 + if (empty($options['display'])) {
88 + return ob_get_clean();
89 + }
90 +
91 + return '';
92 + }
93 +
94 + public function getColumnsForList(string $join = '', bool $small = false): array
95 + {
96 + $columns = [
97 + 'color' => $small ? 'small-2' : 'small-1',
98 + 'name' => 'auto',
99 + 'id' => 'small-2',
100 + ];
101 + if (!empty($join)) {
102 + $columns['join'] = $join;
103 + }
104 +
105 + return $columns;
106 + }
107 +
108 + public function getColumnsForUser(string $join = ''): array
109 + {
110 + $columns = [
111 + 'email' => 'auto',
112 + 'name' => 'auto',
113 + 'id' => 'small-1',
114 + ];
115 +
116 + if (!empty($join)) {
117 + $columns['join'] = $join;
118 + }
119 +
120 + return $columns;
121 + }
122 +
123 + private function displayListing(
124 + string $type,
125 + string $allSelector,
126 + string $entity,
127 + array $columnsToDisplay = [],
128 + string $displayedName = ''
129 + ): void {
130 + if (empty($displayedName)) {
131 + $displayedName = $entity;
132 + }
133 +
134 + echo '<div class="cell medium-auto grid-x acym_area acym__entity_select__'.esc_attr($type).'">
135 + <h5 class="cell font-bold acym__title acym__title__secondary text-center">'.esc_html(
136 + acym_translation('ACYM_'.strtoupper($type).'_'.strtoupper($displayedName))
137 + ).'</h5>
138 + <div class="cell grid-x">
139 + <div class="cell grid-x acym__entity_select__header">
140 + <div class="cell grid-x">
141 + <div class="cell margin-bottom-1"><input type="text" v-model="'.esc_attr($type).'Search" placeholder="'.esc_attr(acym_translation('ACYM_SEARCH')).'"></div>
142 + <div class="cell align-right grid-x acym__entity_select__select__all">
143 + <button type="button"
144 + v-show="!loading"
145 + v-if="displaySelectAll_'.esc_attr($type).'"
146 + v-on:click="moveAll('.esc_attr(json_encode($type)).')"
147 + class="cell shrink acym__entity_select__select__all__button acym__entity_select__select__all__button__'.esc_attr($type).'">'.esc_html(
148 + acym_translation('ACYM_'.strtoupper($allSelector).'_ALL')
149 + ).'</button>
150 + </div>
151 + </div>
152 + </div>
153 + <div v-infinite-scroll="loadMoreEntity'.esc_attr(
154 + ucfirst($type)
155 + ).'" :infinite-scroll-disabled="busy" class="acym__listing cell acym__entity_select__'.esc_attr($type).'__listing acym__content" infinite-scroll-distance="10">';
156 + $emptyMessage = acym_translation($type === 'available' ? 'ACYM_NOTHING_TO_SHOW_HERE_RIGHT_PANEL' : 'ACYM_PLEASE_CLICK_ON_THE_LEFT_PANEL');
157 + echo '<div class="cell text-center acym__entity_select__title margin-top-2" v-show="Object.keys(entitiesToDisplay_'.esc_attr(
158 + $type
159 + ).').length == 0 && !loading">'.esc_html($emptyMessage).'</div>
160 + <div class="cell acym_vcenter acym__listing__row grid-x acym__listing__row__header" v-if="Object.keys(entitiesToDisplay_'.esc_attr($type).').length != 0">';
161 +
162 + //Start the listing
163 +
164 + //if it's the select listing we display the - at the start
165 + if ($type !== 'available') {
166 + echo '<div class="cell small-1"></div>';
167 + }
168 +
169 + //We lists all the columns
170 + foreach ($columnsToDisplay as $column => $class) {
171 + echo '<div class="cell grid-x '.esc_attr($class).'">'.esc_html(
172 + in_array($column, $this->columnsHeaderNotToDisplay) ? '' : acym_translation('ACYM_'.strtoupper($column))
173 + ).'</div>';
174 + }
175 +
176 + //if it's the available listing we display the + at the end
177 + if ($type === 'available') {
178 + echo '<div class="cell small-1"></div>';
179 + }
180 + //end of listing header
181 + echo '</div>';
182 +
183 + //trigger the good function depending if were in available or selected listing
184 + $functionClick = $type === 'available' ? 'selectEntity(entity.id)' : 'unselectEntity(entity.id)';
185 + //each row of the listing
186 + echo '<div v-on:click="'.esc_attr($functionClick).'" v-for="(entity, index) in entitiesToDisplay_'.esc_attr(
187 + $type
188 + ).'" class="cell acym_vcenter acym__listing__row grid-x acym__entity_select__'.esc_attr($type).'__listing__row" >';
189 +
190 + //if it's the select listing we display the - at the start
191 + if ($type !== 'available') {
192 + echo '<div class="cell small-1 vertical-align-middle text-center">
193 + <div class="plus-container acym__entity_select__selected__listing__row__unselect">
194 + <div class="top-plus plus-bar"></div>
195 + <div class="plus plus-bar"></div>
196 + <div class="bottom-plus plus-bar"></div>
197 + </div>
198 + </div>';
199 + }
200 +
201 + //Display all the value for the columns
202 + echo '<div v-for="(column, index) in columnsToDisplay" class="cell align-center acym__entity_select__columns" :class="getClass(column)" v-html="entity[column]"></div>';
203 +
204 + //if it's the available listing we display the + at the end
205 + if ($type === 'available') {
206 + echo '<div class="cell small-1 vertical-align-middle text-center">
207 + <div class="plus-container acym__entity_select__available__listing__row__select">
208 + <div class="top-plus plus-bar"></div>
209 + <div class="plus plus-bar"></div>
210 + <div class="bottom-plus plus-bar"></div>
211 + </div>
212 + </div>';
213 + }
214 +
215 + //End of listing with message loading and loading logo
216 + echo '</div>
217 + <div class="cell grid-x align-center acym__entity_select__loading margin-top-1" v-show="loading"><div class="cell text-center acym__entity_select__title">';
218 + echo esc_html(acym_translation('ACYM_WE_ARE_LOADING_YOUR_DATA'));
219 + echo '</div><div class="cell grid-x shrink margin-top-1">';
220 + acym_loaderLogo(false);
221 + echo '</div></div>';
222 + echo '</div>';
223 + echo '</div>
224 + </div>';
225 + }
226 +}