PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Helpers / WorkflowHelper.php

WorkflowHelper.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.11.1, at back/Helpers/WorkflowHelper.php

143 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Helpers;
4
5 use AcyMailing\Core\AcymObject;
6
7 class WorkflowHelper extends AcymObject
8 {
9 public string $disabledAfter = '';
10
11 public function display(array $steps, string $currentStep, bool $editionMode = true, bool $needTabs = false, string $linkParameters = '', string $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 ($editionMode) {
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(array $steps, string $currentStep, array $options = []): string
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 }
143