Issue #1299150 by lliss: View integration for the most emailed counter.
authorJoao Ventura
Sun, 16 Oct 2011 19:06:50 +0000 (21:06 +0200)
committerJoao Ventura
Sun, 16 Oct 2011 19:06:50 +0000 (21:06 +0200)
print_mail/print_mail.module
print_mail/views_handler_sort_print_mail_sentcount.inc [new file with mode: 0644]

index d57a4bf..799a059 100644 (file)
@@ -588,3 +588,29 @@ function print_mail_mollom_form_info($form_id) {
   }
   return $form_info;
 }
+
+/**
+ * Implements hook_views_api().
+ */
+function print_mail_views_api() {
+  return array(
+    'api' => 2.0,
+    'path' => drupal_get_path('module', 'print_mail'),
+  );
+}
+
+/**
+ * Implements hook_views_data_alter().
+ *
+ * Provide a new option the views sorts for the number of times
+ *  a node has been emailed.
+ */
+function print_mail_views_data_alter(&$data) {
+  $data['node']['print_mail_sentcount'] = array(
+    'title' => t('Number of times emailed'),
+    'help' => t("The total number of times the node has been sent through print module's send by email feature."),
+    'sort' => array(
+      'handler' => 'views_handler_sort_print_mail_sentcount',
+    ),
+  );
+}
diff --git a/print_mail/views_handler_sort_print_mail_sentcount.inc b/print_mail/views_handler_sort_print_mail_sentcount.inc
new file mode 100644 (file)
index 0000000..a274263
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * Extend the default sort handler.
+ * Add a relationship with custom join to print's emailed counter
+ */
+class views_handler_sort_print_mail_sentcount extends views_handler_sort {
+  function query() {
+    $table = 'print_mail_page_counter';
+    $join = new views_join;
+    $join->construct($table, NULL, "CONCAT('node/', node.nid)", 'path', NULL, 'LEFT');
+    $alias = $this->query->add_relationship($table, $join, 'node');
+    $this->query->add_orderby($table, 'sentcount', $this->options['order']);
+  }
+}