1 package FS::part_referral;
2 use base qw(FS::Record);
5 use vars qw( @ISA $setup_hack );
6 use FS::Record qw( dbh qsearch ); #qsearchs );
8 @ISA = qw( FS::Record );
13 FS::part_referral - Object methods for part_referral objects
17 use FS::part_referral;
19 $record = new FS::part_referral \%hash
20 $record = new FS::part_referral { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::part_referral represents a advertising source - where a customer heard
33 of your services. This can be used to track the effectiveness of a particular
34 piece of advertising, for example. FS::part_referral inherits from FS::Record.
35 The following fields are currently supported:
39 =item refnum - primary key (assigned automatically for new referrals)
41 =item referral - Text name of this advertising source
43 =item disabled - Disabled flag, empty or 'Y'
45 =item agentnum - Optional agentnum (see L<FS::agent>)
47 =item title - an optional external string that identifies this
48 referral source, such as an advertising campaign code.
54 These were called B<referrals> before version 1.4.0 - the name was changed
55 so as not to be confused with the new customer-to-customer referrals.
63 Creates a new advertising source. To add the referral to the database, see
68 sub table { 'part_referral'; }
72 Adds this advertising source to the database. If there is an error, returns
73 the error, otherwise returns false.
77 Currently unimplemented.
83 return "Can't (yet?) delete part_referral records";
84 #need to make sure no customers have this referral!
87 =item replace OLD_RECORD
89 Replaces OLD_RECORD with this one in the database. If there is an error,
90 returns the error, otherwise returns false.
94 Checks all fields to make sure this is a valid advertising source. If there is
95 an error, returns the error, otherwise returns false. Called by the insert and
103 my $error = $self->ut_numbern('refnum')
104 || $self->ut_text('referral')
105 || $self->ut_enum('disabled', [ '', 'Y' ] )
106 #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
107 || $self->ut_textn('title')
109 ? $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
110 : $self->ut_agentnum_acl('agentnum', 'Edit global advertising sources')
113 return $error if $error;
120 Returns the associated agent for this referral, if any, as an FS::agent object.
128 =item acl_agentnum_sql [ INCLUDE_GLOBAL_BOOL ]
130 Returns an SQL fragment for searching for part_referral records allowed by the
131 current users's agent ACLs (and "Edit global advertising sources" right).
133 Pass a true value to include global advertising sources (for example, when
134 simply using rather than editing advertising sources).
138 sub acl_agentnum_sql {
141 my $curuser = $FS::CurrentUser::CurrentUser;
142 my $sql = $curuser->agentnums_sql;
143 $sql = " ( $sql OR agentnum IS NULL ) "
144 if $curuser->access_right('Edit global advertising sources')
145 or defined($_[0]) && $_[0];
151 =item all_part_referral [ INCLUDE_GLOBAL_BOOL ]
153 Returns all part_referral records allowed by the current users's agent ACLs
154 (and "Edit global advertising sources" right).
156 Pass a true value to include global advertising sources (for example, when
157 simply using rather than editing advertising sources).
161 sub all_part_referral {
163 my $global = @_ ? shift : '';
164 my $disabled = @_ ? shift : '';
166 my $hashref = $disabled ? {} : { 'disabled' => '' };
167 my $and = $disabled ? ' WHERE ' : ' AND ';
170 'table' => 'part_referral',
171 'hashref' => $hashref,
172 'extra_sql' => $and. $self->acl_agentnum_sql($global). ' ORDER BY refnum ',
177 =item num_part_referral [ INCLUDE_GLOBAL_BOOL ]
179 Returns the number of part_referral records allowed by the current users's
180 agent ACLs (and "Edit global advertising sources" right).
184 sub num_part_referral {
187 my $sth = dbh->prepare(
188 'SELECT COUNT(*) FROM part_referral WHERE '. $self->acl_agentnum_sql(@_)
189 ) or die dbh->errstr;
190 $sth->execute() or die $sth->errstr;
191 $sth->fetchrow_arrayref->[0];
198 The delete method is unimplemented.
200 `Advertising source'. Yes, it's a sucky name. The only other ones I could
201 come up with were "Marketing channel" and "Heard Abouts" and those are
202 definately both worse.
206 L<FS::Record>, L<FS::cust_main>, schema.html from the base documentation.