Commit b0e4e6a9 authored by jcnventura's avatar jcnventura

Issue #1281678 by Damien Tournoud: issue a single request in print_*_node_load().

parent 188ddeeb
......@@ -451,8 +451,17 @@ function print_node_view($node, $view_mode) {
* Implements hook_node_load().
*/
function print_node_load($nodes, $types) {
$ids = array();
foreach ($nodes as $node) {
_print_set_node_fields($node);
$ids[] = $node->nid;
}
$result = db_query('SELECT nid, link, comments, url_list FROM {print_node_conf} WHERE nid IN (:nids)', array(':nids' => $ids))->fetchAllAssoc('nid');
foreach ($nodes as $node) {
$node->print_display = isset($result[$node->nid]) ? intval($result[$node->nid]->link) : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_display_comment = isset($result[$node->nid]) ? intval($result[$node->nid]->comments) : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_display_urllist = isset($result[$node->nid]) ? intval($result[$node->nid]->url_list) : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
}
......@@ -561,25 +570,6 @@ function print_entity_info_alter(&$info) {
);
}
/**
* Auxiliary function to assign the per-node settings to the node object fields
*
* @param $node
* node to be modified
*/
function _print_set_node_fields(&$node) {
if (isset($node->nid)) {
$res = db_query("SELECT link, comments, url_list FROM {print_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
else {
$res = FALSE;
}
$node->print_display = $res ? intval($res->link) : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_display_comment = $res ? intval($res->comments) : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_display_urllist = $res ? intval($res->url_list) : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
/**
* Auxiliary function to discover a given page's title
*
......
......@@ -210,8 +210,17 @@ function print_mail_help($path, $arg) {
* Implements hook_node_load().
*/
function print_mail_node_load($nodes, $types) {
$ids = array();
foreach ($nodes as $node) {
_print_mail_set_node_fields($node);
$ids[] = $node->nid;
}
$result = db_query('SELECT nid, link, comments, url_list FROM {print_mail_node_conf} WHERE nid IN (:nids)', array(':nids' => $ids))->fetchAllAssoc('nid');
foreach ($nodes as $node) {
$node->print_mail_display = isset($result[$node->nid]) ? intval($result[$node->nid]->link) : variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_mail_display_comment = isset($result[$node->nid]) ? intval($result[$node->nid]->comments) : variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_mail_display_urllist = isset($result[$node->nid]) ? intval($result[$node->nid]->url_list) : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
}
......@@ -346,25 +355,6 @@ function _print_mail_access($permission) {
return (user_access($permission) && $page_access);
}
/**
* Auxiliary function to assign the per-node settings to the node object fields
*
* @param $node
* node to be modified
*/
function _print_mail_set_node_fields(&$node) {
if (isset($node->nid)) {
$res = db_query("SELECT link, comments, url_list FROM {print_mail_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
else {
$res = FALSE;
}
$node->print_mail_display = $res ? intval($res->link) : variable_get('print_mail_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_mail_display_comment = $res ? intval($res->comments) : variable_get('print_mail_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_mail_display_urllist = $res ? intval($res->url_list) : variable_get('print_mail_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
/**
* Update the print_mail_node_conf table to reflect the given attributes
* If updating to the default values, delete the record.
......
......@@ -325,8 +325,17 @@ function print_pdf_help($path, $arg) {
* Implements hook_node_load().
*/
function print_pdf_node_load($nodes, $types) {
$ids = array();
foreach ($nodes as $node) {
_print_pdf_set_node_fields($node);
$ids[] = $node->nid;
}
$result = db_query('SELECT nid, link, comments, url_list FROM {print_pdf_node_conf} WHERE nid IN (:nids)', array(':nids' => $ids))->fetchAllAssoc('nid');
foreach ($nodes as $node) {
$node->print_pdf_display = isset($result[$node->nid]) ? intval($result[$node->nid]->link) : variable_get('print_pdf_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_pdf_display_comment = isset($result[$node->nid]) ? intval($result[$node->nid]->comments) : variable_get('print_pdf_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_pdf_display_urllist = isset($result[$node->nid]) ? intval($result[$node->nid]->url_list) : variable_get('print_pdf_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
}
......@@ -413,25 +422,6 @@ function print_pdf_form_alter(&$form, &$form_state, $form_id) {
}
}
/**
* Auxiliary function to assign the per-node settings to the node object fields
*
* @param $node
* node to be modified
*/
function _print_pdf_set_node_fields(&$node) {
if (isset($node->nid)) {
$res = db_query("SELECT link, comments, url_list FROM {print_pdf_node_conf} WHERE nid = :nid", array(':nid' => $node->nid))
->fetch();
}
else {
$res = FALSE;
}
$node->print_pdf_display = $res ? intval($res->link) : variable_get('print_pdf_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
$node->print_pdf_display_comment = $res ? intval($res->comments) : variable_get('print_pdf_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
$node->print_pdf_display_urllist = $res ? intval($res->url_list) : variable_get('print_pdf_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
}
/**
* Update the print_pdf_node_conf table to reflect the given attributes
* If updating to the default values, delete the record.
......
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