1 package FS::agent_type;
5 use FS::Record qw( qsearch );
10 @ISA = qw( FS::m2m_Common FS::Record );
14 FS::agent_type - Object methods for agent_type records
20 $record = new FS::agent_type \%hash;
21 $record = new FS::agent_type { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
31 $hashref = $record->pkgpart_hashref;
32 #may purchase $pkgpart if $hashref->{$pkgpart};
34 @type_pkgs = $record->type_pkgs;
36 @pkgparts = $record->pkgpart;
40 An FS::agent_type object represents an agent type. Every agent (see
41 L<FS::agent>) has an agent type. Agent types define which packages (see
42 L<FS::part_pkg>) may be purchased by customers (see L<FS::cust_main>), via
43 FS::type_pkgs records (see L<FS::type_pkgs>). FS::agent_type inherits from
44 FS::Record. The following fields are currently supported:
48 =item typenum - primary key (assigned automatically for new agent types)
50 =item atype - Text name of this agent type
60 Creates a new agent type. To add the agent type to the database, see
65 sub table { 'agent_type'; }
69 Adds this agent type to the database. If there is an error, returns the error,
70 otherwise returns false.
74 Deletes this agent type from the database. Only agent types with no agents
75 can be deleted. If there is an error, returns the error, otherwise returns
83 return "Can't delete an agent_type with agents!"
84 if qsearch( 'agent', { 'typenum' => $self->typenum } );
89 =item replace OLD_RECORD
91 Replaces OLD_RECORD with this one in the database. If there is an error,
92 returns the error, otherwise returns false.
96 Checks all fields to make sure this is a valid agent type. If there is an
97 error, returns the error, otherwise returns false. Called by the insert and
105 $self->ut_numbern('typenum')
106 or $self->ut_text('atype')
107 or $self->SUPER::check;
111 =item pkgpart_hashref
113 Returns a hash reference. The keys of the hash are pkgparts. The value is
114 true iff this agent may purchase the specified package definition. See
119 sub pkgpart_hashref {
122 #$pkgpart{$_}++ foreach $self->pkgpart;
123 # not compatible w/5.004_04 (fixed in 5.004_05)
124 foreach ( $self->pkgpart ) { $pkgpart{$_}++; }
130 Returns all FS::type_pkgs objects (see L<FS::type_pkgs>) for this agent type.
136 qsearch('type_pkgs', { 'typenum' => $self->typenum } );
139 =item type_pkgs_enabled
141 Returns all FS::type_pkg objects (see L<FS::type_pkgs>) that link to enabled
142 package definitions (see L<FS::part_pkg>).
144 An additional strange feature is that the returned type_pkg objects also have
145 all fields of the associated part_pkg object.
149 sub type_pkgs_enabled {
152 'table' => 'type_pkgs',
153 'addl_from' => 'JOIN part_pkg USING ( pkgpart )',
154 'hashref' => { 'typenum' => $self->typenum },
155 'extra_sql' => " AND ( disabled = '' OR disabled IS NULL )".
162 Returns the pkgpart of all package definitions (see L<FS::part_pkg>) for this
169 map $_->pkgpart, $self->type_pkgs;
176 type_pkgs_enabled should order itself by something (pkg?)
178 type_pkgs_enabled should populate something that caches for the part_pkg method
179 rather than add fields to this object, right? In fact we need a "poop" object
180 framework that does that automatically for any joined search at some point....
185 L<FS::Record>, L<FS::agent>, L<FS::type_pkgs>, L<FS::cust_main>,
186 L<FS::part_pkg>, schema.html from the base documentation.