Towards per-node config. If only I can coax it into making the table...
authorJason Skomorowski <jason@indexdata.com>
Thu, 18 Nov 2010 00:42:43 +0000 (01:42 +0100)
committerJason Skomorowski <jason@indexdata.com>
Thu, 18 Nov 2010 00:54:08 +0000 (01:54 +0100)
mkdru.info
mkdru.module

index 119b00d..e618a45 100644 (file)
@@ -1,3 +1,3 @@
-name = Z39.50 metasearch
+name = Z39.50/SRU metasearch
 description = Metasearching of Z39.50 and other targets via Index Data's Pazpar2 and associated tool stack.
 core = 6.x
index 986ddb4..9996cd9 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+// Module metainfo
 /**
 * Implementation of hook_node_info().
 */
@@ -36,12 +36,16 @@ function mkdru_access($op, $node, $account) {
   if ($op == 'update' || $op == 'delete') {
     if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
       return TRUE;
-    } else if (user_access('edit any metasearch interface', $account)) {
+    }
+    elseif (user_access('edit any metasearch interface', $account)) {
       return TRUE;
     }
   }
 }
 
+
+
+// Node config
 /**
 * Implementation of hook_form().
 */
@@ -55,11 +59,75 @@ function mkdru_form(&$node, $form_state) {
     '#default_value' => $node->title,
     '#weight' => -5
   );
-
+  $form['pz2_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Pazpar2/Service Proxy path'),
+    '#description' => t('Absolute URL path without leading slash'),
+    '#required' => TRUE,
+    '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2',
+    '#weight' => 0
+  );
   return $form;
 }
 
 /**
+* 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);
+}
+
+/**
+* Implementation of hook_update().
+*/
+function mkdru_update($node) {
+  if ($node->revision) {
+    // New revision; treat it as a new record.
+    mkdru_insert($node);
+  }
+  else {
+    db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
+  }
+}
+
+/**
+ * Implementation of hook_nodeapi().
+ *
+ * When a node revision is deleted, we need to remove the corresponding record
+ * from our table. The only way to handle revision deletion is by implementing
+ * hook_nodeapi().
+ */
+function node_example_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;
+  }
+}
+
+/**
+ * Implementation of hook_delete().
+ *
+ * When a node is deleted, we need to remove all related records from our table.
+ */
+function node_example_delete($node) {
+  // Deleting by nid covers all revisions.
+  db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
+}
+
+
+
+// Node rendering
+/**
+* Implementation of hook_load()
+*/
+function mkdru_load($node) {
+  return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
+}
+
+/**
 * Implementation of hook_theme().
 */
 function mkdru_theme() {