#436398 by Pasqualle: Support for aggregator category table.
authorEarl Miles
Tue, 2 Jun 2009 19:46:06 +0000 (19:46 +0000)
committerEarl Miles
Tue, 2 Jun 2009 19:46:06 +0000 (19:46 +0000)
CHANGELOG.txt
modules/aggregator.views.inc
modules/aggregator/views_handler_argument_aggregator_category_cid.inc [new file with mode: 0644]
modules/aggregator/views_handler_field_aggregator_category.inc [new file with mode: 0644]
modules/aggregator/views_handler_filter_aggregator_category_cid.inc [new file with mode: 0644]

index d83fa51..38d9e81 100644 (file)
@@ -34,6 +34,7 @@ Views 2.x
     o #408180 by joachim: Allow taxonomy term parent argument.
     o #469456 by dereine: Automatically give .info file during views bulk export.
     o #424460 by thePanz: Customizable breadcrumb title for arguments.
+    o #436398 by Pasqualle: Support for aggregator category table.
 
 Views 2.5
   Bugs fixed:
index e61d177..d24076a 100644 (file)
@@ -261,6 +261,66 @@ function aggregator_views_data() {
     ),
   );
 
+  // ----------------------------------------------------------------------
+  // Aggregator category feed table
+
+  $data['aggregator_category_feed']['table']['join'] = array(
+    'aggregator_item' => array(
+      'left_field' => 'fid',
+      'field' => 'fid',
+    ),
+  );
+
+  // ----------------------------------------------------------------------
+  // Aggregator category table
+
+  $data['aggregator_category']['table']['group'] = t('Aggregator category');
+
+  $data['aggregator_category']['table']['join'] = array(
+    'aggregator_item' => array(
+      'left_table' => 'aggregator_category_feed',
+      'left_field' => 'cid',
+      'field' => 'cid',
+    ),
+  );
+
+  // cid
+  $data['aggregator_category']['cid'] = array(
+    'title' => t('Category ID'),
+    'help' => t('The unique ID of the aggregator category.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_aggregator_category_cid',
+      'name field' => 'title',
+      'numeric' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_aggregator_category_cid',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // title
+  $data['aggregator_category']['title'] = array(
+    'title' => t('Category'),
+    'help' => t('The title of the aggregator category.'),
+    'field' => array(
+      'handler' => 'views_handler_field_aggregator_category',
+      'click sortable' => TRUE,
+     ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
   return $data;
 }
 
@@ -274,15 +334,26 @@ function aggregator_views_handlers() {
       'path' => drupal_get_path('module', 'views') . '/modules/aggregator',
     ),
     'handlers' => array(
-      // field handler
+      // field handlers
       'views_handler_field_aggregator_title_link' => array(
         'parent' => 'views_handler_field',
       ),
+      'views_handler_field_aggregator_category' => array(
+        'parent' => 'views_handler_field',
+      ),
 
       // argument handlers
       'views_handler_argument_aggregator_fid' => array(
         'parent' => 'views_handler_argument_numeric',
       ),
+      'views_handler_argument_aggregator_category_cid' => array(
+        'parent' => 'views_handler_argument_numeric',
+      ),
+
+      // filter handlers
+      'views_handler_filter_aggregator_category_cid' => array(
+        'parent' => 'views_handler_filter_in_operator',
+      ),
     ),
   );
 }
diff --git a/modules/aggregator/views_handler_argument_aggregator_category_cid.inc b/modules/aggregator/views_handler_argument_aggregator_category_cid.inc
new file mode 100644 (file)
index 0000000..1565e7f
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * Argument handler to accept an aggregator category id.
+ */
+class views_handler_argument_aggregator_category_cid extends views_handler_argument_numeric {
+  /**
+   * Override the behavior of title(). Get the title of the category.
+   */
+  function title_query() {
+    $titles = array();
+    $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
+
+    $result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN ($placeholders)", $this->value);
+    while ($term = db_fetch_object($result)) {
+      $titles[] = check_plain($term->title);
+    }
+    return $titles;
+  }
+}
diff --git a/modules/aggregator/views_handler_field_aggregator_category.inc b/modules/aggregator/views_handler_field_aggregator_category.inc
new file mode 100644 (file)
index 0000000..a13b483
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+// $Id$
+
+/**
+ * Field handler to provide simple renderer that allows linking to aggregator
+ * category.
+ */
+class views_handler_field_aggregator_category extends views_handler_field {
+  /**
+   * Constructor to provide additional field to add.
+   */
+  function construct() {
+    parent::construct();
+    $this->additional_fields['cid'] = 'cid';
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['link_to_category'] = array('default' => FALSE);
+    return $options;
+  }
+
+  /**
+   * Provide link to category option
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['link_to_category'] = array(
+      '#title' => t('Link this field to its aggregator category page'),
+      '#description' => t('This will override any other link you have set.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_category']),
+    );
+  }
+
+  /**
+   * Render whatever the data is as a link to the category.
+   *
+   * Data should be made XSS safe prior to calling this function.
+   */
+  function render_link($data, $values) {
+    if (!empty($this->options['link_to_category']) && !empty($values->{$this->aliases['cid']}) && $data !== NULL && $data !== '') {
+      $cid = $values->{$this->aliases['cid']};
+      $this->options['alter']['make_link'] = TRUE;
+      $this->options['alter']['path'] = "aggregator/category/$cid";
+    }
+    return $data;
+  }
+
+  function render($values) {
+    return $this->render_link(check_plain($values->{$this->field_alias}), $values);
+  }
+}
diff --git a/modules/aggregator/views_handler_filter_aggregator_category_cid.inc b/modules/aggregator/views_handler_filter_aggregator_category_cid.inc
new file mode 100644 (file)
index 0000000..0b4c8a7
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+// $Id$
+
+/**
+ * Filter by aggregator category cid
+ */
+class views_handler_filter_aggregator_category_cid extends views_handler_filter_in_operator {
+  function get_value_options() {
+    if (isset($this->value_options)) {
+      return;
+    }
+
+    $this->value_options = array();
+
+    $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title');
+    while ($category = db_fetch_object($result)) {
+      $this->value_options[$category->cid] = check_plain($category->title);
+    }
+  }
+}