| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Controllers\Segments; |
| 4 |
|
| 5 |
use AcyMailing\Classes\SegmentClass; |
| 6 |
use AcyMailing\Helpers\PaginationHelper; |
| 7 |
use AcyMailing\Helpers\ToolbarHelper; |
| 8 |
|
| 9 |
trait Listing |
| 10 |
{ |
| 11 |
public function listing(): void |
| 12 |
{ |
| 13 |
if (!acym_level(ACYM_ENTERPRISE)) { |
| 14 |
acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true)); |
| 15 |
} |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
private function prepareToolbar(array &$data): void |
| 20 |
{ |
| 21 |
$toolbarHelper = new ToolbarHelper(); |
| 22 |
$toolbarHelper->addSearchBar($data['search'], 'segments_search'); |
| 23 |
$toolbarHelper->addButton(acym_translation('ACYM_CREATE'), ['data-task' => 'edit'], 'add', true); |
| 24 |
|
| 25 |
$data['toolbar'] = $toolbarHelper; |
| 26 |
} |
| 27 |
|
| 28 |
public function duplicate(): void |
| 29 |
{ |
| 30 |
$ids = acym_getVar('array', 'elements_checked', []); |
| 31 |
|
| 32 |
$segmentClass = new SegmentClass(); |
| 33 |
|
| 34 |
foreach ($ids as $id) { |
| 35 |
$segment = $segmentClass->getOneById($id); |
| 36 |
|
| 37 |
if (empty($segment)) { |
| 38 |
continue; |
| 39 |
} |
| 40 |
|
| 41 |
unset($segment->id); |
| 42 |
$segment->name .= ' - '.acym_translation('ACYM_COPY'); |
| 43 |
$segment->creation_date = acym_date('now', 'Y-m-d H:i:s'); |
| 44 |
$segment->filters = json_encode($segment->filters); |
| 45 |
|
| 46 |
$segmentClass->save($segment); |
| 47 |
} |
| 48 |
|
| 49 |
$this->listing(); |
| 50 |
} |
| 51 |
} |
| 52 |
|