Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to replace "get_all_categories" method?

Quote Reply
How to replace "get_all_categories" method?
How is possible to replace the "get_all_categories" method?
$DB->html()->get_all_categories()

I would like to use it in my own plugin, but the original get_all_categories is not really good for me, so I have to replace putting into my own plugin (and modify a bit), Link_add_modify.pm.

Please help me!
Suggestions, solutions are welcome!

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
What does get_all_categories return?
Quote Reply
Re: [Paul] How to replace "get_all_categories" method? In reply to
Result is a select form category list.

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
Code:
sub _get_my_cats {
#---------------------------------------------------------------
# Build a select list of cats.

my $sel = q|<select name="Categories">|;
my $sth = $DB->table('Category')->select( ['ID','Name','Full_Name'] );

while (my $row = $sth->fetchrow_hashref) {
$sel .= q|<option value="$row->{ID}">$row->{Full_Name}</option>|;
}

$sel .= q|</select>|;

return $sel;
}

Last edited by:

Paul: Aug 2, 2002, 4:22 AM
Quote Reply
Re: [Paul] How to replace "get_all_categories" method? In reply to
Duplicating "get_all_categories" method as "get_all_categories2" name would be also fine, which I can modify for myself.

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...
Quote Reply
Re: [Paul] How to replace "get_all_categories" method? In reply to
This is the original code, which should be duplicated if possible, as method with name "get_all_categories2".

Code:
sub get_all_categories {
# -------------------------------------------------------------------
# Returns a select box of all categories.
#
my $self = shift;
my $id = shift;
my $name = shift || 'CatLinks.CategoryID';
my $mult = shift || 5;
my $db = $DB->table ('Category');
my $sth = $db->select ( ['ID', 'Full_Name'] );
my %res = ();
while (my ($id, $name) = $sth->fetchrow_array) {
$res{$id} = $name;
}
return $self->select ( {
name => $name,
values => \%res,
value => $id,
multiple => $mult,
sort => sub { lc $_[0] cmp lc $_[1] }
} );
}

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
So you want to overwrite the method everytime it's called in Links SQL? In this case, you should subclass Links::Link::HTML. I wouldn't do that...

If you just want to use the method with your own code, you can place it anywhere....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
>>
If you just want to use the method with your own code, you can place it anywhere....
<<

$self won't be defined though.
Quote Reply
Re: [Paul] How to replace "get_all_categories" method? In reply to
Except if you call it as an object method....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
Yeah but thats what I mean...in order to call it as an object method you need an object.
Quote Reply
Re: [Paul] How to replace "get_all_categories" method? In reply to
Maybe he defines his own class Wink

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
>"If you just want to use the method with your own code, you can place it anywhere"
No. This is not what I want.

I would like to copy "get_all_categories" method into my plugin module (Link_add_modify.pm) using the name "get_all_categories2".
Then modify it for my needs, and use in the "_category_list" function, which is also I copied into my module, and modified for my needs.

I know isn't a usual way, but I have to keep the original codes untouched, and duplicate, what I want to change...

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: Aug 2, 2002, 5:57 AM
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
Is there a problem with this?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
The problem is, that I do not know OOP very well, still learning it.
Yes, maybe I should define my own class...

The problems:
- I don't know how to duplicate a method
- I don't know if I need to duplicate, and inherit further classes, methods, other than just "get_all_categories"
- etc... Wink

I'm almost just shoothing in the dark...
Right now I'm reading the docs, so I try to learn something about OOP, but your ideas, suggestions would help me greatly...
Thanks in advance!

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
If you just copy the functions and adapt them to your own needs, thats fine. If you are not going to call the as object methods, you can just take out the first line, i.e. my $self = shift; and it should be fine.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
Fine.
But there is another $self in the function:
return $self->select ( { ... } } );

How about this? Should I call directly? I think it is not possible.

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
The self is just the object basically, in this case its a GT::SQL::Display::HTML::Table object. You could e.g. define (as seen in Links/User/Add.pm):

my $db = $DB->table('Links');
my $html = $DB->html($db, $IN);

The $html object would be just the same thing as the $self object

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] How to replace "get_all_categories" method? In reply to
Thanks, Yogi, that worked!

Just in case somebody will need similar tricks, I post the duplicated code.
So the duplicated version (get_all_categories_duplicated) of the original (get_all_categories) method will look as following after the modification:
Code:
sub get_all_categories_duplicated {
# -------------------------------------------------------------------
# Returns a select box of all categories.

# removed the: "$self = shift;" line
my $id = shift;
my $name = shift || 'CatLinks.CategoryID';
my $mult = shift || 5;
my $db = $DB->table ('Category');
my $sth = $db->select ( ['ID', 'Full_Name'] );
my %res = ();
while (my ($id, $name) = $sth->fetchrow_array) {
$res{$id} = $name;
}
return $DB->html($db, $IN)->select ({ # the red code part in this line was $self originally
name => $name,
values => \%res,
value => $id,
multiple => $mult,
sort => sub { lc $_[0] cmp lc $_[1] }
} );
}
It should be called just: get_all_categories_duplicated(...) instead of $something->get_all_categories(...)

Thanks for Yogi & Paul for the help!

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...
Quote Reply
Re: [webmaster33] How to replace "get_all_categories" method? In reply to
I think it should be

$DB->html($DB->table('Links'), $IN)->select

instead of

$DB->html($db, $IN)->select

Ivan
-----
Iyengar Yoga Resources / GT Plugins