'not null' => TRUE,
'default' => 0
),
- 'pz2_path' => array(
+ 'settings' => array(
'type' => 'text',
'not null' => TRUE,
- 'description' => t('Path to Pazpar2 or Service Proxy.')
- ),
- 'use_sessions' => array(
- 'description' => t('Session handling toggle.'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'source_max' => array(
- 'description' => t('Number of sources to display'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'author_max' => array(
- 'description' => t('Number of authors to display'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'subject_max' => array(
- 'description' => t('Number of subjects to display'),
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'sp_user' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'description' => t('Service Proxy username')
- ),
- 'sp_pass' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'description' => t('Service Proxy password')
+ 'description' => 'Metasearch settings',
),
),
'primary key' => array('nid', 'vid'),
variable_set('comment_mkdru', COMMENT_NODE_DISABLED);
// Create table.
drupal_install_schema('mkdru');
+ // Default settings
+ $settings['pz2_path'] = "/pazpar2/search.pz2";
+ $settings['use_sessions'] = 1;
+ $settings['sp']['user'] = "";
+ $settings['sp']['pass'] = "";
+ $settings['facets']['source']['displayName'] = "Source";
+ $settings['facets']['source']['pz2Name'] = "xtargets";
+ $settings['facets']['source']['limiter'] = NULL;
+ $settings['facets']['source']['multiLimit'] = NULL;
+ $settings['facets']['source']['max'] = 10;
+ $settings['facets']['source']['orderWeight'] = 1;
+ $settings['facets']['subject']['displayName'] = "Subject";
+ $settings['facets']['subject']['pz2Name'] = "subject";
+ $settings['facets']['subject']['limiter'] = "su";
+ $settings['facets']['subject']['multiLimit'] = TRUE;
+ $settings['facets']['subject']['max'] = 10;
+ $settings['facets']['subject']['orderWeight'] = 2;
+ $settings['facets']['author']['displayName'] = "Author";
+ $settings['facets']['author']['pz2Name'] = "author";
+ $settings['facets']['author']['limiter'] = "au";
+ $settings['facets']['author']['multiLimit'] = FALSE;
+ $settings['facets']['author']['max'] = 10;
+ $settings['facets']['author']['orderWeight'] = 3;
+ variable_set('mkdru_defaults', $settings);
+ variable_set('mkdru_ding', $settings);
}
/**
drupal_uninstall_schema('mkdru');
// Delete variables
variable_del('pz2_js_path');
-}
-
-function mkdru_update_6100() {
- $ret = array();
- db_add_field($ret, 'mkdru', 'sp_user', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') );
- db_add_field($ret, 'mkdru', 'sp_pass', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') );
- return $ret;
-}
+ variable_del('mkdru_defaults');
+ variable_del('mkdru_ding');
+}
\ No newline at end of file
drupal_add_js($path . '/recipe.js', 'module', 'footer');
drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
- $html = theme('mkdru_results');
+ $html = theme('mkdru_results');
drupal_add_js(array('mkdru' =>
array(
- 'use_sessions' => variable_get('use_sessions', '1'),
+ 'settings' => variable_get('mkdru_ding'),
'pz2_path' => variable_get('pz2_path', '/pazpar2/search.pz2'),
- 'sp_user' => variable_get('sp_user', ''),
- 'sp_pass' => variable_get('sp_pass', ''),
'query' => $keys
)
), 'setting');
*/
function mkdru_menu() {
$items['admin/settings/mkdru'] = array(
- 'title' => 'mkdru Settings',
+ 'title' => 'Pazpar2 Metasearch Settings',
'description' => 'Settings for mkdru.',
'page callback' => 'drupal_get_form',
'page arguments' => array('mkdru_admin_settings'),
'type' => MENU_NORMAL_ITEM,
'file' => 'mkdru.admin.inc',
);
+ $items['admin/settings/mkdru-ding'] = array(
+ 'title' => 'Pazpar2 Metasearch Ding Integration',
+ 'description' => 'Search settings for mkdru instance integrated into Ding.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('mkdru_ding_settings'),
+ 'access arguments' => array('administer site configuration'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
return $items;
}
}
+// Config form common to node and settings
+// function mkdru_settings_form($form, &$form_state) {
+function mkdru_settings_form(&$form_state) {
+// dpm($form_state);
+ if (isset($form_state['values']['settings'])) {
+ $settings = $form_state['build_info']['args']['settings'];
+ }
+ else if (isset($form_state['build_info']['args']['settings'])) {
+ $settings = $form_state['build_info']['args']['settings'];
+ }
+ else {
+ $settings = variable_get('mkdru_defaults', NULL);
+ }
-// Node config
-/**
-* Implements hook_form()
-*/
-function mkdru_form(&$node, $form_state) {
- $type = node_get_types('type', $node);
-
- $form['title'] = array(
- '#type' => 'textfield',
- '#title' => check_plain($type->title_label),
- '#required' => FALSE,
- '#default_value' => $node->title,
- '#weight' => -5
+ $form['settings'] = array(
+ '#tree' => TRUE,
);
- $form['search_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Pazpar2/Service Proxy search settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE
- );
- $form['search_settings']['pz2_path'] = array(
+ $form['settings']['pz2_path'] = array(
'#type' => 'textfield',
'#title' => t('Pazpar2/Service Proxy path'),
'#description' => t('Path that takes Pazpar2 commands via HTTP'),
'#required' => TRUE,
- '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
+ '#default_value' => $settings['pz2_path'],
);
- $form['search_settings']['use_sessions'] = array(
+ $form['settings']['use_sessions'] = array(
'#type' => 'checkbox',
'#title' => t('Session handling'),
'#description' => t('Disable for use with Service Proxy'),
- '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
+ '#default_value' => $settings['use_sessions'],
);
- $form['sp_settings'] = array(
+ $form['settings']['sp'] = array(
'#type' => 'fieldset',
'#title' => t('Service Proxy specific settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
- $form['sp_settings']['sp_user'] = array(
+ $form['settings']['sp']['user'] = array(
'#type' => 'textfield',
'#title' => t('Service Proxy username'),
'#description' => t('Service Proxy username'),
'#required' => FALSE,
- '#default_value' => isset($node->mkdru->sp_user) ?
- $node->mkdru->sp_user : '',
+ '#default_value' => $settings['sp']['user'],
);
- $form['sp_settings']['sp_pass'] = array(
- '#type' => 'textfield',
+ $form['settings']['sp']['pass'] = array(
+ '#type' => 'password',
'#title' => t('Service Proxy password'),
'#description' => t('Service Proxy password'),
'#required' => FALSE,
- '#default_value' => isset($node->mkdru->sp_pass) ?
- $node->mkdru->sp_pass : '',
+ '#default_value' => $settings['sp']['pass'],
);
- $form['display_settings'] = array(
+ $form['settings']['facets'] = array(
'#type' => 'fieldset',
- '#title' => t('Display settings'),
+ '#title' => t('Facet settings'),
+ // Set up the wrapper so that AJAX will be able to replace the fieldset.
+ '#prefix' => '<div id="mkdru-facets-form-wrapper">',
+ '#suffix' => '</div>',
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
- $form['display_settings']['source_max'] = array(
- '#type' => 'textfield',
- '#title' => t('Number of sources to display'),
- '#required' => TRUE,
- '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
- '#size' => 3,
- '#maxlength' => 3,
- );
- $form['display_settings']['author_max'] = array(
- '#type' => 'textfield',
- '#title' => t('Number of authors to display'),
- '#required' => TRUE,
- '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
- '#size' => 3,
- '#maxlength' => 3,
+ if (empty($form_state['facet_names'])) {
+ $form_state['facet_names'] = array('source', 'author', 'subject');
+ }
+ foreach ($form_state['facet_names'] as $facet) {
+ $form['settings']['facets'][$facet] = array(
+ '#type' => 'fieldset',
+ '#title' => $facet . ' ' . t('facet'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['settings']['facets'][$facet]['displayName'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Facet name to display in UI'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['displayName'],
+ );
+ $form['settings']['facets'][$facet]['pz2Name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of termlist in Pazpar2'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['pz2Name'],
+ );
+ $form['settings']['facets'][$facet]['limiter'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Query limiter string'),
+ '#default_value' => $settings['facets'][$facet]['limiter'],
+ '#size' => 5,
+ );
+ $form['settings']['facets'][$facet]['max'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Number of terms to display'),
+ '#required' => TRUE,
+ '#default_value' => $settings['facets'][$facet]['max'],
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ $form['settings']['facets'][$facet]['orderWeight'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Facet weight'),
+ '#default_value' => $settings['facets'][$facet]['orderWeight'],
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ }
+// $form['new_facet'] = array(
+// '#type' => 'fieldset',
+// '#title' => t('Add new facet...'),
+// '#tree' => TRUE,
+// '#collapsible' => TRUE,
+// '#collapsed' => FALSE
+// );
+// $form['new_facet']['canonical'] = array(
+// '#type' => 'textfield',
+// '#title' => t('Canonical name of new facet'),
+// );
+// $form['new_facet']['button'] = array(
+// '#type' => 'submit',
+// '#value' => t('Add facet'),
+// '#description' => t('Configure additional facets based on Pazpar2/SP termlists'),
+// '#weight' => 1,
+// '#submit' => array('mkdru_add_facet_form'),
+// '#ajax' => array(
+// 'callback' => 'mkdru_add_facet_callback',
+// 'wrapper' => 'mkdru-facets-form-wrapper',
+// ),
+// );
+ return $form;
+}
+
+
+
+// Ding config
+function mkdru_ding_settings(&$form_state) {
+ $form_state['build_info']['args']['settings'] = variable_get('mkdru_ding', NULL);
+ $form = drupal_retrieve_form('mkdru_settings_form', &$form_state);
+ $form['settings']['#title'] = t('Default search settings');
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => 'Save configuration',
);
- $form['display_settings']['subject_max'] = array(
+ return $form;
+}
+function mkdru_ding_settings_submit($form, &$form_state) {
+ dpm($form_state);
+ variable_set('mkdru_ding', $form_state[values][settings]);
+ drupal_set_message(t('The configuration options have been saved.'));
+}
+
+
+
+// Node config
+/**
+* Implements hook_form()
+*/
+function mkdru_form(&$node, &$form_state) {
+ if (isset($node->settings)) {
+ // Second decode parameter indicates associative array
+ $form_state['build_info']['args']['settings'] = json_decode($node->settings, TRUE);
+ }
+
+ $form = drupal_retrieve_form('mkdru_settings_form', &$form_state);
+
+ $type = node_get_types('type', $node);
+ $form['title'] = array(
'#type' => 'textfield',
- '#title' => t('Number of subjects to display'),
- '#required' => TRUE,
- '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
- '#size' => 3,
- '#maxlength' => 3,
+ '#title' => check_plain($type->title_label),
+ '#required' => FALSE,
+ '#default_value' => $node->title,
+ '#weight' => -5
);
return $form;
}
* Implements hook_validate()
*/
function mkdru_validate($node) {
- if (!is_numeric($node->source_max)) {
- form_set_error('source_max', t('Please enter a number.'));
- }
- if (!is_numeric($node->author_max)) {
- form_set_error('author_max', t('Please enter a number.'));
- }
- if (!is_numeric($node->subject_max)) {
- form_set_error('subject_max', t('Please enter a number.'));
- }
+ // TODO: validation
}
/**
* Implements hook_insert().
*/
function mkdru_insert($node) {
- drupal_write_record('mkdru', $node);
+ $record['nid'] = $node->nid;
+ $record['vid'] = $node->vid;
+ $record['settings'] = json_encode($node->settings);
+ drupal_write_record('mkdru', &$record);
}
/**
mkdru_insert($node);
}
else {
- drupal_write_record('mkdru', $node, 'vid');
+ $record['nid'] = $node->nid;
+ $record['vid'] = $node->vid;
+ $record['settings'] = json_encode($node->settings);
+ drupal_write_record('mkdru', &$record, 'vid');
}
}
* Implements hook_load()
*/
function mkdru_load($node) {
- return array('mkdru' => db_fetch_object(db_query(
- 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
+ return db_fetch_object(db_query('SELECT * FROM {mkdru} WHERE vid = %d', $node->vid));
}
/**
drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer', TRUE, TRUE, FALSE);
drupal_add_js($path . '/mkdru.client.js', 'module', 'footer', TRUE, TRUE, FALSE);
drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
+ drupal_add_js(array('mkdru' =>
+ array(
+ 'settings' => $node->settings,
+ )
+ ), 'setting');
}
/**