Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_Feedback | |
0.00% |
0 / 25 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
| dispatch | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
| error | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| info | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| success | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| warning | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Utility to display error messages and such |
| 24 | * |
| 25 | * @author Dieter Raber, <dieter@taotesting.com> |
| 26 | * @package tao |
| 27 | |
| 28 | */ |
| 29 | class tao_helpers_Feedback |
| 30 | { |
| 31 | /** |
| 32 | * @param $type |
| 33 | * @param $message |
| 34 | * @param array $settings |
| 35 | * @return string |
| 36 | */ |
| 37 | protected static function dispatch($type, $message, $settings = []) |
| 38 | { |
| 39 | $defaults = [ |
| 40 | 'delayToClose' => 2000, |
| 41 | 'closer' => true, |
| 42 | 'icon' => true, |
| 43 | 'modal' => false |
| 44 | ]; |
| 45 | $settings = array_merge($defaults, $settings); |
| 46 | $closer = $settings['closer'] |
| 47 | ? sprintf('<span class="icon-close close-trigger" title="%s"></span>', __('Remove Message')) |
| 48 | : ''; |
| 49 | if (is_string($settings['icon'])) { |
| 50 | $icon = sprintf('<span class="%s"></span>', $settings['icon']); |
| 51 | } elseif ($settings['icon'] === true) { |
| 52 | $icon = sprintf('<span class="icon-%s"></span>', $type); |
| 53 | } else { |
| 54 | $icon = ''; |
| 55 | } |
| 56 | return sprintf('<div class="feedback-%s">%s%s%s</div>', $type, $icon, $message, $closer); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @param $message |
| 61 | * @param array $settings |
| 62 | * @return string |
| 63 | */ |
| 64 | public static function error($message, $settings = []) |
| 65 | { |
| 66 | return self::dispatch(__FUNCTION__, $message, $settings); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @param $message |
| 71 | * @param array $settings |
| 72 | * @return string |
| 73 | */ |
| 74 | public static function info($message, $settings = []) |
| 75 | { |
| 76 | return self::dispatch(__FUNCTION__, $message, $settings); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @param $message |
| 81 | * @param array $settings |
| 82 | * @return string |
| 83 | */ |
| 84 | public static function success($message, $settings = []) |
| 85 | { |
| 86 | return self::dispatch(__FUNCTION__, $message, $settings); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param $message |
| 91 | * @param array $settings |
| 92 | * @return string |
| 93 | */ |
| 94 | public static function warning($message, $settings = []) |
| 95 | { |
| 96 | return self::dispatch(__FUNCTION__, $message, $settings); |
| 97 | } |
| 98 | } |