PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
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/Controllers/EntitySelectController.php +0 -118 trunk → 11.1.1 View file →
@@ -1,118 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Controllers;
4 -
5 -use AcyMailing\Core\AcymController;
6 -
7 -class EntitySelectController extends AcymController
8 -{
9 - public function __construct()
10 - {
11 - parent::__construct();
12 -
13 - $this->loadScripts = [
14 - 'all' => ['vue-applications' => ['entity_select']],
15 - ];
16 - }
17 -
18 - public function loadEntityFront(): void
19 - {
20 - $entity = acym_getVar('string', 'entity');
21 - $offset = acym_getVar('int', 'offset');
22 - $perCalls = acym_getVar('int', 'perCalls');
23 - $join = acym_getVar('string', 'join');
24 - $joinColumnGet = acym_getVar('string', 'join_table', '');
25 - $columnsToDisplay = explode(',', acym_getVar('string', 'columns', ''));
26 - if (!empty($joinColumnGet)) {
27 - $columnsToDisplay['join'] = $joinColumnGet;
28 - }
29 -
30 - $entityBack = $this->loadEntityBack($entity, $offset, $perCalls, $join, $columnsToDisplay);
31 - if (!empty($entityBack['error'])) {
32 - acym_sendAjaxResponse($entityBack['error'], [], false);
33 - } else {
34 - acym_sendAjaxResponse('', ['results' => $entityBack]);
35 - }
36 - }
37 -
38 - private function loadEntityBack(string $entity, int $offset, int $perCalls, string $join, array $columnsToDisplay): array
39 - {
40 - if (empty($entity) || (empty($offset) && 0 !== $offset) || empty($perCalls)) {
41 - return ['error' => acym_translation('ACYM_MISSING_PARAMETERS')];
42 - }
43 -
44 - if (!in_array($entity, ['list', 'user'])) {
45 - return ['error' => acym_translation('ACYM_UNAUTHORIZED_ACCESS')];
46 - }
47 -
48 - $entityParams = [
49 - 'offset' => $offset,
50 - 'elementsPerPage' => $perCalls,
51 - 'entitySelect' => true,
52 - ];
53 - if ($entity === 'list') {
54 - $entityParams['status'] = 'active';
55 - }
56 - if (!empty($join)) {
57 - $entityParams['join'] = $join;
58 - }
59 - if (!empty($columnsToDisplay)) {
60 - foreach ($columnsToDisplay as $column) {
61 - acym_secureDBColumn($column);
62 - }
63 - $entityParams['columns'] = $columnsToDisplay;
64 - }
65 -
66 - if ('list' === $entity) {
67 - $entityParams['columns'][] = 'description';
68 - $entityParams['columns'][] = 'active';
69 - }
70 -
71 - if (!acym_isAdmin()) {
72 - $entityParams['creator_id'] = acym_currentUserId();
73 - }
74 -
75 - $namespaceClass = 'AcyMailing\\Classes\\'.ucfirst($entity).'Class';
76 - $entityClass = new $namespaceClass();
77 -
78 - $availableEntity = $entityClass->getMatchingElements($entityParams);
79 -
80 - $this->formatEntites($availableEntity, $entity);
81 -
82 - return ['data' => empty($availableEntity) ? 'end' : $availableEntity];
83 - }
84 -
85 - private function formatEntites(array &$availableEntity, string $entity): void
86 - {
87 - if ($entity === 'list') {
88 - foreach ($availableEntity['elements'] as $key => $element) {
89 - $availableEntity['elements'][$key]->color = '<i style="color: '.esc_attr(
90 - $element->color ?? '#0079d3'
91 - ).'" class="acym_subscription acymicon-circle">';
92 - $availableEntity['elements'][$key]->name = esc_html($element->name);
93 - if (empty($element->active)) {
94 - $availableEntity['elements'][$key]->name .= '<span class="acym__entity_select__list__inactive">'.esc_html(
95 - acym_translation('ACYM_INACTIVE')
96 - ).'</span>';
97 - }
98 - if (!empty($element->description)) {
99 - ob_start();
100 - acym_info(['textShownInTooltip' => esc_html($element->description)]);
101 - $availableEntity['elements'][$key]->name .= ob_get_clean();
102 - }
103 - }
104 - } elseif ($entity === 'user') {
105 - foreach ($availableEntity['elements'] as $key => $element) {
106 - ob_start();
107 - acym_info(['textShownInTooltip' => '<i class="acymicon-circle-o-notch acymicon-spin"></i>']);
108 - $tooltip = ob_get_clean();
109 - $availableEntity['elements'][$key]->name = esc_html($element->name ?? '');
110 - $availableEntity['elements'][$key]->email = esc_html($element->email).'<span class="acym__hover__user_info" data-id="'.esc_attr(
111 - $element->id
112 - ).'">
113 - '.$tooltip.'
114 - </span>';
115 - }
116 - }
117 - }
118 -}