TYPO3 CMS  TYPO3_8-7
AbstractStepAction.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
22 abstract class AbstractStepAction extends AbstractAction implements StepInterface
23 {
27  protected $currentStep = 0;
28 
32  protected $totalSteps = 0;
33 
40  public function setStepsCounter($current, $total)
41  {
42  $this->currentStep = $current;
43  $this->totalSteps = $total;
44  }
45 
51  public function getCurrentStep()
52  {
53  return $this->currentStep;
54  }
55 
61  public function getTotalSteps()
62  {
63  return $this->totalSteps;
64  }
65 
69  protected function assignSteps()
70  {
71  $steps = [];
72  $currentStep = $this->getCurrentStep();
73  $totalSteps = $this->getTotalSteps();
74  for ($i = 1; $i <= $totalSteps; $i++) {
75  $class = '';
76  if ($i == $currentStep) {
77  $class = 'cur';
78  } elseif ($i < $currentStep) {
79  $class = 'prev';
80  }
81  $steps[] = [
82  'number' => $i,
83  'class' => $class,
84  'total' => $totalSteps,
85  'percent' => floor((100 * $i) / $totalSteps)
86  ];
87  }
88  $this->view->assign('steps', $steps);
89  $this->view->assign('currentStep', $steps[$currentStep-1]);
90  }
91 }