| @@ -7,17 +7,21 @@ | ||
| 7 | 7 | use AcyMailing\Helpers\ToolbarHelper; |
| 8 | 8 | |
| 9 | 9 | trait Listing |
| 10 | 10 | { |
| 11 | - function listing(): void | |
| 11 | + public function listing(): void | |
| 12 | 12 | { |
| 13 | 13 | if (!acym_level(ACYM_ENTERPRISE)) { |
| 14 | 14 | acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true)); |
| 15 | 15 | } |
| 16 | + $ordering = $this->getVarFiltersListing('cmd', 'scenario_ordering', 'ordering'); | |
| 17 | + $orderingSortOrder = $this->getVarFiltersListing('cmd', 'scenario_ordering_sort_order', 'asc'); | |
| 16 | 18 | |
| 17 | 19 | acym_setVar('layout', 'listing'); |
| 18 | 20 | |
| 19 | 21 | $data = [ |
| 22 | + 'ordering' => $ordering, | |
| 23 | + 'ordering_sort_order' => $orderingSortOrder, | |
| 20 | 24 | 'pagination' => new PaginationHelper(), |
| 21 | 25 | ]; |
| 22 | 26 | |
| 23 | 27 | $this->prepareListingFilters($data); |
| @@ -30,15 +34,16 @@ | ||
| 30 | 34 | private function prepareListingFilters(array &$data): void |
| 31 | 35 | { |
| 32 | 36 | $data['search'] = $this->getVarFiltersListing('string', 'scenario_search', ''); |
| 33 | 37 | $data['status'] = $this->getVarFiltersListing('string', 'scenarios_status', ''); |
| 34 | - $data['ordering'] = $this->getVarFiltersListing('string', 'scenarios_ordering', 'id'); | |
| 35 | - $data['ordering_sort_order'] = $this->getVarFiltersListing('string', 'scenarios_ordering_sort_order', 'asc'); | |
| 38 | + $data['ordering'] = $this->getVarFiltersListing('cmd', 'scenarios_ordering', 'id'); | |
| 39 | + $data['ordering_sort_order'] = $this->getVarFiltersListing('cmd', 'scenarios_ordering_sort_order', 'asc'); | |
| 36 | 40 | $data['page'] = $this->getVarFiltersListing('int', 'scenarios_pagination_page', 1); |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | private function prepareListingElements(array &$data): void |
| 40 | 44 | { |
| 45 | + // Prepare the pagination | |
| 41 | 46 | $scenarioPerPage = $data['pagination']->getListLimit(); |
| 42 | 47 | |
| 43 | 48 | $matchingScenarios = $this->getMatchingElementsFromData( |
| 44 | 49 | [ |
| @@ -69,9 +74,9 @@ | ||
| 69 | 74 | } |
| 70 | 75 | |
| 71 | 76 | public function duplicate(): void |
| 72 | 77 | { |
| 73 | - acym_checkToken(); | |
| 78 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 74 | 79 | |
| 75 | 80 | $scenarioIds = acym_getVar('array', 'elements_checked', []); |
| 76 | 81 | |
| 77 | 82 | acym_arrayToInteger($scenarioIds); |
| @@ -86,6 +91,21 @@ | ||
| 86 | 91 | $scenarioClass->duplicate($scenarioId); |
| 87 | 92 | } |
| 88 | 93 | |
| 89 | 94 | $this->listing(); |
| 95 | + } | |
| 96 | + | |
| 97 | + public function ajaxSetOrdering(): void | |
| 98 | + { | |
| 99 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 100 | + | |
| 101 | + $order = json_decode(acym_getVar('string', 'order', '[]'), true); | |
| 102 | + | |
| 103 | + $error = false; | |
| 104 | + foreach ($order as $index => $scenarioId) { | |
| 105 | + $query = 'UPDATE #__acym_scenario SET `ordering` = '.intval($index + 1).' WHERE `id` = '.intval($scenarioId); | |
| 106 | + $error = acym_query($query) < 0 || $error; | |
| 107 | + } | |
| 108 | + | |
| 109 | + acym_sendAjaxResponse('', [], !$error); | |
| 90 | 110 | } |
| 91 | 111 | } |