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