| @@ -1,0 +1,60 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers\Fields; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\FieldClass; | |
| 6 | +use AcyMailing\Helpers\ToolbarHelper; | |
| 7 | + | |
| 8 | +trait Listing | |
| 9 | +{ | |
| 10 | + public function listing(): void | |
| 11 | + { | |
| 12 | + $data = []; | |
| 13 | + | |
| 14 | + if (!acym_level(ACYM_ENTERPRISE)) { | |
| 15 | + acym_setVar('layout', 'splashscreen'); | |
| 16 | + } | |
| 17 | + | |
| 18 | + parent::display($data); | |
| 19 | + } | |
| 20 | + | |
| 21 | + protected function prepareToolbar(array &$data): void | |
| 22 | + { | |
| 23 | + $toolbarHelper = new ToolbarHelper(); | |
| 24 | + $toolbarHelper->addButton(acym_translation('ACYM_CREATE'), ['data-task' => 'edit'], 'add', true); | |
| 25 | + | |
| 26 | + $data['toolbar'] = $toolbarHelper; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public function ajaxSetOrdering(): void | |
| 30 | + { | |
| 31 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 32 | + | |
| 33 | + $order = json_decode(acym_getVar('string', 'order'), true); | |
| 34 | + if (empty($order)) { | |
| 35 | + $order = []; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $i = 1; | |
| 39 | + $error = false; | |
| 40 | + foreach ($order as $field) { | |
| 41 | + $query = 'UPDATE #__acym_field SET `ordering` = '.intval($i).' WHERE `id` = '.intval($field); | |
| 42 | + $error = acym_query($query) < 0 || $error; | |
| 43 | + $i++; | |
| 44 | + } | |
| 45 | + | |
| 46 | + acym_sendAjaxResponse('', [], !$error); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public function delete(): void | |
| 50 | + { | |
| 51 | + $fieldClass = new FieldClass(); | |
| 52 | + $ids = acym_getVar('array', 'elements_checked', []); | |
| 53 | + if (in_array('1', $ids) || in_array('2', $ids) || in_array($fieldClass->getLanguageFieldId(), $ids)) { | |
| 54 | + acym_enqueueMessage(acym_translation('ACYM_CANT_DELETE'), 'error'); | |
| 55 | + $this->listing(); | |
| 56 | + } else { | |
| 57 | + parent::delete(); | |
| 58 | + } | |
| 59 | + } | |
| 60 | +} | |