a55bb7b0d503411a91a1852eb252fa68a0368351
[freeside.git] / rt / lib / RT / Ticket_Vendor.pm
1 package RT::Ticket;
2 use strict;
3
4 sub SetPriority {
5   # Special case: Pass a value starting with 'R' to set priority 
6   # relative to the current level.  Used for bulk updates, though 
7   # it can be used anywhere else too.
8   my $Ticket = shift;
9   my $value = shift;
10   if ( $value =~ /^R([+-]?\d+)$/ ) {
11     $value = $1 + ($Ticket->Priority || 0);
12   }
13   $Ticket->SUPER::SetPriority($value);
14 }
15
16 =head2 Touch
17
18 Creates a Touch transaction (a null transaction).  Like Comment and 
19 Correspond but without any content.
20
21 =cut
22
23 sub Touch {
24     my $self = shift;
25     my %args = (
26         TimeTaken => 0,
27         ActivateScrips => 1,
28         CommitScrips => 1,
29         CustomFields => {},
30         @_
31     );
32     unless ( $self->CurrentUserHasRight('ModifyTicket')
33               or $self->CurrentUserHasRight('CommentOnTicket')
34               or $self->CurrentUserHasRight('ReplyToTicket')) {
35         return ( 0, $self->loc("Permission Denied"));
36     }
37     $self->_NewTransaction(
38         Type => 'Touch',
39         TimeTaken => $args{'TimeTaken'},
40         ActivateScrips => $args{'ActivateScrips'},
41         CommitScrips => $args{'CommitScrips'},
42         CustomFields => $args{'CustomFields'},
43     );
44 }
45
46
47 =head2 MissingRequiredFields {
48
49 Return all custom fields with the Required flag set for which this object
50 doesn't have any non-empty values.
51
52 =cut
53
54 sub MissingRequiredFields {
55     my $self = shift;
56     my $CustomFields = $self->CustomFields;
57     my @results;
58     while ( my $CF = $CustomFields->Next ) {
59         next if !$CF->Required;
60         if ( !length($self->FirstCustomFieldValue($CF->Id) || '') )  {
61             push @results, $CF;
62         }
63     }
64     return @results;
65 }
66
67 # Declare the 'WillResolve' field
68 sub _VendorAccessible {
69     {
70         WillResolve =>
71         {read => 1, write => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
72     },
73 };
74
75 sub WillResolveObj {
76   my $self = shift;
77
78   my $time = new RT::Date( $self->CurrentUser );
79
80   if ( my $willresolve = $self->WillResolve ) {
81     $time->Set( Format => 'sql', Value => $willresolve );
82   }
83   else {
84     $time->Set( Format => 'unix', Value => -1 );
85   }
86
87   return $time;
88 }
89
90 sub WillResolveAsString {
91   my $self = shift;
92   return $self->WillResolveObj->AsString();
93 }
94
95
96 1;