X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fagent_type.pm;h=e0f749500f578d72e2fdc464a80393624e591e78;hp=968b3b72e942fbef198908a313a61cb9e8112fda;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hpb=673b9a458d9138523026963df6fa3b4683e09bae diff --git a/FS/FS/agent_type.pm b/FS/FS/agent_type.pm index 968b3b72e..e0f749500 100644 --- a/FS/FS/agent_type.pm +++ b/FS/FS/agent_type.pm @@ -2,11 +2,12 @@ package FS::agent_type; 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 @@ -44,9 +45,17 @@ FS::Record. The following fields are currently supported: =over 4 -=item typenum - primary key (assigned automatically for new agent types) +=item typenum -=item atype - Text name of this agent type +primary key (assigned automatically for new agent types) + +=item atype + +Text name of this agent type + +=item disabled + +Disabled flag, empty or 'Y' =back @@ -102,8 +111,9 @@ sub check { my $self = shift; $self->ut_numbern('typenum') - or $self->ut_text('atype') - or $self->SUPER::check; + || $self->ut_text('atype') + || $self->ut_enum('disabled', [ '', 'Y' ] ) + || $self->SUPER::check; } @@ -118,9 +128,7 @@ L. 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; } @@ -135,6 +143,27 @@ sub type_pkgs { qsearch('type_pkgs', { 'typenum' => $self->typenum } ); } +=item type_pkgs_enabled + +Returns all FS::type_pkg objects (see L) that link to enabled +package definitions (see L). + +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) for this @@ -144,13 +173,26 @@ agent type. 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 BUGS +type_pkgs_enabled should order itself by something (pkg?) + +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 L, L, L, L,