| @@ -1,151 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Helpers; | |
| 4 | - | |
| 5 | -use AcyMailing\Classes\MailClass; | |
| 6 | -use AcyMailing\Core\AcymObject; | |
| 7 | - | |
| 8 | -class WorkflowHelper extends AcymObject | |
| 9 | -{ | |
| 10 | - // Disable all the steps after this one | |
| 11 | - public string $disabledAfter = ''; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * Call this helper in an element with the class acym__content | |
| 15 | - * The steps are defined in the Main view class | |
| 16 | - * Put acym_formOptions(true, 'edit', 'CURRENT STEP') at the end of each step | |
| 17 | - */ | |
| 18 | - public function display( | |
| 19 | - array $steps, | |
| 20 | - string $currentStep, | |
| 21 | - bool $editionMode = true, | |
| 22 | - bool $needTabs = false, | |
| 23 | - string $linkParameters = '', | |
| 24 | - string $idName = 'id' | |
| 25 | - ): void { | |
| 26 | - $ctrl = acym_getVar('cmd', 'ctrl'); | |
| 27 | - $id = acym_getVar('int', $idName, 0); | |
| 28 | - | |
| 29 | - echo '<ul id="workflow">'; | |
| 30 | - | |
| 31 | - $disableTabs = false; | |
| 32 | - $step = 0; | |
| 33 | - foreach ($steps as $task => $title) { | |
| 34 | - $class = 'step'; | |
| 35 | - if ($disableTabs) { | |
| 36 | - $class .= ' disabled_step'; | |
| 37 | - } | |
| 38 | - if ($currentStep === $task) { | |
| 39 | - $class .= ' current_step'; | |
| 40 | - } | |
| 41 | - | |
| 42 | - if ($step !== 0) { | |
| 43 | - echo '<li class="step_separator '.esc_attr($needTabs ? '' : 'acymicon-keyboard-arrow-right').'"></li>'; | |
| 44 | - } | |
| 45 | - echo '<li class="'.esc_attr($class).'">'; | |
| 46 | - | |
| 47 | - if (!$disableTabs) { | |
| 48 | - $link = $editionMode ? $ctrl.'&task=edit&step='.$task.'&'.$idName.'='.$id : $ctrl.'&task='.$task; | |
| 49 | - echo '<a href="'.esc_url(acym_completeLink($link.$linkParameters)).'">'; | |
| 50 | - } | |
| 51 | - echo esc_html(acym_translation($title)); | |
| 52 | - if (!$disableTabs) { | |
| 53 | - echo '</a>'; | |
| 54 | - } | |
| 55 | - echo '</li>'; | |
| 56 | - | |
| 57 | - if ($task === $this->disabledAfter) { | |
| 58 | - $disableTabs = true; | |
| 59 | - } | |
| 60 | - | |
| 61 | - $step++; | |
| 62 | - } | |
| 63 | - | |
| 64 | - echo '</ul>'; | |
| 65 | - } | |
| 66 | - | |
| 67 | - public function displayNew(array $steps, string $currentStep, bool $edition = true, string $linkParameters = '', string $idName = 'id'): void | |
| 68 | - { | |
| 69 | - $ctrl = acym_getVar('cmd', 'ctrl'); | |
| 70 | - $id = acym_getVar('int', $idName, 0); | |
| 71 | - | |
| 72 | - echo '<div class="acym__workflow">'; | |
| 73 | - | |
| 74 | - $disableTabs = false; | |
| 75 | - foreach ($steps as $task => $title) { | |
| 76 | - if ($disableTabs) { | |
| 77 | - continue; | |
| 78 | - } | |
| 79 | - | |
| 80 | - $classCurrentStep = $currentStep === $task ? 'acym__workflow__step__active' : ''; | |
| 81 | - $classDisabled = $disableTabs ? 'acym__workflow__step__disabled' : ''; | |
| 82 | - | |
| 83 | - echo '<div class="acym__workflow__step '.esc_attr($classDisabled.' '.$classCurrentStep).'">'; | |
| 84 | - if (!$disableTabs) { | |
| 85 | - $link = $edition ? $ctrl.'&task=edit&step='.$task.'&'.$idName.'='.$id : $ctrl.'&task='.$task; | |
| 86 | - echo '<a href="'.esc_url(acym_completeLink($link.$linkParameters)).'">'; | |
| 87 | - } | |
| 88 | - echo esc_html(acym_translation($title)); | |
| 89 | - if (!$disableTabs) { | |
| 90 | - echo '</a>'; | |
| 91 | - } | |
| 92 | - echo '</div>'; | |
| 93 | - | |
| 94 | - if ($task === $this->disabledAfter) { | |
| 95 | - $disableTabs = true; | |
| 96 | - } | |
| 97 | - } | |
| 98 | - | |
| 99 | - echo '</div>'; | |
| 100 | - } | |
| 101 | - | |
| 102 | - public function displayTabs(array $steps, string $currentStep, array $options = []): void | |
| 103 | - { | |
| 104 | - $ctrl = acym_getVar('cmd', 'ctrl'); | |
| 105 | - | |
| 106 | - echo '<ul class="tabs" id="workflow">'; | |
| 107 | - | |
| 108 | - $mailClass = new MailClass(); | |
| 109 | - $mailTypes = ['mailbox_action']; | |
| 110 | - | |
| 111 | - foreach ($steps as $task => $title) { | |
| 112 | - if (in_array($task, $mailTypes)) { | |
| 113 | - $searchSettings = [ | |
| 114 | - 'offset' => 0, | |
| 115 | - 'mailsPerPage' => 1, | |
| 116 | - 'key' => '', | |
| 117 | - ]; | |
| 118 | - $existingMailbox = $mailClass->getMailsByType($task, $searchSettings); | |
| 119 | - | |
| 120 | - if (empty($existingMailbox['mails'])) { | |
| 121 | - continue; | |
| 122 | - } | |
| 123 | - } | |
| 124 | - | |
| 125 | - if (!empty($options['query'])) { | |
| 126 | - $link = $ctrl.$options['query'].$task; | |
| 127 | - } else { | |
| 128 | - $link = $ctrl.'&task='.$task; | |
| 129 | - } | |
| 130 | - | |
| 131 | - if (!empty($options['disableTabs']) && in_array($task, $options['disableTabs'])) { | |
| 132 | - $link = ''; | |
| 133 | - } | |
| 134 | - | |
| 135 | - echo '<li class="tabs-title"><a class="acym_tab acym__color__medium-gray"'; | |
| 136 | - if (!empty($link)) { | |
| 137 | - echo ' href="'.esc_url(acym_completeLink($link)).'"'; | |
| 138 | - if ($currentStep === $task) { | |
| 139 | - echo ' aria-selected="true"'; | |
| 140 | - } | |
| 141 | - } else { | |
| 142 | - echo ' aria-disabled="true"'; | |
| 143 | - } | |
| 144 | - echo '>'; | |
| 145 | - echo esc_html(acym_translation($title)); | |
| 146 | - echo '</a></li>'; | |
| 147 | - } | |
| 148 | - | |
| 149 | - echo '</ul>'; | |
| 150 | - } | |
| 151 | -} | |