|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This is a simple example of template with table of SPs |
| 4 | + * |
| 5 | + * @author Dominik Baránek <[email protected]> |
| 6 | + */ |
| 7 | + |
| 8 | +$this->data['header'] = ''; |
| 9 | +$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' . SimpleSAML\Module::getModuleUrl('perun/res/css/listOfSps.css') . '" />'; |
| 10 | + |
| 11 | +$this->includeAtTemplateBase('includes/header.php'); |
| 12 | + |
| 13 | +$attrNames = $this->data['attrNames']; |
| 14 | +$facilitiesWithAttributes = $this->data['facilitiesWithAttributes']; |
| 15 | + |
| 16 | +$columns = '['; |
| 17 | +$columns .= '{label: "Id", type: "number"},'; |
| 18 | +$columns .= '{label: "Name", type: "string"},'; |
| 19 | +$columns .= '{label: "Description", type: "string"},'; |
| 20 | +if (!empty($attrNames)) { |
| 21 | + $facilityAttributes = array_values($facilitiesWithAttributes)[0]['facilityAttributes']; |
| 22 | + foreach ($attrNames as $attrName) { |
| 23 | + if (typeIsSupported($facilityAttributes[$attrName]['type'])) { |
| 24 | + $columns .= '{label: "' . $facilityAttributes[$attrName]['displayName'] . '", type: "'; |
| 25 | + if (strpos($facilityAttributes[$attrName]['type'], 'Integer')) { |
| 26 | + $columns .= 'number'; |
| 27 | + } else if (strpos($facilityAttributes[$attrName]['type'], 'Boolean')) { |
| 28 | + $columns .= 'boolean'; |
| 29 | + } else if (strpos($facilityAttributes[$attrName]['type'], 'String') || strpos($facilityAttributes[$attrName]['type'], 'Array')) { |
| 30 | + $columns .= 'string'; |
| 31 | + } |
| 32 | + $columns .= '"},'; |
| 33 | + } |
| 34 | + } |
| 35 | + $columns = substr($columns, 0, -1) . ']'; |
| 36 | +} else { |
| 37 | + $columns .= ']'; |
| 38 | +} |
| 39 | + |
| 40 | +$rows = '['; |
| 41 | +foreach ($facilitiesWithAttributes as $facilityWithAttributes) { |
| 42 | + $rows .= '{c:['; |
| 43 | + $rows .= '{v: "' . $facilityWithAttributes['facility']->getId() . '"}, '; |
| 44 | + $rows .= '{v: "' . $facilityWithAttributes['facility']->getName() . '"}, '; |
| 45 | + $rows .= '{v: "' . $facilityWithAttributes['facility']->getDescription() . '"}, '; |
| 46 | + foreach ($attrNames as $attrName) { |
| 47 | + if (typeIsSupported($facilityWithAttributes['facilityAttributes'][$attrName]['type'])) { |
| 48 | + if ((strpos($facilityWithAttributes['facilityAttributes'][$attrName]['type'], 'Array'))) { |
| 49 | + $rows .= '{v: "'; |
| 50 | + foreach ($facilityWithAttributes['facilityAttributes'][$attrName]['value'] as $value) { |
| 51 | + $rows .= $value . '; '; |
| 52 | + } |
| 53 | + if (!empty($facilityWithAttributes['facilityAttributes'][$attrName]['value'])) { |
| 54 | + $rows = substr($rows, 0, -2) . '"}, '; |
| 55 | + } else { |
| 56 | + $rows .= '"}, '; |
| 57 | + } |
| 58 | + } else { |
| 59 | + $rows .= '{v: "' . $facilityWithAttributes['facilityAttributes'][$attrName]['value'] . '"}, '; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + $rows = substr($rows, 0, -2) . ']},'; |
| 64 | +} |
| 65 | +if (!empty($facilitiesWithAttributes)) { |
| 66 | + $rows = substr($rows, 0, -1) . ']'; |
| 67 | +} else { |
| 68 | + $rows .= ']'; |
| 69 | +} |
| 70 | + |
| 71 | +?> |
| 72 | + <html> |
| 73 | + <head> |
| 74 | + <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> |
| 75 | + <script type="text/javascript"> |
| 76 | + google.charts.load('current', {'packages':['corechart', 'controls']}); |
| 77 | + google.charts.setOnLoadCallback(drawDashboard); |
| 78 | + |
| 79 | + function drawDashboard() { |
| 80 | + |
| 81 | + var dashboard = new google.visualization.Dashboard( |
| 82 | + document.getElementById('dashboard_div')); |
| 83 | + |
| 84 | + var control = new google.visualization.ControlWrapper({ |
| 85 | + 'controlType': 'StringFilter', |
| 86 | + 'containerId': 'stringFilter', |
| 87 | + 'options': { |
| 88 | + 'matchType': 'any', |
| 89 | + 'filterColumnLabel': 'Name', |
| 90 | + } |
| 91 | + }); |
| 92 | + |
| 93 | + var chart = new google.visualization.ChartWrapper({ |
| 94 | + 'chartType': 'Table', |
| 95 | + 'containerId': 'table', |
| 96 | + }); |
| 97 | + |
| 98 | + var data = new google.visualization.DataTable({ |
| 99 | + cols: <?php echo $columns ?>, |
| 100 | + rows: <?php echo $rows ?> |
| 101 | + }); |
| 102 | + |
| 103 | + dashboard.bind(control, chart); |
| 104 | + dashboard.draw(data); |
| 105 | + } |
| 106 | + </script> |
| 107 | + </head> |
| 108 | + <body> |
| 109 | + <h2><?php echo $this->t('{perun:perun:listOfSps_header}'); ?></h2> |
| 110 | + <div id="listOfSps"> |
| 111 | + <div id="stringFilter"></div> |
| 112 | + <div id="table"></div> |
| 113 | + </div> |
| 114 | + </body> |
| 115 | + </html> |
| 116 | + |
| 117 | +<?php |
| 118 | +$this->includeAtTemplateBase('includes/footer.php'); |
| 119 | + |
| 120 | +function typeIsSupported($type) { |
| 121 | + return strpos($type, 'Integer') || |
| 122 | + strpos($type, 'Boolean') || |
| 123 | + strpos($type, 'String') || |
| 124 | + strpos($type, 'Array'); |
| 125 | +} |
0 commit comments