agent-virtualize credit card surcharge percentage, RT#72961
[freeside.git] / FS / FS / access_group.pm
1 package FS::access_group;
2 use base qw( FS::m2m_Common FS::m2name_Common FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6 use FS::access_right;
7
8 =head1 NAME
9
10 FS::access_group - Object methods for access_group records
11
12 =head1 SYNOPSIS
13
14   use FS::access_group;
15
16   $record = new FS::access_group \%hash;
17   $record = new FS::access_group { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::access_group object represents an access group.  FS::access_group inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item groupnum - primary key
35
36 =item groupname - Access group name
37
38 =back
39
40 =head1 METHODS
41
42 =over 4
43
44 =item new HASHREF
45
46 Creates a new access group.  To add the access group to the database, see L<"insert">.
47
48 Note that this stores the hash reference, not a distinct copy of the hash it
49 points to.  You can ask the object for a copy with the I<hash> method.
50
51 =cut
52
53 # the new method can be inherited from FS::Record, if a table method is defined
54
55 sub table { 'access_group'; }
56
57 =item insert
58
59 Adds this record to the database.  If there is an error, returns the error,
60 otherwise returns false.
61
62 =cut
63
64 # the insert method can be inherited from FS::Record
65
66 =item delete
67
68 Delete this record from the database.
69
70 =cut
71
72 # the delete method can be inherited from FS::Record
73
74 =item replace OLD_RECORD
75
76 Replaces the OLD_RECORD with this one in the database.  If there is an error,
77 returns the error, otherwise returns false.
78
79 =cut
80
81 # the replace method can be inherited from FS::Record
82
83 =item check
84
85 Checks all fields to make sure this is a valid access group.  If there is
86 an error, returns the error, otherwise returns false.  Called by the insert
87 and replace methods.
88
89 =cut
90
91 # the check method should currently be supplied - FS::Record contains some
92 # data checking routines
93
94 sub check {
95   my $self = shift;
96
97   my $error = 
98     $self->ut_numbern('groupnum')
99     || $self->ut_text('groupname')
100   ;
101   return $error if $error;
102
103   $self->SUPER::check;
104 }
105
106 =item access_groupagent
107
108 Returns all associated FS::access_groupagent records.
109
110 =item access_rights
111
112 Returns all associated FS::access_right records.
113
114 =cut
115
116 sub access_rights {
117   my $self = shift;
118   qsearch('access_right', { 'righttype'   => 'FS::access_group',
119                             'rightobjnum' => $self->groupnum 
120                           }
121          );
122 }
123
124 =item access_right RIGHTNAME
125
126 Returns the specified FS::access_right record.  Can be used as a boolean, to
127 test if this group has the given RIGHTNAME.
128
129 =cut
130
131 sub access_right {
132   my( $self, $name ) = @_;
133   qsearchs('access_right', { 'righttype'   => 'FS::access_group',
134                              'rightobjnum' => $self->groupnum,
135                              'rightname'   => $name,
136                            }
137           );
138 }
139
140 =back
141
142 =head1 BUGS
143
144 =head1 SEE ALSO
145
146 L<FS::Record>, schema.html from the base documentation.
147
148 =cut
149
150 1;
151