| @@ -1,0 +1,100 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers\Lists; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\TagClass; | |
| 6 | +use AcyMailing\Helpers\PaginationHelper; | |
| 7 | +use AcyMailing\Helpers\ToolbarHelper; | |
| 8 | + | |
| 9 | +trait Listing | |
| 10 | +{ | |
| 11 | + public function listing(): void | |
| 12 | + { | |
| 13 | + acym_setVar('layout', 'listing'); | |
| 14 | + | |
| 15 | + $tagClass = new TagClass(); | |
| 16 | + $data = []; | |
| 17 | + $data['search'] = $this->getVarFiltersListing('string', 'lists_search', ''); | |
| 18 | + $data['tag'] = $this->getVarFiltersListing('string', 'lists_tag', ''); | |
| 19 | + $data['ordering'] = $this->getVarFiltersListing('cmd', 'lists_ordering', 'id'); | |
| 20 | + $data['orderingSortOrder'] = $this->getVarFiltersListing('cmd', 'lists_ordering_sort_order', 'desc'); | |
| 21 | + $data['status'] = $this->getVarFiltersListing('string', 'lists_status', ''); | |
| 22 | + $data['allTags'] = $tagClass->getAllTagsByType(TagClass::TYPE_LIST); | |
| 23 | + $data['pagination'] = new PaginationHelper(); | |
| 24 | + | |
| 25 | + if (!empty($data['tag'])) { | |
| 26 | + $data['status_toolbar'] = [ | |
| 27 | + 'lists_tag' => $data['tag'], | |
| 28 | + ]; | |
| 29 | + } | |
| 30 | + | |
| 31 | + $this->prepareListsListing($data); | |
| 32 | + $this->prepareToolbar($data); | |
| 33 | + | |
| 34 | + parent::display($data); | |
| 35 | + } | |
| 36 | + | |
| 37 | + protected function prepareToolbar(array &$data): void | |
| 38 | + { | |
| 39 | + $toolbarHelper = new ToolbarHelper(); | |
| 40 | + $toolbarHelper->addSearchBar($data['search'], 'lists_search', 'ACYM_SEARCH'); | |
| 41 | + $toolbarHelper->addFilterByTag($data, 'lists_tag', 'acym__lists__filter__tags acym__select'); | |
| 42 | + | |
| 43 | + $toolbarHelper->addButton( | |
| 44 | + 'ACYM_ACYCHECKER_CLEAN_LISTS', | |
| 45 | + [ | |
| 46 | + 'data-task' => 'clean', | |
| 47 | + 'type' => 'submit', | |
| 48 | + ], | |
| 49 | + 'user-check' | |
| 50 | + ); | |
| 51 | + | |
| 52 | + $toolbarHelper->addButton( | |
| 53 | + acym_translation('ACYM_EXPORT').' (<span id="acym__lists__listing__number_to_export" data-default="0"></span>)', | |
| 54 | + ['data-task' => 'export', 'type' => 'submit', 'data-ctrl' => 'users', 'id' => 'acym__list__export'], | |
| 55 | + 'download' | |
| 56 | + ); | |
| 57 | + $toolbarHelper->addButton(acym_translation('ACYM_CREATE'), ['data-task' => 'settings'], 'playlist_add', true); | |
| 58 | + | |
| 59 | + $data['toolbar'] = $toolbarHelper; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public function clean(): void | |
| 63 | + { | |
| 64 | + if (acym_isAcyCheckerInstalled()) { | |
| 65 | + if (ACYM_CMS === 'joomla') { | |
| 66 | + acym_redirect(acym_route('index.php?option=com_acychecker', false)); | |
| 67 | + } else { | |
| 68 | + acym_redirect(admin_url().'admin.php?page=acychecker_dashboard'); | |
| 69 | + } | |
| 70 | + } else { | |
| 71 | + acym_redirect(acym_completeLink('dashboard&task=acychecker', false, true)); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 75 | + protected function prepareListsListing(array &$data): void | |
| 76 | + { | |
| 77 | + // Prepare the pagination | |
| 78 | + $listsPerPage = $data['pagination']->getListLimit(); | |
| 79 | + $page = $this->getVarFiltersListing('int', 'lists_pagination_page', 1); | |
| 80 | + | |
| 81 | + // Get the matching lists | |
| 82 | + $matchingLists = $this->getMatchingElementsFromData( | |
| 83 | + [ | |
| 84 | + 'search' => $data['search'], | |
| 85 | + 'tag' => $data['tag'], | |
| 86 | + 'ordering' => $data['ordering'], | |
| 87 | + 'ordering_sort_order' => $data['orderingSortOrder'], | |
| 88 | + 'elementsPerPage' => $listsPerPage, | |
| 89 | + 'offset' => ($page - 1) * $listsPerPage, | |
| 90 | + 'status' => $data['status'], | |
| 91 | + ], | |
| 92 | + $data['status'], | |
| 93 | + $page | |
| 94 | + ); | |
| 95 | + $data['pagination']->setStatus($matchingLists['total']->total, $page, $listsPerPage); | |
| 96 | + | |
| 97 | + $data['lists'] = $matchingLists['elements']; | |
| 98 | + $data['listNumberPerStatus'] = $matchingLists['status']; | |
| 99 | + } | |
| 100 | +} | |