View source
<?php
function apachesolr_sort_menu() {
$items['admin/settings/apachesolr/sort'] = array(
'title' => 'Sorting',
'description' => 'Sorting settings',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'apachesolr_sort_page_form',
),
'access arguments' => array(
'administer site configuration',
),
'weight' => 55,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function apachesolr_sort_page_form_submit($form, &$form_state) {
foreach ($form['#post'] as $key => $field) {
if (is_array($field)) {
$keys = array_keys($field);
if (isset($field['apachesolr_sort_sort_' . $key])) {
variable_set('apachesolr_sort_sort_' . $key, TRUE);
}
else {
variable_set('apachesolr_sort_sort_' . $key, FALSE);
}
variable_set('apachesolr_sort_sort_weight_' . $key, $field['apachesolr_sort_sort_weight_' . $key]);
}
}
$bid = 'apachesolr-sort';
$delta = "sort";
}
function apachesolr_sort_page_form() {
$default_search_term = variable_get('apachesolr_sort_term', "test");
$form['apachesolr_sort_term'] = array(
'#type' => 'textfield',
'#title' => t('A search term which returns multiple search results. '),
'#default_value' => $default_search_term,
'#description' => t('A search term which returns multiple search results. '),
'#size' => 60,
);
$query = apachesolr_drupal_query($keys = $default_search_term);
$sorts = $query
->get_available_sorts();
$form['apachesolr_sort_enable'] = array(
'#type' => 'fieldset',
'#title' => t('enable/disable sort fields'),
'#tree' => FALSE,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['apachesolr_sort_weight'] = array(
'#type' => 'fieldset',
'#title' => t('adapt the weight on sort fields'),
'#tree' => FALSE,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
foreach ($sorts as $key => $sort) {
$variable = 'apachesolr_sort_sort_' . $key;
$wvariable = 'apachesolr_sort_sort_weight_' . $key;
$form['apachesolr_sort_enable'][$variable] = array(
'#type' => 'checkbox',
'#title' => $sort['title'],
'#default_value' => variable_get($variable, TRUE),
'#description' => t('enable this sort. '),
);
$form['apachesolr_sort_weight'][$wvariable] = array(
'#type' => 'textfield',
'#title' => t('The weight of ' . $sort['title']),
'#default_value' => variable_get($wvariable, 0),
'#description' => t('Change the order of the facest by altering this weight. '),
'#size' => 5,
);
}
return system_settings_form($form);
}
function apachesolr_sort_apachesolr_sort_links_alter($sort_links) {
foreach ($sort_links as $key => $sort_link) {
if (!variable_get('apachesolr_sort_sort_' . $key, TRUE)) {
unset($sort_links[$key]);
}
else {
$sort_links[$key]['weight'] = variable_get('apachesolr_sort_sort_weight_' . $key, '0');
}
}
uasort($sort_links, "apachesolr_sort_weight_sort");
return $sort_links;
}
function apachesolr_sort_weight_sort($a, $b) {
return strcmp($a['weight'], $b['weight']);
}