summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Ticket_Vendor.pm
blob: 4a7883888bd435f5fb48ff13a08d2882d1f93498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package RT::Ticket;
use strict;

sub SetPriority {
  # Special case: Pass a value starting with 'R' to set priority 
  # relative to the current level.  Used for bulk updates, though 
  # it can be used anywhere else too.
  my $Ticket = shift;
  my $value = shift;
  if ( $value =~ /^R([+-]?\d+)$/ ) {
    $value = $1 + ($Ticket->Priority || 0);
  }
  $Ticket->SUPER::SetPriority($value);
}

=head2 Touch

Creates a Touch transaction (a null transaction).  Like Comment and 
Correspond but without any content.

=cut

sub Touch {
    my $self = shift;
    my %args = (
        TimeTaken => 0,
        ActivateScrips => 1,
        CommitScrips => 1,
        CustomFields => {},
        @_
    );
    unless ( $self->CurrentUserHasRight('ModifyTicket')
              or $self->CurrentUserHasRight('CommentOnTicket')
              or $self->CurrentUserHasRight('ReplyToTicket')) {
        return ( 0, $self->loc("Permission Denied"));
    }
    $self->_NewTransaction(
        Type => 'Touch',
        TimeTaken => $args{'TimeTaken'},
        ActivateScrips => $args{'ActivateScrips'},
        CommitScrips => $args{'CommitScrips'},
        CustomFields => $args{'CustomFields'},
    );
}


=head2 MissingRequiredFields {

Return all custom fields with the Required flag set for which this object
doesn't have any non-empty values.

=cut

sub MissingRequiredFields {
    my $self = shift;
    my $CustomFields = $self->CustomFields;
    my @results;
    while ( my $CF = $CustomFields->Next ) {
        next if !$CF->Required;
        if ( !length($self->FirstCustomFieldValue($CF->Id) || '') )  {
            push @results, $CF;
        }
    }
    return @results;
}

# Declare the 'WillResolve' field
sub _VendorAccessible {
    {
        WillResolve =>
        {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
    },
};

sub WillResolveObj {
  my $self = shift;

  my $time = new RT::Date( $self->CurrentUser );

  if ( my $willresolve = $self->WillResolve ) {
    $time->Set( Format => 'sql', Value => $willresolve );
  }
  else {
    $time->Set( Format => 'unix', Value => -1 );
  }

  return $time;
}

sub WillResolveAsString {
  my $self = shift;
  return $self->WillResolveObj->AsString();
}

=head2 IsUnreplied

Returns true if there's a Correspond or Create transaction more recent than
the Told date of this ticket (or the ticket has no Told date) and the ticket
is not rejected or resolved.

=cut

sub IsUnreplied {
  my $self = shift;
  return 0 if $self->Status eq 'resolved'
           or $self->Status eq 'rejected';

  my $Told = $self->Told || '1970-01-01';
  my $Txns = $self->Transactions;
  $Txns->Limit(FIELD => 'Type',
               OPERATOR => 'IN',
               VALUE => [ 'Correspond', 'Create' ]);
  $Txns->Limit(FIELD => 'Created',
               OPERATOR => '>',
               VALUE => $Told);
  $Txns->Count ? 1 : 0;
}

1;