Home : Products : Gossamer Links : Discussions :

Products: Gossamer Links: Discussions: Re: [hegu] Help needed with different form for different category: Edit Log

Here is the list of edits for this post
Re: [hegu] Help needed with different form for different category
This global should check whether current category ID is subcategory of the examined category or not. Returns true if current category id, is same, or current category is child of the examined category.

Global name: is_child_category
Code:
sub {
my $catid_current = shift;
my $catid_check = shift;
return 1 if $catid_check eq $catid_current;
my @children = $DB->table('Category')->children($catid_check);
foreach (@children) {
return 1 if $_ eq $catid_current;
}
}
NOTE: code edited

Usage examples in add*.html template pages:
<%if is_child_category($ID, 123)%><%include add_form_123.html%><%endif%>
<%if is_child_category($ID, 130)%><%include add_form_130.html%><%endif%>
<%if is_child_category($ID, 131)%><%include add_form_131.html%><%endif%>

Input parameters:
1) The ID should the current category ID (hopefully it is, but if not, please correct it)
2) category we analyze if it's same with current category, or it is subcategory of it

Output:
- True if examined category id is same as current category
- True if examined category id is subcategory of current category

I did not test the global, but logically should work.
Let me know, if there will be any problems with it.

BTW: Well, could be possible to avoid the first input parameter, if really needed, but that current way was easier for me. Oh no, I'm not lazy! Just very lazy Wink

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: May 7, 2003, 8:19 AM

Edit Log: