use strict;
use vars qw( @ISA );
-use FS::Record qw( qsearch );
+use FS::Record qw( qsearch dbh );
+use FS::m2m_Common;
use FS::agent;
use FS::type_pkgs;
-@ISA = qw( FS::Record );
+@ISA = qw( FS::m2m_Common FS::Record );
=head1 NAME
sub pkgpart_hashref {
my $self = shift;
my %pkgpart;
- #$pkgpart{$_}++ foreach $self->pkgpart;
- # not compatible w/5.004_04 (fixed in 5.004_05)
- foreach ( $self->pkgpart ) { $pkgpart{$_}++; }
+ $pkgpart{$_}++ foreach $self->pkgpart;
\%pkgpart;
}
qsearch('type_pkgs', { 'typenum' => $self->typenum } );
}
+=item type_pkgs_enabled
+
+Returns all FS::type_pkg objects (see L<FS::type_pkgs>) that link to enabled
+package definitions (see L<FS::part_pkg>).
+
+An additional strange feature is that the returned type_pkg objects also have
+all fields of the associated part_pkg object.
+
+=cut
+
+sub type_pkgs_enabled {
+ my $self = shift;
+ qsearch({
+ 'table' => 'type_pkgs',
+ 'addl_from' => 'JOIN part_pkg USING ( pkgpart )',
+ 'hashref' => { 'typenum' => $self->typenum },
+ 'extra_sql' => " AND ( disabled = '' OR disabled IS NULL )".
+ " ORDER BY pkg",
+ });
+}
+
=item pkgpart
Returns the pkgpart of all package definitions (see L<FS::part_pkg>) for this
sub pkgpart {
my $self = shift;
- map $_->pkgpart, $self->type_pkgs;
+
+ #map $_->pkgpart, $self->type_pkgs;
+
+ my $sql = 'SELECT pkgpart FROM type_pkgs WHERE typenum = ?';
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute( $self->typenum ) or die $sth->errstr;
+ map $_->[0], @{ $sth->fetchall_arrayref };
}
=back
-=head1 VERSION
+=head1 BUGS
-$Id: agent_type.pm,v 1.2 2003-08-05 00:20:40 khoff Exp $
+type_pkgs_enabled should order itself by something (pkg?)
-=head1 BUGS
+type_pkgs_enabled should populate something that caches for the part_pkg method
+rather than add fields to this object, right? In fact we need a "poop" object
+framework that does that automatically for any joined search at some point....
+right?
=head1 SEE ALSO