| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Helpers; |
| 4 |
|
| 5 |
use AcyMailing\Core\AcymObject; |
| 6 |
|
| 7 |
class ToolbarHelper extends AcymObject |
| 8 |
{ |
| 9 |
private array $searchBarInformation = []; |
| 10 |
private array $actionButtons = []; |
| 11 |
private array $filteringOptions = []; |
| 12 |
|
| 13 |
public function addSearchBar(string $search, string $name, string $placeholder = 'ACYM_SEARCH', bool $showClearBtn = true): void |
| 14 |
{ |
| 15 |
$this->searchBarInformation = [ |
| 16 |
'search' => $search, |
| 17 |
'name' => $name, |
| 18 |
'placeholder' => $placeholder, |
| 19 |
'showClearBtn' => $showClearBtn, |
| 20 |
]; |
| 21 |
} |
| 22 |
|
| 23 |
public function addButton(string $textContent, array $attributes, string $icon = '', bool $isPrimary = false): void |
| 24 |
{ |
| 25 |
$this->actionButtons[] = [ |
| 26 |
'type' => 'button', |
| 27 |
'icon' => $icon, |
| 28 |
'content' => acym_translation($textContent), |
| 29 |
'attributes' => $attributes, |
| 30 |
'isPrimary' => $isPrimary, |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
public function addModalButton(array $options): void |
| 35 |
{ |
| 36 |
$options['type'] = 'modal'; |
| 37 |
$this->actionButtons[] = $options; |
| 38 |
} |
| 39 |
|
| 40 |
public function addFilterByTag(array &$data, string $name, string $class): void |
| 41 |
{ |
| 42 |
$allTags = new \stdClass(); |
| 43 |
$allTags->name = acym_translation('ACYM_ALL_TAGS'); |
| 44 |
$allTags->value = ''; |
| 45 |
array_unshift($data['allTags'], $allTags); |
| 46 |
$this->addOptionSelect( |
| 47 |
acym_translation('ACYM_TAG'), |
| 48 |
acym_select( |
| 49 |
$data['allTags'], |
| 50 |
$name, |
| 51 |
$data['tag'], |
| 52 |
[ |
| 53 |
'class' => $class, |
| 54 |
], |
| 55 |
'value', |
| 56 |
'name' |
| 57 |
) |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
public function addOptionSelect(string $title, string $select): void |
| 62 |
{ |
| 63 |
$this->filteringOptions[] = [ |
| 64 |
'title' => $title, |
| 65 |
'select' => $select, |
| 66 |
]; |
| 67 |
} |
| 68 |
|
| 69 |
public function displayToolbar(array $data): void |
| 70 |
{ |
| 71 |
$data['toolbarHelper'] = $this; |
| 72 |
$data['searchBarInformation'] = $this->searchBarInformation; |
| 73 |
$data['actionButtons'] = $this->actionButtons; |
| 74 |
$data['filteringOptions'] = $this->filteringOptions; |
| 75 |
include acym_getPartial('toolbar', 'toolbar'); |
| 76 |
} |
| 77 |
|
| 78 |
public function displaySearchBar(): void |
| 79 |
{ |
| 80 |
acym_filterSearch( |
| 81 |
$this->searchBarInformation['search'], |
| 82 |
$this->searchBarInformation['name'], |
| 83 |
$this->searchBarInformation['placeholder'], |
| 84 |
$this->searchBarInformation['showClearBtn'], |
| 85 |
'acym__toolbar__search-field margin-bottom-0' |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
public function displayActionButtons(): void |
| 90 |
{ |
| 91 |
foreach ($this->actionButtons as $data) { |
| 92 |
if ($data['type'] === 'button') { |
| 93 |
include acym_getPartial('toolbar', 'button_main'); |
| 94 |
} else { |
| 95 |
acym_modal( |
| 96 |
$data['button'], |
| 97 |
$data['modalContent'] ?? '', |
| 98 |
$data['id'] ?? null, |
| 99 |
$data['attributesModal'] ?? [], |
| 100 |
$data['attributesButton'] ?? [], |
| 101 |
$data['isButton'] ?? true, |
| 102 |
$data['isLarge'] ?? true, |
| 103 |
$data['classesModal'] ?? '', |
| 104 |
); |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|