Towards generalised facets.
authorJason Skomorowski <jason@indexdata.com>
Wed, 23 Feb 2011 05:43:43 +0000 (06:43 +0100)
committerJason Skomorowski <jason@indexdata.com>
Wed, 23 Feb 2011 05:43:43 +0000 (06:43 +0100)
mkdru.install
mkdru.module

index 23d4de3..56b8d4b 100644 (file)
@@ -78,7 +78,18 @@ function mkdru_schema() {
 */
 function mkdru_install() {
   // Disable comments by default
-  variable_set('comment_mkdru', COMMENT_NODE_DISABLED);
+  variable_set('comment_mkdru', COMMENT_NODE_HIDDEN);
+  // Facets
+  $facets = array('source', 'subject', 'author');
+  variable_set('mkdru_facets', $facets);
+  // Restrict facet block visibility
+  foreach ($facets as $facet) {
+    db_insert('block_node_type')
+    ->fields(array(
+      'module' => 'mkdru',
+      'delta' => 'mkdru_facet_' . $facet,
+      'type' => 'mkdru'))->execute();
+  }
 }
 
 /**
@@ -87,4 +98,6 @@ function mkdru_install() {
 function mkdru_uninstall() {
   // Delete variables
   variable_del('pz2_js_path');
+  // Clear block visibility
+  db_delete('block_node_type')->condition('module', 'mkdru')->execute();
 }
\ No newline at end of file
index f9b89ed..b21b38b 100644 (file)
@@ -245,7 +245,7 @@ function mkdru_node_revision_delete($node) {
 function mkdru_delete($node) {
   // Deleting by nid covers all revisions.
   db_delete('mkdru')
-    ->condition('nid', $nid->nid)
+    ->condition('nid', $node->nid)
     ->execute();
 }
 
@@ -334,13 +334,13 @@ function mkdru_view($node, $view_mode) {
 * Implements hook_block_info()
 */
 function mkdru_block_info() {
-  // NB: block caching is redundant for static content
-  $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
-  $blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE;
-  $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
-  $blocks['mkdru_subjects']['cache'] = DRUPAL_NO_CACHE;
-  $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
-  $blocks['mkdru_authors']['cache'] = DRUPAL_NO_CACHE;
+  // facet blocks
+  $facets = variable_get('mkdru_facets');
+  foreach ($facets as $facet) {
+    // NB: block caching is redundant for static content
+    $blocks['mkdru_facet_' . $facet]['info'] = "mkdru - $facet " . t('facet');
+    $blocks['mkdru_facet_' . $facet]['cache'] = DRUPAL_NO_CACHE;
+  }
 
   // search blocks
   $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
@@ -349,6 +349,7 @@ function mkdru_block_info() {
         t('mkdru - search box for "' . $node->title . '"');
     $blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE;
   };
+
   return $blocks;
 }
 
@@ -356,24 +357,14 @@ function mkdru_block_info() {
 * Implements hook_block_view()
 */
 function mkdru_block_view($delta) {
-  switch ($delta) {
-    case 'mkdru_sources':
-      $block['subject'] = t('Source');
-      $block['content'] = theme('mkdru_block_facet',
-                                array('class' => 'mkdru-facet-source'));
-      return $block;
-    case 'mkdru_subjects':
-      $block['subject'] = t('Subject');
-      $block['content'] = theme('mkdru_block_facet',
-                                array('class' => 'mkdru-facet-subject'));
-      return $block;
-    case 'mkdru_authors':
-      $block['subject'] = t('Author');
-      $block['content'] = theme('mkdru_block_facet',
-                                array('class' => 'mkdru-facet-author'));
-      return $block;
-    }
-  if (substr($delta, 0, 13) == 'mkdru_search_') {
+  if (substr($delta, 0, 12) == 'mkdru_facet_') {
+    $facet = substr($delta, 12);
+    $block['subject'] = t(ucwords($facet));
+    $block['content'] = theme('mkdru_block_facet',
+                               array('class' => 'mkdru-facet-' . $facet));
+    return $block;
+  }
+  elseif (substr($delta, 0, 13) == 'mkdru_search_') {
     $nid = substr($delta, 13);
     $block['content'] = theme('mkdru_block_search',
         array('nid' => $nid, 'path' => '/node/' . $nid));