Node config.
[mkdru-moved-to-drupal.org.git] / mkdru.module
index 9996cd9..a89db52 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+// $Id$
+
+
+
 // Module metainfo
 /**
 * Implementation of hook_node_info().
@@ -55,27 +59,86 @@ function mkdru_form(&$node, $form_state) {
   $form['title'] = array(
     '#type' => 'textfield',
     '#title' => check_plain($type->title_label),
-    '#required' => TRUE,
+    '#required' => FALSE,
     '#default_value' => $node->title,
     '#weight' => -5
   );
-  $form['pz2_path'] = array(
+
+  $form['search_settings']  = array(
+    '#type' => 'fieldset',
+    '#title' => t('Pazpar2/Service Proxy search settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE
+  );
+  $form['search_settings']['pz2_path'] = array(
     '#type' => 'textfield',
     '#title' => t('Pazpar2/Service Proxy path'),
-    '#description' => t('Absolute URL path without leading slash'),
+    '#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',
+  );
+  $form['search_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,
+  );
+
+  $form['display_settings']  = array(
+    '#type' => 'fieldset',
+    '#title' => t('Display settings'),
+    '#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->pz2_path) ? $node->pz2_path : 'pazpar2',
-    '#weight' => 0
+    '#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,
+  );
+  $form['display_settings']['subject_max'] = 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,
   );
   return $form;
 }
 
+
+/**
+* Implementation of 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.'));
+  }
+}
+
 /**
 * Implementation of hook_insert().
 */
 function mkdru_insert($node) {
-  db_query("INSERT INTO {mkdru} (nid, vid, pz2_path) VALUES (%d, %d, '%s')",
-    $node->nid, $node->vid, $node->pz2_path);
+  db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d)",
+    $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
 }
 
 /**
@@ -87,7 +150,7 @@ function mkdru_update($node) {
     mkdru_insert($node);
   }
   else {
-    db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
+    db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid);
   }
 }
 
@@ -98,10 +161,9 @@ function mkdru_update($node) {
  * from our table. The only way to handle revision deletion is by implementing
  * hook_nodeapi().
  */
-function node_example_nodeapi(&$node, $op, $teaser, $page) {
+function mkdru_nodeapi(&$node, $op, $teaser, $page) {
   switch ($op) {
     case 'delete revision':
-      // Notice that we're matching a single revision based on the node's vid.
       db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
       break;
   }
@@ -112,7 +174,7 @@ function node_example_nodeapi(&$node, $op, $teaser, $page) {
  *
  * When a node is deleted, we need to remove all related records from our table.
  */
-function node_example_delete($node) {
+function mkdru_delete($node) {
   // Deleting by nid covers all revisions.
   db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
 }
@@ -124,7 +186,8 @@ function node_example_delete($node) {
 * Implementation of hook_load()
 */
 function mkdru_load($node) {
-  return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
+  return array('mkdru' => db_fetch_object(db_query(
+    'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
 }
 
 /**
@@ -137,7 +200,7 @@ function mkdru_theme() {
       'arguments' => array(),
     ),
     'mkdru_page_js' => array(
-      'arguments' => array(),
+      'arguments' => array('node' => NULL),
     ),
 //     'mkdru_block_facet' => array(
 //       'template' => 'mkdru-block-facet',
@@ -149,11 +212,12 @@ function mkdru_theme() {
 /**
 * Theme function to include Javascript search client and deps
 */
-function theme_mkdru_page_js() {
+function theme_mkdru_page_js($node) {
   $path = drupal_get_path('module', 'mkdru');
   drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
   drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
   drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
+  drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
 }
 
 /** 
@@ -161,7 +225,7 @@ function theme_mkdru_page_js() {
 */
 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
   $node->content['mkdru_page_js'] = array(
-    '#value' => theme('mkdru_page_js'), 
+    '#value' => theme('mkdru_page_js', $node), 
     '#weight' => 0,
   );
   $node->content['mkdru_page'] = array(