~ubuntu-branches/ubuntu/oneiric/bugzilla/oneiric

« back to all changes in this revision

Viewing changes to Bugzilla/Milestone.pm

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Bossek
  • Date: 2008-06-27 22:34:34 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080627223434-0ib57vstn43bb4a3
Tags: 3.0.4.1-1
* Update of French, Russian and German translations. (closes: #488251)
* Added Bulgarian and Belarusian translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- Mode: perl; indent-tabs-mode: nil -*-
2
 
#
3
 
# The contents of this file are subject to the Mozilla Public
4
 
# License Version 1.1 (the "License"); you may not use this file
5
 
# except in compliance with the License. You may obtain a copy of
6
 
# the License at http://www.mozilla.org/MPL/
7
 
#
8
 
# Software distributed under the License is distributed on an "AS
9
 
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
 
# implied. See the License for the specific language governing
11
 
# rights and limitations under the License.
12
 
#
13
 
# The Original Code is the Bugzilla Bug Tracking System.
14
 
#
15
 
# Contributor(s): Tiago R. Mello <timello@async.com.br>
16
 
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
17
 
 
18
 
use strict;
19
 
 
20
 
package Bugzilla::Milestone;
21
 
 
22
 
use base qw(Bugzilla::Object);
23
 
 
24
 
use Bugzilla::Util;
25
 
use Bugzilla::Error;
26
 
 
27
 
################################
28
 
#####    Initialization    #####
29
 
################################
30
 
 
31
 
use constant DEFAULT_SORTKEY => 0;
32
 
 
33
 
use constant DB_TABLE => 'milestones';
34
 
 
35
 
use constant DB_COLUMNS => qw(
36
 
    id
37
 
    value
38
 
    product_id
39
 
    sortkey
40
 
);
41
 
 
42
 
use constant NAME_FIELD => 'value';
43
 
use constant LIST_ORDER => 'sortkey, value';
44
 
 
45
 
sub new {
46
 
    my $class = shift;
47
 
    my $param = shift;
48
 
    my $dbh = Bugzilla->dbh;
49
 
 
50
 
    my $product;
51
 
    if (ref $param) {
52
 
        $product = $param->{product};
53
 
        my $name = $param->{name};
54
 
        if (!defined $product) {
55
 
            ThrowCodeError('bad_arg',
56
 
                {argument => 'product',
57
 
                 function => "${class}::new"});
58
 
        }
59
 
        if (!defined $name) {
60
 
            ThrowCodeError('bad_arg',
61
 
                {argument => 'name',
62
 
                 function => "${class}::new"});
63
 
        }
64
 
 
65
 
        my $condition = 'product_id = ? AND value = ?';
66
 
        my @values = ($product->id, $name);
67
 
        $param = { condition => $condition, values => \@values };
68
 
    }
69
 
 
70
 
    unshift @_, $param;
71
 
    return $class->SUPER::new(@_);
72
 
}
73
 
 
74
 
sub bug_count {
75
 
    my $self = shift;
76
 
    my $dbh = Bugzilla->dbh;
77
 
 
78
 
    if (!defined $self->{'bug_count'}) {
79
 
        $self->{'bug_count'} = $dbh->selectrow_array(q{
80
 
            SELECT COUNT(*) FROM bugs
81
 
            WHERE product_id = ? AND target_milestone = ?},
82
 
            undef, $self->product_id, $self->name) || 0;
83
 
    }
84
 
    return $self->{'bug_count'};
85
 
}
86
 
 
87
 
################################
88
 
#####      Accessors      ######
89
 
################################
90
 
 
91
 
sub name       { return $_[0]->{'value'};      }
92
 
sub product_id { return $_[0]->{'product_id'}; }
93
 
sub sortkey    { return $_[0]->{'sortkey'};    }
94
 
 
95
 
################################
96
 
#####     Subroutines      #####
97
 
################################
98
 
 
99
 
sub check_milestone {
100
 
    my ($product, $milestone_name) = @_;
101
 
 
102
 
    unless ($milestone_name) {
103
 
        ThrowUserError('milestone_not_specified');
104
 
    }
105
 
 
106
 
    my $milestone = new Bugzilla::Milestone({ product => $product,
107
 
                                              name    => $milestone_name });
108
 
    unless ($milestone) {
109
 
        ThrowUserError('milestone_not_valid',
110
 
                       {'product' => $product->name,
111
 
                        'milestone' => $milestone_name});
112
 
    }
113
 
    return $milestone;
114
 
}
115
 
 
116
 
sub check_sort_key {
117
 
    my ($milestone_name, $sortkey) = @_;
118
 
    # Keep a copy in case detaint_signed() clears the sortkey
119
 
    my $stored_sortkey = $sortkey;
120
 
 
121
 
    if (!detaint_signed($sortkey) || $sortkey < -32768
122
 
        || $sortkey > 32767) {
123
 
        ThrowUserError('milestone_sortkey_invalid',
124
 
                       {'name' => $milestone_name,
125
 
                        'sortkey' => $stored_sortkey});
126
 
    }
127
 
    return $sortkey;
128
 
}
129
 
 
130
 
1;
131
 
 
132
 
__END__
133
 
 
134
 
=head1 NAME
135
 
 
136
 
Bugzilla::Milestone - Bugzilla product milestone class.
137
 
 
138
 
=head1 SYNOPSIS
139
 
 
140
 
    use Bugzilla::Milestone;
141
 
 
142
 
    my $milestone = new Bugzilla::Milestone(
143
 
        { product => $product, name => 'milestone_value' });
144
 
 
145
 
    my $product_id = $milestone->product_id;
146
 
    my $value = $milestone->value;
147
 
 
148
 
    my $milestone = $hash_ref->{'milestone_value'};
149
 
 
150
 
=head1 DESCRIPTION
151
 
 
152
 
Milestone.pm represents a Product Milestone object.
153
 
 
154
 
=head1 METHODS
155
 
 
156
 
=over
157
 
 
158
 
=item C<new($product_id, $value)>
159
 
 
160
 
 Description: The constructor is used to load an existing milestone
161
 
              by passing a product id and a milestone value.
162
 
 
163
 
 Params:      $product_id - Integer with a Bugzilla product id.
164
 
              $value - String with a milestone value.
165
 
 
166
 
 Returns:     A Bugzilla::Milestone object.
167
 
 
168
 
=item C<bug_count()>
169
 
 
170
 
 Description: Returns the total of bugs that belong to the milestone.
171
 
 
172
 
 Params:      none.
173
 
 
174
 
 Returns:     Integer with the number of bugs.
175
 
 
176
 
=back
177
 
 
178
 
=head1 SUBROUTINES
179
 
 
180
 
=over
181
 
 
182
 
=item C<check_milestone($product, $milestone_name)>
183
 
 
184
 
 Description: Checks if a milestone name was passed in
185
 
              and if it is a valid milestone.
186
 
 
187
 
 Params:      $product - Bugzilla::Product object.
188
 
              $milestone_name - String with a milestone name.
189
 
 
190
 
 Returns:     Bugzilla::Milestone object.
191
 
 
192
 
=back
193
 
 
194
 
=cut