forked from ding2/ting-client
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathting_client.admin.inc
More file actions
207 lines (171 loc) · 6.28 KB
/
ting_client.admin.inc
File metadata and controls
207 lines (171 loc) · 6.28 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* return a search_client configuration form :
* set name on search tab
* disable/enable cache
**/
function ting_client_cache_admin_form($form_state) {
$form = array();
$form['openformat']['search_client_enable_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Enable cache'),
'#description' => t('overall caching - very nice while testing, but might stress the system in production.
disable this if you wish NO caching for any webservices'),
'#default_value' => variable_get('search_client_enable_cache', FALSE),
);
$client = new ting_client_class();
$cache_classes = $client->get_all_cache_classes();
// suffixes to use for variables
$cache_lifetime = TingClientRequest::cache_lifetime;
$cache_enable = TingClientRequest::cache_enable;
// make cache configuration foreach request that implements ITingClientRequestCache
foreach( $cache_classes as $cache_class ) {
$element_name = $cache_class['name'];
$class_name = $cache_class['className'];
$form['openformat'][$element_name] = array(
'#type' => 'fieldset',
'#title' => $element_name,
);
$form['openformat'][$element_name][$class_name.$cache_enable] = array(
'#type' => 'checkbox',
'#title' => t('Enable cache'),
'#description' => t('Enable cache for this type of request' ),
'#default_value' => variable_get($class_name.$cache_enable, FALSE),
);
$form['openformat'][$element_name][$class_name.$cache_lifetime] = array(
'#type' => 'textfield',
'#title' => t('Cache lifetime'),
'#description' => t('For how many minutes do you wish to cache results'),
'#default_value' => variable_get($class_name.$cache_lifetime,'10'),
);
}
$form['#submit'] = array('ting_client_cache_admin_form_submit');
$form['buttons']['save'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
);
return $form;
}
/**
* submit handler for search_client_admin_form
**/
function ting_client_cache_admin_form_submit($form, $form_state) {
$client = new ting_client_class();
$cache_classes = $client->get_all_cache_classes();
// $cache_classes = ting_client_class::get_all_cache_classes();
// suffixes for variables
$cache_lifetime = TingClientRequest::cache_lifetime;
$cache_enable = TingClientRequest::cache_enable;
foreach( $form_state['values'] as $key => $val ) {
if( strpos($key, $cache_lifetime) || strpos($key, $cache_enable ) ) {
variable_set($key, $val);
}
}
// overall caching
variable_set('search_client_enable_cache', $form_state['values']['search_client_enable_cache']);
// rebuild menu to show search_client_name on search-tab
menu_rebuild();
drupal_set_message(t('The changes has been saved'));
}
/**
* Form builder; Configure ting settings for this site.
*
* @ingroup forms
* @see system_settings_form()
*/
function ting_client_admin_webservices_settings($form_state) {
form_load_include($form_state, 'inc', 'ting_client', 'ting_client.admin');
$form = array();
$form['webservices'] = array(
'#type' => 'fieldset',
'#title' => t('client webservice settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => FALSE,
);
$form['webservices']['ting_search_url'] = array(
'#type' => 'textfield',
'#title' => t('Search service URL'),
'#description' => t('URL to the Ting search webservice, e.g. http://bibliotek.dk/openbibdk/next/'),
'#required' => TRUE,
'#default_value' => variable_get('ting_search_url', ''),
);
/*
$form['webservices']['ting_scan_url'] = array(
'#type' => 'textfield',
'#title' => t('Scan service URL'),
'#description' => t('URL to the Ting scan webservice, e.g. http://openscan.addi.dk/1.7/'),
'#required' => TRUE,
'#default_value' => variable_get('ting_scan_url', ''),
);
$form['webservices']['ting_spell_url'] = array(
'#type' => 'textfield',
'#title' => t('Spell service URL'),
'#description' => t('URL to the Ting spell webservice, e.g. http://openspell.addi.dk/1.2/'),
'#required' => TRUE,
'#default_value' => variable_get('ting_spell_url', ''),
);
*/
$form['webservices']['ting_enable_logging'] = array(
'#type' => 'checkbox',
'#title' => t('Enable logging'),
'#default_value' => variable_get('ting_enable_logging', FALSE),
'#weight' => 1,
);
$form['webservices']['ting_agency'] = array(
'#type' => 'textfield',
'#title' => t('Library code'),
'#description' => t('The 6-digit code representing the library organization'),
'#default_value' => variable_get('ting_agency', ''),
);
$form['webservices']['ting_search_profile'] = array(
'#type' => 'textfield',
'#title' => t('Search profile'),
'#description' => t('Profile name, used for filtering the search based on settings from vip.dbc.dk.'),
'#default_value' => variable_get('ting_search_profile', ''),
);
$form['webservices']['ting_search_openformat'] = array(
'#type' => 'textfield',
'#title' => t('OpenFormat profile'),
'#description' => t('OpenFormat format name. Leave blank if using the default search result format (dkabm).'),
'#default_value' => variable_get('ting_search_openformat', 'dkabm'),
);
$intervals = array(
60,
300,
900,
1800,
3600,
10800,
43200,
86400,
259200,
604800,
);
$options = array(
0 => t('No caching'),
);
foreach ($intervals as $interval) {
$options[$interval] = format_interval($interval, 2);
}
$form['webservices']['ting_cache_lifetime'] = array(
'#type' => 'select',
'#title' => t('Cache lifetime'),
'#default_value' => variable_get('ting_cache_lifetime', TING_DEFAULT_CACHE_LIFETIME),
'#options' => $options,
'#description' => t("Cache answers from the datawell for this time. At least a few minutes is recommended, so the same objects doesn't have to be fetched on each page request."),
'#weight' => 1,
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#submit'][] = 'ting_client_admin_webservices_settings_submit';
return system_settings_form($form);
}
function ting_client_admin_webservices_settings_submit($form, &$form_state) {
// force a check for altered XSDs
$client = new ting_client_class();
$client->getXSDurls();
}