Jump to:
| Project: | Advertisement |
| Version: | 6.x-2.0-rc1 |
| Component: | ad_channel module |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Hi! I have a site which is based on roles to identify the user's profile who is surfing it.
First I created different ads groups for each role and I put the blocks one below the other, but if one user has two or more roles, he views two or more ads one below the other.
Then I installed the Nodeaccess module. I thought if I created only one group for all the ads and I grant view permissions for each role in each ad, the 'ad block' would displays randomly the permited ads. This module works perfectly with all content types, but not with Advertisment Type.
I didn't explore the ad module deeply because is huge! So I don't know if this feature already exists, but it will be a great feature!
My idea:
In Ads Creation Form add some checkboxes with the roles (defined at ads settings in administration page). The selected roles must be able to see the ad. If none role is selected, all roles must be able to see the ad.
thanks for taking time to read me :)
Comments
#1
This is not currently possible. It believe it would be best added as a feature to the ad_channel module, I'll leave it open to review at some point if I find the time - patches welcome.
#2
Hi, i think i understand what your trying to do, and if i do, i wanted to do the same thing. ive done very little php work, but have programmed in other languages. Anyway, this is working for me...
in whatever .tpl.php files i want to use it in, i place an ad as follows:
<?phpglobal $user;
if (!(in_array('adfree', $user->roles)))
{
print ad(NULL, 1, array('nids' => '66')); ;
}
?>
this particular example will show the advert unless the uesr has been assigned to the adfree role. and it will show add at node id 66.
To display an ad to a prticular role instead of to all but a particular role, use:
<?phpglobal $user;
if ((in_array('ads', $user->roles)))
{
print ad(NULL, 1, array('nids' => '66')); ;
}
?>
where node id 66 is the advert you want to show, and ads is the user role to show it to.
alternatively, im assuming you can create a new html ad, and put the following:
<?phpglobal $user;
if ((in_array('ads', $user->roles)))
{
print [ad code here]
}
?>
replacing the [] with your ad code. should also work with the first example excluding it from a certain role.
Hope this helps...
#3
Hi Pingu,
thank you very much for this code but I feel as if this takes much of the flexibility of the module - for example if I want to choose embedded ads which are automatically embedded in content after the Xth paragraph and where I can choose after which paragraph.
Is there anyone working on this issue?
Greez,
Tobias
#4
#5
From your initial post it looks like you are using blocks which are congifured to be displayed on a per role basis (configured via the block configuration page). If you have hard-coded the ad display blocks into a template file you should still be able to adapt the code below.
Instead of using the checkboxes to decide which user role should see the block, why don't you enter php code to determine the whether to display the block then you could check multiple roles and set up a heirarchy of which one you want to displayed and which ones you want hidden.
I haven't checked this code (and am not much of a php coder so this may contain errors) but it will look something like this based on 3 groups / user roles (x,y,z). This should hide group x if the user is a member of y or z and hide group y if the user is a member of z.
For group x:
<?php
global $user;
if ((in_array('x', $user->roles) && !(in_array('y', $user->roles)) && !(in_array('z', $user->roles))) {
return true;
}
else {
return false;
}
?>
For group y:
<?php
global $user;
if ((in_array('y', $user->roles)) && !(in_array('z', $user->roles))) {
return true;
}
else {
return false;
}
?>
Group z could be set up using the checkboxes.
The main problem with this is that you will have to go back and edit all the code whenever you add more roles.