Skip to content

Commit

Permalink
Added a materials tab to the ting.admin page, where to define which m…
Browse files Browse the repository at this point in the history
…aterials to search in. Implemented in the ting.search module as well
  • Loading branch information
ramlev committed May 27, 2010
1 parent c199819 commit ce7b2da
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
44 changes: 42 additions & 2 deletions includes/ting.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function ting_admin_settings_form_addi($form_state) {

$form['addi'] = array(
'#type' => 'fieldset',
'#title' => t('Additional Information settings'),
'#title' => t('Ting - Additional Information settings'),
'#description' => t('The Additional Information service is used to retrieve cover images and other information about objects. <a href="http://www.danbib.dk/index.php?doc=forsideservice">More information about the service (in Danish)</a>'),
'#tree' => FALSE,
);
Expand Down Expand Up @@ -113,7 +113,7 @@ function ting_admin_settings_form_proxy($form_state) {

$form['proxy'] = array(
'#type' => 'fieldset',
'#title' => t('Proxy service'),
'#title' => t('Ting Proxy service'),
'#description' => t('Restricted-access resources referenced by Ting may be accessed through the library\'s proxy server'),
'#tree' => FALSE,
);
Expand All @@ -135,6 +135,46 @@ function ting_admin_settings_form_proxy($form_state) {

return system_settings_form($form);
}
/**
* Ting search settings form - Material tab
*
* @author Hasse R. Hansen <hasse@reload.dk>
*/
function ting_admin_settings_form_material($form_state) {
$form = $options = array();

$form['material'] = array(
'#type' => 'fieldset',
'#title' => t('Ting Materials'),
'#description' => t('Choose in which materials to search'),
'#tree' => FALSE
);

// Fetch material information from Ting
require_once drupal_get_path('module', 'ting') . '/ting.client.inc';
$request = ting_get_request_factory()->getScanRequest();
$request->setField('phrase.type');
$request->setLower('');

// TODO: Fix webservice to really use the quantity
$request->setNumResults(9999);
$data = ting_execute($request);

foreach ($data->terms as $m) {
if ($m->name != '') {
$options[$m->name] = $m->name;
}
}

$form['ting_materials'] = array(
'#type' => 'checkboxes',
'#default_value' => variable_get('ting_materials', array()),
'#options' => $options,
'#description' => t('Check which material types to be searchable in the ting_ssearch.'),
);

return system_settings_form($form);
}

/**
* Value callback for restricted_access_proxy_hostnames field defined in
Expand Down
16 changes: 13 additions & 3 deletions ting.client.inc
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,11 @@ function ting_add_agency(TingClientAgentRequest $request) {
}

function ting_remove_supporting_types(TingClientSearchRequest $request) {
$supportingTypes = array('materialevurdering*', 'anmeldelse');
$supportingTypes = arrange_types(variable_get('ting_materials', array()));
foreach ($supportingTypes as &$type)
{
$type = 'facet.type='.$type;
$type = "facet.type=" . $type ;
}

$request->setQuery($request->getQuery().' NOT ('.implode(' OR ', $supportingTypes).')');
return $request;
}
Expand All @@ -516,3 +515,14 @@ function ting_rewrite_download_url($url) {
return $url;
}

function arrange_types($types = false) {
$return = array();
if (is_array($types)) {
foreach ($types as $k => $s) {
if ($s == false) {
$return[] = $k;
}
}
}
return $return;
}
12 changes: 12 additions & 0 deletions ting.module
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ function ting_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);

$items['admin/settings/ting/material'] = array(
'title' => 'Material',
'description' => '',
'access arguments' => array('access administration pages'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_admin_settings_form_material'),
'file' => 'ting.admin.inc',
'file path' => $path,
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);

return $items;
}
Expand Down

0 comments on commit ce7b2da

Please sign in to comment.