Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
19 / 19 |
| AlertBox | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
19 / 19 |
| alertBox | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| getClass | |
100.00% |
1 / 1 |
3 | |
100.00% |
5 / 5 |
|||
| renderMessage | |
100.00% |
1 / 1 |
4 | |
100.00% |
11 / 11 |
|||
| <?php | |
| namespace Bone\View\Helper; | |
| class AlertBox | |
| { | |
| /** | |
| * @param array $message array of messages, last item in array should be alert class | |
| * @return bool|string | |
| */ | |
| public function alertBox(array $message) | |
| { | |
| $class = $this->getClass($message); | |
| $alert = '<div class="alert ' . $class . '"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' . $this->renderMessage($message) . '</div>'; | |
| return $alert; | |
| } | |
| /** | |
| * @param array $message | |
| * @return string | |
| */ | |
| private function getClass(array $message) | |
| { | |
| if (count($message) < 2) { | |
| return 'alert-info'; | |
| } | |
| $class = array_pop($message); | |
| $class = (!strstr($class, 'alert-')) ? 'alert-' . $class : ''; | |
| return $class; | |
| } | |
| /** | |
| * @param array $message | |
| * @return string | |
| */ | |
| private function renderMessage(array $message) | |
| { | |
| $alert = ''; | |
| if (count($message) > 1) { | |
| array_pop($message); | |
| } | |
| $num = count($message); | |
| $x = 1; | |
| foreach ($message as $msg) { | |
| $alert .= $msg; | |
| if ($x < $num) { | |
| $alert .= '<br />'; | |
| } | |
| $x++; | |
| } | |
| return $alert; | |
| } | |
| } |