Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 4051a72

Browse files
BaranekDvyskocilpavel
authored andcommitted
Added page with list of all Sps (#35)
Added configurable page with table of all Sps.
1 parent 5e9dfea commit 4051a72

File tree

9 files changed

+248
-1
lines changed

9 files changed

+248
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
[Added]
66
- Added badges to README
77
- Added new property to Facility model: description
8+
- Added page with configurable table of SPs on Proxy
89

910
[Changed]
1011
- Connectors methods are not static for now.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$config = array(
4+
'proxyIdentifier' => '',
5+
'perunProxyIdentifierAttr' => '',
6+
'attributesDefinitions' => array(
7+
'perunAttrName'
8+
),
9+
);

dictionaries/perun.definition.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,9 @@
6262
"go_back": {
6363
"en": "Go back to ",
6464
"cs": "Vraťte se zpět na "
65+
},
66+
"listOfSps_header": {
67+
"en": "List of Service providers",
68+
"cs": "Seznam služeb"
6569
}
6670
}

lib/Adapter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ public abstract function getFacilitiesByEntityId($spEntityId);
112112
*/
113113
public abstract function getUsersGroupsOnFacility($spEntityId, $userId);
114114

115+
/**
116+
* @param <String, String> map $attribute
117+
* @return array of sspmod_perun_model_Facility
118+
*/
119+
public abstract function searchFacilitiesByAttributeValue($attribute);
120+
121+
/**
122+
* @param sspmod_perun_model_Facility $facility
123+
* @param $attrNames array string $attrNames
124+
* @return array of attributes
125+
*/
126+
public abstract function getFacilityAttributes($facility, $attrNames);
115127

116128
/**
117129
* @param sspmod_perun_model_HasId[] $entities

lib/AdapterLdap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public function getFacilityAttribute($facility, $attrName)
187187
// TODO: Implement getFacilityAttribute() method.
188188
}
189189

190+
public function searchFacilitiesByAttributeValue($attribute)
191+
{
192+
throw new BadMethodCallException("NotImplementedException");
193+
// TODO: Implement searchFacilitiesByAttributeValue() method.
194+
}
195+
196+
public function getFacilityAttributes($facility, $attrNames)
197+
{
198+
throw new BadMethodCallException("NotImplementedException");
199+
// TODO: Implement getFacilityAttributes() method.
200+
}
190201

191202
public function getUsersGroupsOnFacility($spEntityId, $userId)
192203
{

lib/AdapterRpc.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct ($configFileName = null)
3434

3535
$this->connector = new sspmod_perun_RpcConnector($this->rpcUrl, $this->rpcUser, $this->rpcPassword);
3636
}
37-
37+
3838
public function getPerunUser($idpEntityId, $uids)
3939
{
4040
$user = null;
@@ -276,4 +276,34 @@ public function getFacilitiesByEntityId($spEntityId)
276276
}
277277
return $facilities;
278278
}
279+
280+
public function searchFacilitiesByAttributeValue($attribute)
281+
{
282+
$perunAttrs = $this->connector->post('searcher', 'getFacilities', array(
283+
'attributesWithSearchingValues' => $attribute,
284+
));
285+
$facilities = array();
286+
foreach($perunAttrs as $perunAttr) {
287+
array_push($facilities, new sspmod_perun_model_Facility($perunAttr['id'], $perunAttr['name'], $perunAttr['description'],null));
288+
}
289+
return $facilities;
290+
}
291+
292+
public function getFacilityAttributes($facility, $attrNames) {
293+
$perunAttrs = $this->connector->get('attributesManager', 'getAttributes', array(
294+
'facility' => $facility->getId(),
295+
'attrNames' => $attrNames,
296+
));
297+
$attributes = array();
298+
foreach($perunAttrs as $perunAttr) {
299+
array_push($attributes, array(
300+
'id' => $perunAttr['id'],
301+
'name' => $perunAttr['namespace'] . ':' . $perunAttr['friendlyName'],
302+
'displayName' => $perunAttr['displayName'],
303+
'type' => $perunAttr['type'],
304+
'value' => $perunAttr['value']
305+
));
306+
}
307+
return $attributes;
308+
}
279309
}

templates/listOfSps-tpl.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
}

www/listOfSps.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
const CONFIG_FILE_NAME = 'module_perun_listOfSps.php';
4+
const PROXY_IDENTIFIER = 'proxyIdentifier';
5+
const ATTRIBUTES_DEFINITIONS = 'attributesDefinitions';
6+
const PERUN_PROXY_IDENTIFIER_ATTR_NAME = 'perunProxyIdentifierAttr';
7+
8+
$config = SimpleSAML_Configuration::getInstance();
9+
$conf = SimpleSAML_Configuration::getConfig(CONFIG_FILE_NAME);
10+
11+
$proxyIdentifier = $conf->getString(PROXY_IDENTIFIER);
12+
assert(is_null($proxyIdentifier) || empty($proxyIdentifier));
13+
$attributesDefinitions = $conf->getArray(ATTRIBUTES_DEFINITIONS);
14+
$perunProxyIdentifierAttr = $conf->getString(PERUN_PROXY_IDENTIFIER_ATTR_NAME);
15+
assert(is_null($attributesDefinitions) || is_array($attributesDefinitions));
16+
17+
$rpcAdapter = new sspmod_perun_AdapterRpc();
18+
$attributeDefinition = array();
19+
$attributeDefinition[$perunProxyIdentifierAttr] = $proxyIdentifier;
20+
$facilities = $rpcAdapter->searchFacilitiesByAttributeValue($attributeDefinition);
21+
22+
$attrNames = array();
23+
foreach ($attributesDefinitions as $attributeDefinition) {
24+
array_push($attrNames, $attributeDefinition);
25+
}
26+
27+
$facilitiesWithAttributes = array();
28+
foreach ($facilities as $facility) {
29+
$attributes = $rpcAdapter->getFacilityAttributes($facility, $attrNames);
30+
$facilityAttributes = array();
31+
foreach ($attributes as $attribute) {
32+
$facilityAttributes[$attribute['name']] = $attribute;
33+
}
34+
$facilitiesWithAttributes[$facility->getId()] = array(
35+
'facility' => $facility,
36+
'facilityAttributes' => $facilityAttributes
37+
);
38+
}
39+
40+
$t = new SimpleSAML_XHTML_Template($config, 'perun:listOfSps-tpl.php');
41+
$t->data['attrNames'] = $attrNames;
42+
$t->data['facilitiesWithAttributes'] = $facilitiesWithAttributes;
43+
$t->show();

www/res/css/listOfSps.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#content {
2+
max-width: 75%;
3+
}
4+
5+
#listOfSps{
6+
margin: 0 auto;
7+
padding: 10px;
8+
}
9+
10+
#stringFilter {
11+
padding-bottom: 20px;
12+
}

0 commit comments

Comments
 (0)