Commit c6366c9b authored by jcnventura's avatar jcnventura

Issue #1299150: Views integration for all fields in the module tables.

parent ab193f75
......@@ -6,4 +6,6 @@ files[] = print.module
files[] = print.admin.inc
files[] = print.pages.inc
files[] = print.install
files[] = print.views.inc
files[] = print_join_page_counter.inc
configure = admin/config/user-interface/print
......@@ -328,3 +328,13 @@ function _print_scan_libs($lib, $mask) {
return array_unique($tools);
}
/**
* Implements hook_views_api().
*/
function print_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'print'),
);
}
<?php
/**
* Implements hook_views_data().
*/
function print_views_data() {
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['print_node_conf']['table']['group'] = t('Printer-friendly version');
$data['print_page_counter']['table']['group'] = t('Printer-friendly version');
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['print_node_conf']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
// 'type' => 'INNER',
);
$data['print_page_counter']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'path',
// 'type' => 'INNER',
'handler' => 'print_join_page_counter',
);
// print_node_conf fields
$data['print_node_conf']['link'] = array(
'title' => t('Web: Show link'),
'help' => t('Whether to show the printer-friendly version link.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_node_conf']['comments'] = array(
'title' => t('Web: Show link in individual comments'),
'help' => t('Whether to show the printer-friendly version link in individual comments.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_node_conf']['url_list'] = array(
'title' => t('Web: Show Printer-friendly URLs list'),
'help' => t('Whether to show the URL list.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// print_page_counter fields
$data['print_page_counter']['totalcount'] = array(
'title' => t('Web: Number of page accesses'),
'help' => t('Counter of accesses to the printer-friendly version for this node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['print_page_counter']['timestamp'] = array(
'title' => t('Web: Last access'),
'help' => t("The date of the last access to the node's printer-friendly version."),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
<?php
class print_join_page_counter extends views_join {
// PHP 4 doesn't call constructors of the base class automatically from a
// constructor of a derived class. It is your responsibility to propagate
// the call to constructors upstream where appropriate.
function construct($table, $left_table, $left_field, $field, $extra = array(), $type = 'LEFT') {
parent::construct($table, $left_table, $left_field, $field, $extra, $type);
}
function build_join($select_query, $table, $view_query) {
$this->left_field = "CONCAT('node/', " . $this->left_table . '.' . $this->left_field . ')';
$this->left_table = NULL;
parent::build_join($select_query, $table, $view_query);
}
}
?>
......@@ -7,4 +7,5 @@ files[] = print_mail.module
files[] = print_mail.inc
files[] = print_mail.admin.inc
files[] = print_mail.install
files[] = print_mail.views.inc
configure = admin/config/user-interface/print/email
......@@ -364,22 +364,6 @@ function print_mail_views_api() {
);
}
/**
* 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',
),
);
}
/**
* Implements hook_rules_action_info().
*
......
<?php
/**
* Implements hook_views_data().
*/
function print_mail_views_data() {
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['print_mail_node_conf']['table']['group'] = t('Printer-friendly version');
$data['print_mail_page_counter']['table']['group'] = t('Printer-friendly version');
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['print_mail_node_conf']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
// 'type' => 'INNER',
);
$data['print_mail_page_counter']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'path',
// 'type' => 'INNER',
'handler' => 'print_join_page_counter',
);
// print_mail_node_conf fields
$data['print_mail_node_conf']['link'] = array(
'title' => t('Email: Show link'),
'help' => t('Whether to show the send by email link.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_mail_node_conf']['comments'] = array(
'title' => t('Email: Show link in individual comments'),
'help' => t('Whether to show the send by email link in individual comments.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_mail_node_conf']['url_list'] = array(
'title' => t('Email: Show Printer-friendly URLs list'),
'help' => t('Whether to show the URL list.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// print_mail_page_counter fields
$data['print_mail_page_counter']['totalcount'] = array(
'title' => t('Email: Number of page accesses'),
'help' => t('Counter of accesses to the send by email form for this node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['print_mail_page_counter']['timestamp'] = array(
'title' => t('Email: Last access'),
'help' => t("The date of the last access to the node's send by email form."),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
$data['print_mail_page_counter']['sentcount'] = array(
'title' => t('Email: Number of sent emails'),
'help' => t('Counter of emails sent for this node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['print_mail_page_counter']['sent_timestamp'] = array(
'title' => t('Email: Last email sent'),
'help' => t('The date when the node was last sent by email.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
<?php
/**
* @file
* Views sort handler for the print_mail module
*
* 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']);
}
}
......@@ -7,4 +7,5 @@ files[] = print_pdf.module
files[] = print_pdf.admin.inc
files[] = print_pdf.pages.inc
files[] = print_pdf.install
files[] = print_pdf.views.inc
configure = admin/config/user-interface/print/pdf
......@@ -235,3 +235,13 @@ function print_pdf_generate_html($html, $meta, $filename = NULL) {
return NULL;
}
/**
* Implements hook_views_api().
*/
function print_pdf_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'print_pdf'),
);
}
<?php
/**
* Implements hook_views_data().
*/
function print_pdf_views_data() {
// The 'group' index will be used as a prefix in the UI for any of this
// table's fields, sort criteria, etc. so it's easy to tell where they came
// from.
$data['print_pdf_node_conf']['table']['group'] = t('Printer-friendly version');
$data['print_pdf_page_counter']['table']['group'] = t('Printer-friendly version');
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['print_pdf_node_conf']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'nid',
// 'type' => 'INNER',
);
$data['print_pdf_page_counter']['table']['join']['node'] = array(
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'left_field' => 'nid',
'field' => 'path',
// 'type' => 'INNER',
'handler' => 'print_pdf_join_page_counter',
);
// print_pdf_node_conf fields
$data['print_pdf_node_conf']['link'] = array(
'title' => t('PDF: Show link'),
'help' => t('Whether to show the PDF version link.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_pdf_node_conf']['comments'] = array(
'title' => t('PDF: Show link in individual comments'),
'help' => t('Whether to show the PDF version link in individual comments.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['print_pdf_node_conf']['url_list'] = array(
'title' => t('PDF: Show Printer-friendly URLs list'),
'help' => t('Whether to show the URL list.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'label' => t('Active'),
'type' => 'yes-no',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
// print_pdf_page_counter fields
$data['print_pdf_page_counter']['totalcount'] = array(
'title' => t('PDF: Number of page accesses'),
'help' => t('Counter of accesses to the PDF version for this node.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['print_pdf_page_counter']['timestamp'] = array(
'title' => t('PDF: Last access'),
'help' => t("The date of the last access to the node's PDF version."),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
return $data;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment