-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsection-related-datasets.php
123 lines (115 loc) · 3.66 KB
/
section-related-datasets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
$datasets = opendev_get_related_datasets();
$groupby = 'groups';
if(!empty($datasets)) {
$grouped = array();
foreach($datasets as $dataset) {
if(!empty($dataset[$groupby])) {
foreach($dataset[$groupby] as $group) {
if(!$grouped[$group['id']]) {
$grouped[$group['id']] = $group;
$grouped[$group['id']]['datasets'] = array();
}
$grouped[$group['id']]['datasets'][] = $dataset;
}
} else {
if(!$grouped['_other'])
$grouped['_other'] = array(
'display_name' => __('Other', 'opendev'),
'datasets' => array()
);
$grouped['_other']['datasets'][] = $dataset;
}
}
}
?>
<?php if(isset($grouped) && !empty($grouped)) : ?>
<section id="related-datasets" class="row">
<div class="container">
<div class="box-section twelve columns">
<div class="box-title">
<h2><?php _e('Related resources', 'opendev'); ?></h2>
</div>
<div class="box-items">
<?php
foreach($grouped as $group) :
if(!empty($group['datasets'])) :
?>
<div class="group-item box-item">
<?php if(count($grouped) > 1) : ?>
<h3><?php echo isset($group['title']) ? $group['title'] : $group['display_name']; ?></h3>
<?php endif; ?>
<ul class="dataset-list">
<?php foreach($group['datasets'] as $dataset) : ?>
<li class="dataset-item">
<h4>
<a href="<?php echo $dataset['']; ?>"><?php echo $dataset['title']; ?></a>
</h4>
<?php if(isset($dataset['description'])) : ?>
<p class="dataset-description"><?php echo $dataset['description']; ?></p>
<?php elseif(isset($dataset['notes'])) : ?>
<p class="dataset-description"><?php echo $dataset['notes']; ?></p>
<?php endif; ?>
<ul class="dataset-resources clearfix">
<?php
$i = 0;
foreach($dataset['resources'] as $resource) :
if($i > 3)
continue;
$i++;
?>
<li class="resource-item">
<a href="<?php echo $resource['url']; ?>" target="_blank" rel="external">
<?php echo $resource['description']; ?>
<?php if($resource['format']) : ?>
<span class="format"><?php echo $resource['format']; ?></span>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<p class="read-more"><a href="<?php echo $dataset['']; ?>"><?php _e('Read more...', 'opendev'); ?></a></p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
endif;
endforeach;
?>
</div>
<a class="toggle-resources"><?php _e('Show resources details', 'opendev'); ?></a>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#related-datasets').addClass('collapsed');
$('.dataset-resources').hide();
var viewingAll = false;
$('.toggle-resources').on('click', function() {
toggle();
if(viewingAll) {
$(this).text('<?php _e("Hide resources details", "opendev"); ?>');
} else {
$(this).text('<?php _e("Show resources details", "opendev"); ?>');
}
});
function toggle(node) {
node = node || false;
if(!node) {
if(viewingAll) {
$('.dataset-resources').hide();
$('#related-datasets').addClass('collapsed');
viewingAll = false;
} else {
$('.dataset-resources').show();
$('#related-datasets').removeClass('collapsed');
viewingAll = true;
}
} else {
}
}
});
</script>
</div>
</div>
</section>
<?php endif; ?>