|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace WpTracy; |
| 4 | + |
| 5 | +use Tracy, |
| 6 | + Tracy\IBarPanel, |
| 7 | + Tracy\Dumper; |
| 8 | + |
| 9 | +/** |
| 10 | + * Common basic model for other WP panels |
| 11 | + * |
| 12 | + * @author Martin Hlaváč |
| 13 | + * @link http://www.ktstudio.cz/ |
| 14 | + */ |
| 15 | +abstract class WpPanelBase implements IBarPanel { |
| 16 | + |
| 17 | + /** |
| 18 | + * (HTML) content of tab for panel |
| 19 | + * |
| 20 | + * @author Martin Hlaváč |
| 21 | + * @link http://www.ktstudio.cz/ |
| 22 | + * |
| 23 | + * @param string $title |
| 24 | + * @param string $description |
| 25 | + * @param string $imageBase64 |
| 26 | + * @return string |
| 27 | + */ |
| 28 | + public function getSimpleTab($title = null, $description = null, $imageBase64 = null) { |
| 29 | + $output = "<span" . (self::issetAndNotEmpty($description) ? " title=\"$description\"" : "") . ">"; |
| 30 | + if (self::issetAndNotEmpty($imageBase64)) { |
| 31 | + $output .= "<img src=\"data:image/png;base64,$imageBase64\" /> "; |
| 32 | + } |
| 33 | + if (self::issetAndNotEmpty($title)) { |
| 34 | + $output .= $title; |
| 35 | + } |
| 36 | + $output .= "</span>"; |
| 37 | + return $output; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * (HTML) table content of panel based on parameters array |
| 42 | + * |
| 43 | + * @author Martin Hlaváč |
| 44 | + * @link http://www.ktstudio.cz/ |
| 45 | + * |
| 46 | + * @param array $params |
| 47 | + * @param string $title |
| 48 | + * @return string |
| 49 | + */ |
| 50 | + public function getTablePanel(array $params, $title = null) { |
| 51 | + $output = null; |
| 52 | + if (self::issetAndNotEmpty($title)) { |
| 53 | + $output .= "<h1>$title</h1>"; |
| 54 | + } |
| 55 | + $output .= "<div class=\"nette-inner\">"; |
| 56 | + $output .= "<table>"; |
| 57 | + $output .= "<thead>"; |
| 58 | + $output .= "<tr>"; |
| 59 | + $output .= "<th>" . __("Parameter") . "</th>"; |
| 60 | + $output .= "<th>" . __("Value") . "</th>"; |
| 61 | + $output .= "</tr>"; |
| 62 | + $output .= "</thead>"; |
| 63 | + foreach ($params as $key => $value) { |
| 64 | + $output .= "<tr>"; |
| 65 | + $output .= "<td>$key:</td>"; |
| 66 | + $output .= "<td>$value</td>"; |
| 67 | + $output .= "</tr>"; |
| 68 | + } |
| 69 | + $output .= "</table>"; |
| 70 | + $output .= "</div>"; |
| 71 | + return $output; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * (HTML) content of panel based on object |
| 76 | + * |
| 77 | + * @author Martin Hlaváč |
| 78 | + * @link http://www.ktstudio.cz/ |
| 79 | + * |
| 80 | + * @param mixed $object |
| 81 | + * @param string $title |
| 82 | + * @return string |
| 83 | + */ |
| 84 | + public function getObjectPanel($object, $title = null) { |
| 85 | + $output = null; |
| 86 | + if (self::issetAndNotEmpty($title)) { |
| 87 | + $output .= "<h1>$title</h1>"; |
| 88 | + } |
| 89 | + $output .= "<div class=\"nette-inner\">"; |
| 90 | + $output .= Dumper::toHtml($object, array(Dumper::COLLAPSE => false)); |
| 91 | + $output .= "</div>"; |
| 92 | + return $output; |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Check if the value is assigned and if it's not empty |
| 97 | + * |
| 98 | + * @author Martin Hlaváč |
| 99 | + * @link http://www.ktstudio.cz/ |
| 100 | + * |
| 101 | + * @param mixed $value |
| 102 | + * @return boolean |
| 103 | + */ |
| 104 | + public static function issetAndNotEmpty($value) { |
| 105 | + return isset($value) && !empty($value); |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments