Closed (outdated)
Project:
Private
Version:
5.x-1.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
25 Jun 2008 at 16:02 UTC
Updated:
26 Sep 2016 at 15:43 UTC
Jump to comment: Most recent
the views assumes private nodes as regular nodes, so if we define for example 10 nodes to display in the view, if the first two nodes are private, then the view will display only 8 nodes.
To prevent this, I think the better would be to implement the hook views_alter_query, in order to add a new "WHERE private=0" in the query.
Here is the patch:
/**
* Hook views_query_alter
*/
function private_views_query_alter(&$query, &$view) {
if (!user_access('access private content')) {
// the user has no access to private content
// so we alter the query
$query->add_table('private');
$private_join = array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'table' => 'private',
'field' => 'nid'
),
);
$query->joins['private'][1]=$private_join;
$query->add_where('private.private = 0');
}
}
Comments
Comment #1
dingbats commentedBut, would this make it impossible to have a block of "My private nodes"?
Comment #2
dingbats commentedI'm running 6.x-1.x-dev, with an altered version of your code,
Assuming I create a new view: a page of my nodes that I have marked private, this is the SQL generated:
The constraint
(private.private = 1) AND (private.private = 0)will always bring up an empty set.Comment #3
dingbats commentedSorry for confusing anybody who tried the above code and did not get the same query result. I had made some patches to my Private module to integrate it with Views. See #361392: Views integration drupal 5.x for more info.
Comment #4
gregglesMarking this as closed-outdated as the 5.x version is no longer supported and I don't think this issue affects the 6.x and later versions.
If the problem persists on newer versions, please reopen this issue.
Thanks!