From 8cde1b1aae9548ea8cf7a0009f41d0b7823a2198 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Thu, 18 Nov 2010 01:42:43 +0100 Subject: [PATCH] Towards per-node config. If only I can coax it into making the table... --- mkdru.info | 2 +- mkdru.module | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/mkdru.info b/mkdru.info index 119b00d..e618a45 100644 --- a/mkdru.info +++ b/mkdru.info @@ -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 diff --git a/mkdru.module b/mkdru.module index 986ddb4..9996cd9 100644 --- a/mkdru.module +++ b/mkdru.module @@ -1,5 +1,5 @@ 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() { -- 1.7.10.4