| @@ -1,90 +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 | - $entityParams = [ | |
| 45 | - 'offset' => $offset, | |
| 46 | - 'elementsPerPage' => $perCalls, | |
| 47 | - 'entitySelect' => true, | |
| 48 | - ]; | |
| 49 | - if ($entity === 'list') { | |
| 50 | - $entityParams['status'] = 'active'; | |
| 51 | - } | |
| 52 | - if (!empty($join)) $entityParams['join'] = $join; | |
| 53 | - if (!empty($columnsToDisplay)) $entityParams['columns'] = $columnsToDisplay; | |
| 54 | - | |
| 55 | - if ('list' === $entity) { | |
| 56 | - $entityParams['columns'][] = 'description'; | |
| 57 | - } | |
| 58 | - | |
| 59 | - if (!acym_isAdmin()) { | |
| 60 | - $entityParams['creator_id'] = acym_currentUserId(); | |
| 61 | - } | |
| 62 | - | |
| 63 | - $namespaceClass = 'AcyMailing\\Classes\\'.ucfirst($entity).'Class'; | |
| 64 | - $entityClass = new $namespaceClass; | |
| 65 | - | |
| 66 | - $availableEntity = $entityClass->getMatchingElements($entityParams); | |
| 67 | - | |
| 68 | - $this->formatEntites($availableEntity, $entity); | |
| 69 | - | |
| 70 | - return ['data' => empty($availableEntity) ? 'end' : $availableEntity]; | |
| 71 | - } | |
| 72 | - | |
| 73 | - private function formatEntites(array &$availableEntity, string $entity): void | |
| 74 | - { | |
| 75 | - if ($entity === 'list') { | |
| 76 | - foreach ($availableEntity['elements'] as $key => $element) { | |
| 77 | - $availableEntity['elements'][$key]->color = '<i style="color: '.$element->color.'" class="acym_subscription acymicon-circle">'; | |
| 78 | - if (!empty($element->description)) { | |
| 79 | - $availableEntity['elements'][$key]->name = $element->name.acym_info($element->description); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - } elseif ($entity === 'user') { | |
| 83 | - foreach ($availableEntity['elements'] as $key => $element) { | |
| 84 | - $availableEntity['elements'][$key]->email = $element->email.'<span class="acym__hover__user_info" data-id="'.$availableEntity['elements'][$key]->id.'"> | |
| 85 | - '.acym_info('<i class="acymicon-circle-o-notch acymicon-spin"></i>').' | |
| 86 | - </span>'; | |
| 87 | - } | |
| 88 | - } | |
| 89 | - } | |
| 90 | -} | |