From: Jason Skomorowski Date: Thu, 18 Nov 2010 00:42:43 +0000 (+0100) Subject: Towards per-node config. If only I can coax it into making the table... X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=8cde1b1aae9548ea8cf7a0009f41d0b7823a2198;p=mkdru-moved-to-drupal.org.git Towards per-node config. If only I can coax it into making the table... --- 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() {