Review/Retailers.pm

filter: Statementstmt 55.3% 31 / 56 Branchbran 6.6% 2 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 100% 6 / 6 totaltotal 44.3% 47 / 106 CC 16 SCAR 30.9
CC
16
Cov
38%
Save
56.0
Admin
30.0
Edit
12.0
CRAP 21.9
« Review.pm ↑ Summary Review/Types.pm »
1 package Labyrinth::Plugin::Review::Retailers;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $VERSION = '1.00';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::Review::Retailers - Retailers plugin for the Labyrinth framework
12  
13 =head1 DESCRIPTION
14  
15 Contains all the functionality for managing retailers used in reviews.
16  
17 =cut
18  
19 # -------------------------------------
20 # Library Modules
21  
22 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # -------------------------------------
31 # Variables
32  
33 # type: 0 = optional, 1 = mandatory
34 # html: 0 = none, 1 = text, 2 = textarea
35  
36 4 my %fields = (
37 retailerid => { type => 0, html => 0 },
38 retailer => { type => 1, html => 1 },
39 retailerlink => { type => 1, html => 1 },
40 );
41  
42 4 my (@mandatory,@allfields);
43 4 for(keys %fields) {
44 12 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 8 4 12
45 12 push @allfields, $_;
46 }
47  
48 # -------------------------------------
49 # The Subs
50  
51 =head1 ADMIN INTERFACE METHODS
52  
53 =over 4
54  
55 =item * Access
56  
57 Check default access to the Admin methods
58  
59 =item * Admin
60  
61 List retailers for administration purposes.
62  
63 =item * Add
64  
65 Add a retailer.
66  
67 =item * Edit
68  
69 Edit a retailer.
70  
71 =item * Save
72  
73 Save a retailer.
74  
75 =item * Delete
76  
77 Delete one or more retailers.
78  
79 =back
80  
81 =cut
82  
83 0 ▶sub Access { Authorised(PUBLISHER) }
Subroutine Access: not called CC=1 SCAR=6.9
Pod documented
84  
85 sub Admin {
86 0 ▶ return unless AccessUser(PUBLISHER);
Subroutine Admin: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(3) 0 0 0
87  
88 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Review::Retailers::cgiparams{"doaction"}) 0 0 0
89 0 ▶ if($cgiparams{doaction} eq 'Delete') { Delete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Review::Retailers::cgiparams{"doaction"} eq "Delete") 0 0 0
90 }
91  
92 0 my @rows = $dbi->GetQuery('hash','AllRetailers');
93 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
94 }
95  
96 sub Add {
97 0 ▶ return unless AccessUser(PUBLISHER);
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(3) 0 0 0
98 }
99  
100 sub Edit {
101 0 ▶ return unless AccessUser(PUBLISHER);
Subroutine Edit: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(3) 0 0 0
102 0 ▶ return unless AuthorCheck('GetRetailerByID','retailerid',PUBLISHER);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetRetailerByID", "retailerid", 3) 0 0 0
103 }
104  
105 sub Save {
106 0 ▶ return unless AuthorCheck('GetRetailerByID','retailerid',PUBLISHER);
Subroutine Save: not called CC=7 SCAR=40.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetRetailerByID", "retailerid", 3) 0 0 0
107 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
108  
109 0 for(keys %fields) {
110 0 ▶ if($fields{$_}->{html} == 1) { $tvars{data}->{$_} = CleanHTML($tvars{data}->{$_}) }
Branch: 2 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
111 0 elsif($fields{$_}->{html} == 2) { $tvars{data}->{$_} = CleanTags($tvars{data}->{$_}) }
112 }
113  
114 my @fields = (
115 $tvars{data}->{retailer},
116 $tvars{data}->{retailerlink}
117 0 );
118  
119 # store review details
120 0 ▶ if($tvars{data}->{retailerid})
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Review::Retailers::tvars{'data'}{'retailerid'}) { } 0 0 0
121 0 { $dbi->DoQuery('SaveRetailer',@fields,$tvars{data}->{retailerid}); }
122 0 else { $cgiparams{retailerid} = $dbi->IDQuery('AddRetailer',@fields); }
123  
124 0 $tvars{thanks} = 1;
125 }
126  
127 sub Delete {
128 0 ▶ return unless AccessUser(PUBLISHER);
Subroutine Delete: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(3) 0 0 0
129 0 my @ids = CGIArray('LISTED');
130 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
131  
132 0 $dbi->DoQuery('DeleteRetailers',{ ids => join(',',@ids) });
133 }
134  
135 4 1;
136  
137 __END__
138  
139 =head1 SEE ALSO
140  
141 Labyrinth
142  
143 =head1 AUTHOR
144  
145 Barbie, <barbie@missbarbell.co.uk> for
146 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
147  
148 =head1 COPYRIGHT & LICENSE
149  
150 Copyright (C) 2002-2014 Barbie for Miss Barbell Productions
151 All Rights Reserved.
152  
153 This module is free software; you can redistribute it and/or
154 modify it under the Artistic License 2.0.
155  
156 =cut
« Review.pm ↑ Summary Review/Types.pm »