File: ArticleCFValue_Overlay.pm

package info (click to toggle)
rtfm 2.0.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 812 kB
  • ctags: 220
  • sloc: perl: 3,426; sh: 153; makefile: 144
file content (112 lines) | stat: -rw-r--r-- 2,699 bytes parent folder | download | duplicates (2)
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
# BEGIN LICENSE BLOCK
# 
#  Copyright (c) 2002-2003 Jesse Vincent <jesse@bestpractical.com>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of version 2 of the GNU General Public License 
#  as published by the Free Software Foundation.
# 
#  A copy of that license should have arrived with this
#  software, but in any event can be snarfed from www.gnu.org.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
# END LICENSE BLOCK

no warnings qw/redefine/;

use strict;

use RT::FM::ArticleCollection;

use Text::WikiFormat;
%RT::FM::WikiTags = (

);





=head2 Create { } 

    add a custom field value to an article

    takes a param hash


        Article   The id of the article we're adding to
        CustomField  The id of the custom field we're working with
        Content     The content of the custom field value we're adding
                    It's either a scalar or a b<single part> MIME object




=cut



sub Create {
    my $self = shift;
    my %args = ( Content     => '',
                 Article     => undef,
                 CustomField => undef,
                 @_ );


    # {{{ Validate the article
    my $art = RT::FM::Article->new( $self->CurrentUser );
    $art->Load( $args{'Article'} );
    unless ( $art->Id ) {
        return ( 0, $self->loc("Invalid article") );
    }

    # }}}
    # {{{ Validate the custom field
    my $cf = RT::FM::CustomField->new($self->CurrentUser);
    $cf->Load( $args{'CustomField'} );
    unless ( $cf->Id ) {
        return ( 0, $self->loc("Custom field not found") );
    }


    # }}}
# {{{ Validate the content



    unless ( defined $args{'Content'} ) {
        return ( 0, $self->loc("Content not set") );
    }

    # If this custom field is a "select from a list" 
    # make sure that we're not supplying invalid values
    unless ( $cf->ValidateValueForArticle( Value => $args{'Content'}, Article => $args{'Article'} ) ) {
        return ( 0, $self->loc("[_1] is an invalid value for custom field [_2] for article [_3]", $args{'Content'}, $cf->Name, $args{'Article'}) );
    }
    # }}}

    my $ret = $self->SUPER::Create(%args);
    return ($ret, $self->loc("Value added"));
 }


sub WikiFormattedContent {
    my $self = shift;
    my %wiki_options = (
        prefix => 'Display.html?Class='.$self->ArticleObj->ClassObj->id.'&Name=',
        extended => '1'
 );

  return Text::WikiFormat::format($self->Content , \%RT::FM::WikiTags, \%wiki_options);
    

}


1;