/
idsapi.module
187 lines (156 loc) · 4.79 KB
/
idsapi.module
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
171
172
173
174
175
<?php
// $Id$
/**
* @file
* IDS API Module.
*
* This module uses the IDS Knowldege Services API (api.ids.ac.uk) in order
* to search, display and import data and metadata contained in the BRIDGE and ELDIS
* datasets, which are maintained by the IDS.
*/
/* --------------------- Hooks implementations -------------------- */
/**
* Include files that implement the request and objects classes
*/
require_once('idsapi.default.inc');
require_once(IDS_API_LIBRARY_PATH . 'idswrapper.default.inc');
/**
* Implements hook_flush_caches().
*/
function idsapi_flush_caches() {
return array(IDS_API_CACHE_REQUESTS);
}
/**
* Implements hook_enable().
*/
function idsapi_enable() {
drupal_flush_all_caches();
drupal_set_message(t('To use the IDS API module, first go to the <a href="@url">IDS API Administration</a> to set general parameters, including your IDS API key.', array('@url' => url('admin/config/services/idsapi'))));
}
/**
* Implements hook_disable().
*/
function idsapi_disable() {
drupal_flush_all_caches();
}
/**
* Implements of hook_menu().
*/
function idsapi_menu() {
$items = array();
$items['admin/config/services/idsapi'] = array(
'title' => t('IDS API Module settings'),
'description' => t('Global settings for the IDS API module.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('idsapi_settings_form'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('administer idsapi'),
'file' => 'idsapi.admin.inc',
);
return $items;
}
/**
* Implements hook_permission().
*/
function idsapi_permission() {
return array(
'administer idsapi' => array(
'title' => t('Administer the IDS API module'),
'description' => t('Perform administration tasks for the IDS API module.'),
),
);
}
/**
* Implements hook_help().
*/
function idsapi_help($path, $arg) {
if ($path == 'admin/help#idsapi') {
return t('Uses the IDS API to provide access to Eldis and Bridge content. API documentation: ') . IDS_API_DOCUMENTATION_URL;
}
}
/**
* Function used to retrieve IDS items using get_all.
*/
function idsapi_get_all($type, $set, $format) {
$idswrapper = new IdsApiWrapper;
$api_key = variable_get('idsapi_api_key', '');
$response = $idswrapper->getAll($type, $set, $api_key, $format);
return $response;
}
/**
* Function used to retrieve IDS items using search, with parameters.
*/
function idsapi_search($type, $set, $format, $params) {
$idswrapper = new IdsApiWrapper;
$api_key = variable_get('idsapi_api_key', '');
$response = $idswrapper->search($type, $set, $api_key, $format, 0, 0, $params);
return $response;
}
/* ---------------- Examples of calls to the IDS API --------------- */
/**
* Implements hook_block_info().
*/
function idsapi_block_info() {
$blocks = array();
$blocks['idsapi_eldis_documents'] = array(
'info' => t('Eldis documents'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['idsapi_eldis_organisations'] = array(
'info' => t('Eldis organisations'),
'cache' => DRUPAL_NO_CACHE,
);
$blocks['idsapi_bridge_documents'] = array(
'info' => t('Bridge documents'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function idsapi_block_view($block_name = '') {
$block = array();
$content = '';
// Retrieves latest Eldis documents
if ($block_name == 'idsapi_latest_eldis_documents') {
$response = idsapi_get_all('documents', 'eldis', 'full');
$items = $response->getArrayLinks();
if (is_array($items)) {
$theme_args = array('items' => $items, 'type' => 'ol');
$content = theme('item_list', $theme_args);
}
else {
$content = theme('help', 'Error when recovering block content.');
}
$block['subject'] = t('Eldis recent documents');
}
// Retrieves latest Eldis organisations
if ($block_name == 'idsapi_latest_eldis_organisations') {
$response = idsapi_get_all('organisations', 'eldis', 'full');
$items = $response->getArrayLinks();
if (is_array($items)) {
$theme_args = array('items' => $items, 'type' => 'ol');
$content = theme('item_list', $theme_args);
}
else {
$content = theme('help', 'Error when recovering block content.');
}
$block['subject'] = t('Eldis latest organisations');
}
// Retrieves latest Bridge documents
if ($block_name == 'idsapi_latest_bridge_documents') {
$response = idsapi_get_all('documents', 'bridge', 'full');
$items = $response->getArrayLinks();
if (is_array($items)) {
$theme_args = array('items' => $items, 'type' => 'ol');
$content = theme('item_list', $theme_args);
}
else {
$content = theme('help', 'Error when recovering block content.');
}
$block['subject'] = t('Bridge latest documents');
}
$block['content'] = $content;
return $block;
}