Hey,

I'm trying to determine some visibility rules and I'm trying to determine whether or not flag_friend_access checkbox is checked on the node edit.

I.E. I'm looking for some code that more or less performs the following '$node->flag_friend_access' = TRUE or FALSE depending on whether it is checking. I have devel enabled and I don't see anything in the $node array. How do I check to see if the particular node has flag_friend_access checked or not?

Thanks!

Comments

rc2020’s picture

Anyone? Anything?

Scott Reynolds’s picture

Status: Active » Closed (duplicate)

There isn't one, its a bad system that I wrote. There is an issue somewhere that details, a.) creation of a table to hold the data b.) adding this to node_load.

Search around and find it. Create a patch and i will review.

rc2020’s picture

Status: Closed (duplicate) » Active

I looked for this in the queue and I couldn't find it, so I'm marking this as active from duplicate because if no solution can be found I'll use this queue as a launching pad to create the solution meself. I'm looking through the tables on where the heck this info is stored - and I'm having trouble.

The access function uses hook_node_grants() but I don't know where that data is stored on the database tables. Ideally, yes, it would go onto the node tables, so like, $node->grants would be an array of all users accessed to view that node, or something like that.

There needs to be some way to create a conditional for access, that way it gives admins far more flexibility on where to direct users if the access returns false.

Off the top of your head, do you have any clue where this data might be stored? I'm going to check the IRC rooms to ask about hook_node_grants().

Also, as a possible workaround, I might set a cck value on the node or some value somehow to differentiate private nodes from public - but that's not the ideal solution.

rc2020’s picture

From some searching, it would seem as if the access is put on the node_access table. I'm going to try my hand at writing a function for this. I don't know how to create a patch but if I can get something working I'll submit the function here, barring a better solution from someone more knowledgeable.

rc2020’s picture

Found a solution. The data is stored on the node_access table. Here is a function I wrote an included in my flag_friend_access.module.

You can really return any value you want, TRUE/FALSE, or a message. Good for using a custom tpl.php file to control redirects.

NOTE: This function ignores OG access checks which use the same method. You'll have to modify the code to include that check, should be fairly easy.

Here's the code:


/**Function to check to see if access restrictions are enabled on the node**/

function flag_friend_access_check($nid) {

$sql = "SELECT realm from {node_access} where nid = '$nid'";

$result = db_query($sql);

while ($val = db_fetch_array($result)) {
foreach ($val as $key => $value) {
	$access = $value;
		}
	if ($access == 'flag_friend') {
//Access is restricted
print 'restricted';
} else 	{
//Access is Open
print 'open';
		}
	}
}

rc2020’s picture

Update: Probably should use boolean values rather than 'open' or 'restricted'. I just modified the function to reflect that:


/**Function to check to see if access restrictions are enabled on the node**/

function flag_friend_access_check($nid) {

$sql = "SELECT realm from {node_access} where nid = '$nid'";

$result = db_query($sql);

while ($val = db_fetch_array($result)) {
foreach ($val as $key => $value) {
	$access = $value;
		}
	if ($access == 'flag_friend') {
return FALSE;
} else 	{
return TRUE;
		}
	}
}
Scott Reynolds’s picture

Status: Active » Closed (duplicate)