Download & Extend

Simple way to check access based on content type using php?

Project:Content Type Administration by Organic Group
Version:6.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hey,

I have a question about being some type of conditional statement being able to be done in php checking to see if a content type is allowed in a group or not. The reason for this is the Organic group add UI isn't all that fantastic, and I'm trying to make an icon menu to replace it, and im wondering if I can do this with this module installed.

I'm not a php developer but I can do basic conditionals and such. So what I'm looking to do is essentially say (in php),

"If node type "event" is allowed to be posted in this group, Only local images are allowed., , else if node type "blog" is allowed to be posted in this group, and so on, and so on"

What is the function to check to see if "x node type is allowed to be posted in this group"? Is there a simple function that will resolve a boolean value based on what the settings are for that particular group? I'm curious to see if I can get this working.

Many thanks!

Comments

#1

Any chance someone has been able to take a look at this?

Thanks

#2

Does anyone have any time to help out here ?

Thanks Paul

#3

Do a print_r($example); in wherever you are trying to work something out, and see what values are available, doing a search (ctrl+f) from there, for words that could be related to the group and see if theres a variable being passed to each content "type" and the organic group. Or what I usually do when I'm trying to find a variable/function that I can't seem to find in drupal API/forums is go into content template and dig through the body variables there and see if the module in question is leaving a hidden value that can be referenced for the purpose I need.

Sorry I can't be more exact since I'm not familiar with what your asking, but I'm trying to assume that same approach could apply to finding the variable you need, and I would imagine you could easily just run a few IF statements off it, or at least hope so. If this doesn't help I can try to give you more feedback through e-mail if I can get some more details from ya, so feel free to private message me and I'll see if I can help more.

#4

To provide a bit better clarification:

Essentially, I want to check to see if a content type is allowed by og content type admin in that particular group. A group administrator might want to not allow content type x and y into their group. (Group admins can still add them).

The reason I need this is because I want to create an icon menu for users to add content to their groups. If I don't do a conditional statement to determine whether or not the user has access to post that content, the icon menu will show the content types the group administrator wishes to disallow in their group, which would not be good for either the user or the group. So I have to be able to have some method which helps me determine whether or not the content type is allowed to be posted in the group before I print the link and the icon to add that specific type of content.

I'll try your variable check, but my php is very limited. If I knew the actual function to check to see if the access was true or not, it would save me alot of trouble.

Many thanks!

#5

Version:5.x-1.6» 6.x-1.2

Hey,

Wow I forgot I opened this issue nearly a year go. (Moving the issue to 6x since I've upgraded).

Essentially I'd like to run a user access check through some type of function to see if the user has access to add x content type in this group, for the purposes of creating a custom icon menu. user_access() only checks a string, not a url.

I'm looking for a function that would return TRUE or FALSE based on whether the user has the ability to add x content type in this group.

The idea would be this:


<?php
if(user_can_add_content_type_in_this_group($groupid, $contenttype)):
?>

//Print code for icon and link to add content type
<?php
endif;
?>

Does anything like that exist for this module?

I'm going to go through the module tonight and see if I can find a function I can pull out of it. If you happen to know something off the top of your head please let me know!

Thanks!

#6

Did you find an elegant solution for this?

#7

Posted prematurely, will post solution here by tomorrow.

#8

OK, so just use user_access(x) (user module api)

an example:

<?php
//get all content types. (node module api)
$types=node_get_types($op = 'types');

//check is_array($type) here maybe

foreach ($types as $type){
if(
user_access("create $type->type content") ){
//only create access types will live here, CHECK permissions table in drupal and you will get a better idea.

}
?>
nobody click here