Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Restricting ability to add links to certain categories

Quote Reply
Restricting ability to add links to certain categories
I think this has been discussed before but I seem to be unable to find the thread. I'd like to create categories with sub-categories and restrict the ability to post links to the main categories. Does anyone have an idea how to do this?

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Restricting ability to add links to certain categories In reply to
Try looking at this thread:

http://www.gossamer-threads.com/...;search_string=isSub

I am using Shaun's suggestion, and it works great for me.

ronzo
Quote Reply
Re: [ronzo] Restricting ability to add links to certain categories In reply to
A slightly more general solution, using sean's manual method, would be to add a field "AllowLinks", and have it default to "Yes".

Then, edit each category you do *NOT* want to allow links in, and set it to "No".

If it's an Enum field, this should become a drop down list in the admin.

Links doesn't keep track of a "depth" of a link, the only absolute is the FatherID=0 for root categories.

Use the template tags to show the add-link line:

<%if AllowLinks eq "Yes"%> ....

This is the start of a minor plugin/global, which would only allow adding links to categories that had *no* sub categories.

I've been thinking about this for the auction system. The "AllowLinks" would be an "override". In my system, it would default to "No", but you could "AllowLinks" by setting it to "Yes".

The *real* work would be done by a little global, or function, that checks to see if the current category has sub categories, and if it does, it will send you back to the "Select Subcategory" screen (or disallow link additions by not showing an add-link link).

Should be able to find the answer with a low-overhead call to :

select ID from Category where FatherID = "current_category_ID"

If hits = 0/null then it's a leaf node, and you can add links. If hits >0 then it's not a leaf node, and you can't add links unless "AllowLinks = Yes".

Actually, the more I think about it now, a simple little global, could probably do it:

<%if FatherID%>
<%check_for_subcats(ID)%>
<%endif%>

The if FatherID should cut some unnecesary processing,

sub {
my $id = shift;
my $db_cat = $DB->table('Category');
my $count = $db_cat->count ( { FatherID => $id });
return ( {has_subcats => $count} );
}

Then,

<%if FatherID%>
<%check_for_subcats(ID)%>

<%if has_subcats eq '0' or AllowLinks eq 'Yes'%>
.... allow link additions .....
<%else%>
... nothing, or error message ....
<%endif%>

<%endif%>


I haven't tested this, so it may need tweaking, but this would be the idea.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.