News for certain FEU Groups

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

News for certain FEU Groups

Post by clapczyn »

Hello,

Maybe someone can help me with this, i've searched the Forum but couldnt find any Solution.

I need to implement a selection of FEU Groups to the News Module so that certain articles can only be viewed by the selected groups.
Categories are not an option because it should be possible to Show an article to more than one group ...
Best solution would be checkboxes of all groups (similar to multiple category selection in cgblog)

Is there any possibility without hacking THW wohle Module?

Thx in advance for any solution or tipps


Stefan
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: News for certain FEU Groups

Post by jmcgin51 »

with some custom fields and a bit of Smarty logic, this should be very easy...

You could even do it without any custom fields; it just depends on how you want to set it up.
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: News for certain FEU Groups

Post by clapczyn »

Hi, thanks for your reply!
I thought about custom fields, but I don't see how I can make the selection dynamical. When my Client adds a new FEU Group it should automatically appear in the selection (without me adding a new custom field for that new group)

Maybe I misunderstood what you meant?
I don't See how i can get something like:
For each FEU Group create a custom Field (checkbox)

Maybe you could go a bit more into detail?

thx again for your help!
Coldman
Power Poster
Power Poster
Posts: 318
Joined: Sun Jun 22, 2008 5:33 am

Re: News for certain FEU Groups

Post by Coldman »

I would use a UDT thats create a new category i News Module and Event Manager for this.

Write a UDT with insert new category statement. Then go to Extensions -> Event Manager and find "Frontend User Management OnCreateGroup An event generated when a user group is created" and click on OnCreateGroup. Then select the UDT that you want to use and hit save.

In a page or template use some smarty and capture what membergroup a logged in user belongs to and then use it, something like this.

Code: Select all

{news category=$MEMBERGROUP} 
You can read more about Event Manager here http://wiki.cmsmadesimple.org/index.php ... nt_Manager and UDT's here http://wiki.cmsmadesimple.org/index.php ... fined_Tags
Important Code of Conduct
Why don't use CMSMS Docs or search?
Do you read Help?
Admin for Swedish Translations Team
Moderator Swedish Forum
After your problem is solved, push the green button
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: News for certain FEU Groups

Post by clapczyn »

well thx for the answer, I have no experience with the Event Manager and very little with UDTs …

but I will give it a try ;)

THX!

*edit*
If anyone has another solution I would also like to try that …

*edit2*
Ok, searched the whole forum, and now I'm really frustrated
My plan was the following: Create a UDT that creates a new ExtraField (Checkbox) in News with the same name like the new created FEU.
Since I really suck at php I just don't get it at all ;)

Any help appreciated :-[
mcDavid
Power Poster
Power Poster
Posts: 377
Joined: Tue Mar 31, 2009 8:45 pm
Location: Delft, Netherlands

Re: News for certain FEU Groups

Post by mcDavid »

just put something like {if $ccuser->memberof('groupname')} around your templates. You can also make different templates for different groups or no groups, and choose the template you want to use in the {news} tag.
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: News for certain FEU Groups

Post by clapczyn »

Thx,
this is for displaying the article to the correct user, but that doesn't solve my problem regarding the groupselection when newsarticle is created …
An article can be limited to one or more FEUs

I think it would be handy if the system would create an extrafield as soon as a new FEU is created. That extrafield could get the same name as FEU and the type "checkbox".
When adding a Newsarticle the editor could select all the users that are allowed to see this article …

But as I said, I'm really bad at php - playing around with code from other UDTs but don't really understand what I'm doing ;)
mcDavid
Power Poster
Power Poster
Posts: 377
Joined: Tue Mar 31, 2009 8:45 pm
Location: Delft, Netherlands

Re: News for certain FEU Groups

Post by mcDavid »

I'm using different news categories for that.
clapczyn
Forum Members
Forum Members
Posts: 59
Joined: Tue Oct 27, 2009 2:00 pm

Re: News for certain FEU Groups

Post by clapczyn »

hi, maybe I'm wrong, but then you can't display the article to multiple categories …
mcDavid
Power Poster
Power Poster
Posts: 377
Joined: Tue Mar 31, 2009 8:45 pm
Location: Delft, Netherlands

Re: News for certain FEU Groups

Post by mcDavid »

That's indeed a problem with that method.

I've looked into it.
You can create a checkbox field definition in the news module. Let's say its called "groupname"

You can then use this in your template:

Code: Select all

{if $entry->groupname && $ccuser->memberof('groupname') || !$entry->groupname}
// show news item
{/if}
psuedo:
If the checkbox is selected and the user is logged in, OR when the checkbox is not selected, then this item can be showed.

This might just do it, if you also want to support more than one user group, you might want to write a user defined tag instead of using smarty logic. (it's possible with smarty but it will be a bit messy)
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: News for certain FEU Groups

Post by Wishbone »

clapczyn sponsored me to create a solution. His request was slightly different than posted here.. Instead of restricting by group, he wanted it to be by user.

UDT: ExtraUserField

Code: Select all

global $gCms;
$db = $gCms->getDb();

# Get username from the FEU trigger

$name = $params['name'];

# Make sure this field def doesn't exist

$sql = "SELECT id FROM " . cms_db_prefix() . "module_news_fielddefs
           WHERE name='$name'
           LIMIT 1;";

$dbresult =& $db->Execute($sql);
if ($dbresult && $row=$dbresult->FetchRow()) {
  return; # Field definition already exists. Abort!
}

# Field definition doesn't exist. Insert a new one

$sql = "INSERT INTO " . cms_db_prefix() . "module_news_fielddefs
           (`name`, `type`, `max_length`, `create_date`, `modified_date`, `item_order`, `public`)
           VALUES (?, ?, ?, ?, ?, ?, ?);";
$dbresult = $db->Execute(
   $sql, array($name, 'checkbox', 255, 0, 0, 1, 1)
);
The UDT above was registered as an OnCreateUser trigger. Upon a new user being created, the UDT searches for an existing News Field Def, and if it doesn't exist, it creates it. When editing a News article, he can select which users can see the article. He took care of the logic that parses the extra fields to see if the user matches.
Post Reply

Return to “Modules/Add-Ons”