| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers\MailboxActions; |
| 4 |
|
| 5 |
use AcyMailing\Classes\MailboxClass; |
| 6 |
use AcyMailing\Helpers\PaginationHelper; |
| 7 |
use AcyMailing\Helpers\WorkflowHelper; |
| 8 |
|
| 9 |
trait Listing |
| 10 |
{ |
| 11 |
private function prepareMailboxesActions(&$data) |
| 12 |
{ |
| 13 |
if (empty($data['allMailboxes'])) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
foreach ($data['allMailboxes'] as $key => $oneMailbox) { |
| 18 |
$data['allMailboxes'][$key]->actionsRendered = []; |
| 19 |
|
| 20 |
$actions = json_decode($oneMailbox->actions, true); |
| 21 |
if (empty($actions)) { |
| 22 |
continue; |
| 23 |
} |
| 24 |
|
| 25 |
$actionsRendered = []; |
| 26 |
foreach ($actions as $action) { |
| 27 |
acym_trigger('onAcymMailboxActionSummaryListing', [&$action, &$actionsRendered]); |
| 28 |
} |
| 29 |
|
| 30 |
$data['allMailboxes'][$key]->actionsRendered = $actionsRendered; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
public function prepareMailboxesListing(&$data) |
| 35 |
{ |
| 36 |
$mailboxesPerPage = $data['pagination']->getListLimit(); |
| 37 |
$page = $this->getVarFiltersListing('int', 'mailboxes_pagination_page', 1); |
| 38 |
$status = $data['status']; |
| 39 |
|
| 40 |
$matchingMailboxes = $this->getMatchingElementsFromData( |
| 41 |
[ |
| 42 |
'ordering' => $data['ordering'], |
| 43 |
'search' => $data['search'], |
| 44 |
'elementsPerPage' => $mailboxesPerPage, |
| 45 |
'offset' => ($page - 1) * $mailboxesPerPage, |
| 46 |
'ordering_sort_order' => $data['orderingSortOrder'], |
| 47 |
'status' => $status, |
| 48 |
], |
| 49 |
$status, |
| 50 |
$page, |
| 51 |
'mailbox' |
| 52 |
); |
| 53 |
|
| 54 |
$totalElement = $matchingMailboxes['total']; |
| 55 |
$data['allStatusFilters'] = [ |
| 56 |
'all' => $matchingMailboxes['total']->total, |
| 57 |
'active' => $matchingMailboxes['total']->totalActive, |
| 58 |
'inactive' => $matchingMailboxes['total']->total - $matchingMailboxes['total']->totalActive, |
| 59 |
]; |
| 60 |
$data['pagination']->setStatus($totalElement->total, $page, $mailboxesPerPage); |
| 61 |
$data['allMailboxes'] = $matchingMailboxes['elements']; |
| 62 |
} |
| 63 |
|
| 64 |
public function mailboxes() |
| 65 |
{ |
| 66 |
acym_setVar('layout', 'mailboxes'); |
| 67 |
acym_setVar('task', 'mailboxes'); |
| 68 |
|
| 69 |
$data = [ |
| 70 |
'pagination' => new PaginationHelper(), |
| 71 |
'workflowHelper' => new WorkflowHelper(), |
| 72 |
]; |
| 73 |
$this->getAllParamsRequest($data); |
| 74 |
$this->prepareMailboxesListing($data); |
| 75 |
$this->prepareMailboxesActions($data); |
| 76 |
$this->prepareToolbar($data, 'mailboxes'); |
| 77 |
|
| 78 |
parent::display($data); |
| 79 |
} |
| 80 |
|
| 81 |
private function mailboxDoListingAction($action) |
| 82 |
{ |
| 83 |
$mailboxClass = new MailboxClass(); |
| 84 |
if (!method_exists($mailboxClass, $action)) { |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
$mailboxActionSelected = acym_getVar('int', 'elements_checked'); |
| 89 |
|
| 90 |
if (empty($mailboxActionSelected)) { |
| 91 |
return; |
| 92 |
} |
| 93 |
|
| 94 |
$mailboxClass->$action($mailboxActionSelected); |
| 95 |
|
| 96 |
$this->mailboxes(); |
| 97 |
} |
| 98 |
|
| 99 |
public function duplicateMailboxAction() |
| 100 |
{ |
| 101 |
$this->mailboxDoListingAction('duplicate'); |
| 102 |
} |
| 103 |
|
| 104 |
public function deleteMailboxAction() |
| 105 |
{ |
| 106 |
$this->mailboxDoListingAction('delete'); |
| 107 |
} |
| 108 |
} |
| 109 |
|