Stepnav.php
Go to the documentation of this file.
1<?php
10
18{
22 private $htmlString;
23
31 public function __construct($parameters, $form)
32 {
33 $this->form = $form;
34 }
35
41 public function __toString()
42 {
43 $scheme = isset($this->form->url['scheme']) ? $this->form->url['scheme'] . '://' : '';
44 $host = isset($this->form->url['host']) ? $this->form->url['host'] : '';
45 $port = isset($this->form->url['port']) ? ':' . $this->form->url['port'] : '';
46 $path = isset($this->form->url['path']) ? $this->form->url['path'] : '';
47 $baseUrl = "$scheme$host$port$path";
48
49
50 $currentStepId = $this->form->getCurrentStepId();
51 $firstInvalidStep = $this->form->getFirstInvalidStep();
52
53 $htmlString = "<ol class=\"stepnav\">";
54 foreach ($this->form->getSteps() as $stepNum => $step) {
55 $link = "";
56 $class = "step-$stepNum";
57 $label = $step->htmlLabel();
58
59 // add link to previously unsaved steps
60 if ($stepNum <= $firstInvalidStep && $stepNum != $currentStepId) {
61 $link = "href=\"" . htmlspecialchars($baseUrl . $this->form->buildUrlQuery(array('step' => $stepNum))) . "\"";
62 }
63
64 // add valid-class to previous steps
65 if ($stepNum < $currentStepId) {
66 $class .= $step->validate() ? " valid" : " invalid";
67 }
68
69 if ($stepNum == $currentStepId) {
70 $htmlString .= "<li class=\"current-step $class\"><a $link><strong>$label</strong></a></li>";
71 } else {
72 $htmlString .= "<li class=\"$class\"><a $link>$label</a></li>";
73 }
74 }
75 $htmlString .= "</ol>";
76
77 return $htmlString;
78 }
79}
80
81/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Can be used to insert a step navigation.
Definition Stepnav.php:18
__construct($parameters, $form)
stepnav class constructor
Definition Stepnav.php:31
__toString()
Renders element to HTML.
Definition Stepnav.php:41
Classes for HTML input-elements.
Definition Address.php:9