This repository was archived by the owner on Aug 3, 2024. It is now read-only.
forked from GetDKAN/dkan_dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdkan_dataset.theme.inc
170 lines (162 loc) · 5.29 KB
/
dkan_dataset.theme.inc
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* @file
* Theme functions for datasets.
*/
/**
* Implements hook_theme().
*/
function dkan_dataset_theme() {
$theme = array(
'dkan_dataset_resource_view' => array(
'variables' => array('node' => NULL),
),
'dkan_dataset_release_date_view' => array(
'variables' => array('node' => NULL),
),
'dkan_dataset_modified_date_view' => array(
'variables' => array('node' => NULL),
),
'dkan_dataset_identifier_view' => array(
'variables' => array('node' => NULL),
),
'dkan_dataset_resource_teaser_view' => array(
'variables' => array('node' => NULL),
),
);
return $theme;
}
/**
* Outputs the identifier content.
*/
function theme_dkan_dataset_identifier_view($vars) {
return '<div property="dcterms:identifier" class="field-name-field-identifier">' . $vars['node']->uuid . '</div>';
}
/**
* Outputs the modified date content.
*/
function theme_dkan_dataset_modified_date_view($vars) {
return '<div property="dcterms:modified" class="field-name-field-modified-date">' . date('Y-m-d', $vars['node']->changed) . '</div>';
}
/**
* Outputs the release date content.
*/
function theme_dkan_dataset_release_date_view($vars) {
return '<div property="dcterms:issued" class="field-name-field-release-date">' . date('Y-m-d', $vars['node']->created) . '</div>';
}
/**
* Output the resource into the node content.
*/
function theme_dkan_dataset_resource_view($vars) {
$output = '<h2>' . t('Data and Resources') . '</h2>';
$node = entity_metadata_wrapper('node', $vars['node']);
$nodes = $node->field_resources->value();
$links = array();
$output .= '<div property="dcat:distribution">';
if (isset($nodes)) {
foreach ($nodes as $node) {
// Node could be empty if it has been deleted.
if (!$node) {
continue;
}
$node_wrapper = entity_metadata_wrapper('node', $node);
$body = $node_wrapper->body->value();
$term = '';
if (isset($body['safe_value'])) {
$desc = '<p class="description">' . dkan_dataset_text_trim($body['safe_value'], 80) . '</p>';
}
else {
$desc = '<p class="description"></p>';
}
if (isset($node->field_format) && $node->field_format && $node_wrapper->field_format->value()) {
$term .= '<span class="format-label" property="dc:format" data-format="' . $node_wrapper->field_format->value()->name . '">' . $node_wrapper->field_format->value()->name . '</span>';
}
else {
$term = '<span class="format-label" property="dc:format" data-format="data">Data</span>';
}
$explore_link = l(
t('Explore Data'),
'node/' . $node->nid,
array(
'attributes' => array(
'class' => array(
'btn',
'btn-primary',
),
),
)
);
$download_link = '';
if (isset($node->field_upload[LANGUAGE_NONE])) {
$url = file_create_url($node->field_upload[LANGUAGE_NONE][0]['uri']);
$download_link = l(
'<i class="fa fa-download"></i>',
$url,
array(
'html' => TRUE,
'attributes' => array(
'class' => array('btn', 'btn-primary'),
),
)
);
}
$dcat = '<div property="dcat:Distribution">';
$links[] = $dcat . l($node->title . $term, 'node/' . $node->nid, array(
'html' => TRUE,
'attributes' => array(
'class' => array('heading'),
'title' => $node->title,
'property' => 'dcat:accessURL',
))
) . $desc . '<span class="links">' . $explore_link . $download_link . '</span></div>';
}
$output .= theme('item_list', array('items' => $links, 'attributes' => array('class' => array('resource-list'))));
// Close first dcat declaration.
$output .= '</div>';
}
return $output;
}
/**
* Output the resource into the node content.
*/
function theme_dkan_dataset_resource_teaser_view($vars) {
if ($vars['node']->type == 'dataset') {
$node = entity_metadata_wrapper('node', $vars['node']);
$nodes = $node->field_resources->value();
}
else {
$nodes = array($vars['node']);
}
$links = array();
if (isset($nodes)) {
// Data links for generate grouping resources link.
$links_data = array();
foreach ($nodes as $node) {
$node_wrapper = entity_metadata_wrapper('node', $node);
$name = isset($node->field_format['und']) ? $node_wrapper->field_format->value()->name : '';
$term = '';
if (!isset($links_data[$name])) {
$links_data[$name] = array(
'term_name' => $name,
'count' => 1,
'url' => 'node/' . $vars['node']->nid,
'link' => array(
'attributes' => array(
'class' => array('label'),
'title' => t('Resources') . ': ' . $vars['node']->title,
'data-format' => $name,
),
),
);
}
else {
$links_data[$name]['count'] = $links_data[$name]['count'] + 1;
}
}
foreach ($links_data as $term_name => $link) {
$links[] = '<span class="count-resource">' . $link['count'] . 'x</span>' . l($term_name, $link['url'], $link['link']);
}
$output = theme('item_list', array('items' => $links, 'attributes' => array('class' => array('resource-list'))));
}
return $output;
}