blib/lib/Labyrinth/Plugin/MP3s.pm

filter: Statementstmt 34.9% 44 / 126 Branchbran 5.2% 4 / 76 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.1% 8 / 21 Podpod 100% 13 / 13 totaltotal 28.6% 69 / 241 CC 43 SCAR 38.5
CC
43
Cov
23%
Save
110.0
CatSave
90.0
Admin
72.0
CRAP 47.1
↑ Summary
1 package Labyrinth::Plugin::MP3s;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 $VERSION = '1.01';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::MP3s - MP3 plugin handler for Labyrinth
12  
13 =head1 DESCRIPTION
14  
15 Contains all the MP3 management handling functionality for the Labyrinth Web
16 Framework.
17  
18 =cut
19  
20 # -------------------------------------
21 # Library Modules
22  
23 5 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use Labyrinth::Variables;
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 5 my %cat_fields = (
37 mp3catid => { type => 0, html => 0 },
38 category => { type => 1, html => 1 },
39 );
40  
41 5 my (@cat_mandatory,@cat_allfields);
42 5 for(keys %cat_fields) {
43 10 ▶ push @cat_mandatory, $_ if($cat_fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $cat_fields{$_}{"type"} 5 5 10
44 10 push @cat_allfields, $_;
45 }
46  
47 5 my %fields = (
48 mp3id => { type => 0, html => 0 },
49 mp3catid => { type => 1, html => 1 },
50 orderno => { type => 1, html => 1 },
51 source => { type => 1, html => 1 },
52 tracks => { type => 0, html => 2 },
53 notes => { type => 0, html => 2 },
54 publish => { type => 1, html => 1 },
55 );
56  
57 5 my (@mandatory,@allfields);
58 5 for(keys %fields) {
59 35 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 20 15 35
60 35 push @allfields, $_;
61 }
62  
63 5 my @savefields = qw(mp3catid orderno source tracks notes publish);
64 5 my $INDEXKEY = 'mp3id';
65 5 my $ALLSQL = 'AllMP3s';
66 5 my $SAVESQL = 'SaveMP3';
67 5 my $ADDSQL = 'AddMP3';
68 5 my $GETSQL = 'GetMP3ByID';
69 5 my $LEVEL = ADMIN;
70  
71 5 my %adddata = (
72 mp3id => 0,
73 mp3catid => 1,
74 orderno => 999,
75 source => '',
76 tracks => '',
77 notes => '',
78 publish => 1,
79 );
80  
81 # -------------------------------------
82 # The Subs
83  
84 =head1 PUBLIC INTERFACE METHODS
85  
86 =over 4
87  
88 =item * List
89  
90 Lists all the publicly visable categories and MP3s.
91  
92 =back
93  
94 =cut
95  
96 0 ▶sub List {
Subroutine List: not called CC=1 SCAR=6.9
Pod documented
97 # get list for current realm
98 0 my @cats = $dbi->GetQuery('hash','GetMP3Cats');
99 0 $tvars{cats} = \@cats;
100 0 my @rows = $dbi->GetQuery('hash','GetMP3s');
101 0 $tvars{mp3s} = \@rows;
102 }
103  
104 =head1 ADMIN INTERFACE METHODS
105  
106 =head2 MP3s Methods
107  
108 =over 4
109  
110 =item * Admin
111  
112 List, and manages, all the MP3s available within the system.
113  
114 =item * Add
115  
116 Add a new MP3.
117  
118 =item * Edit
119  
120 Edit details of an existing MP3.
121  
122 =item * ReOrder
123  
124 Re-order MP3s within a category.
125  
126 =item * Promote
127  
128 Publish, Archive, etc MP3s.
129  
130 =item * Delete
131  
132 Delete an MP3 from the system.
133  
134 =item * Save
135  
136 Validates the fields returned from the edit page, and either saves or inserts
137 the record into the database.
138  
139 It should be noted that the actual media file upload data is saved in the
140 'images' table. This is for legacy reasons and the table *should* have been
141 renamed, perhaps to 'media', but I've never gotten around to it.
142  
143 =back
144  
145 =cut
146  
147 0 ▶sub Admin {
Subroutine Admin: not called CC=8 SCAR=42.8
Pod documented
148 0 ▶ return unless(AccessUser($LEVEL));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
149 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"}) 0 0 0
150 0 ▶ if($cgiparams{doaction} eq 'ReOrder' ) { ReOrder(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"} eq "ReOrder") 0 0 0
151 0 ▶ if($cgiparams{doaction} eq 'Promote' ) { Promote(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"} eq "Promote") 0 0 0
152 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"} eq "Delete") 0 0 0
153 }
154 0 my @rows = $dbi->GetQuery('hash','AllMP3s');
155 0 for my $row (@rows) {
156 0 $row->{publish} = PublishState($row->{publish});
157 }
158 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
159 }
160  
161 0 ▶sub Add {
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
162 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
163 0 $tvars{data}{ddcats} = CatSelect();
164 0 $tvars{data}{ddpublish} = PublishSelect($tvars{data}{publish},1);
165 }
166  
167 0 ▶sub Edit {
Subroutine Edit: not called CC=3 SCAR=24.8
Pod documented
168 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
169 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
170 0 $tvars{data}{ddcats} = CatSelect($tvars{data}{mp3catid});
171 0 $tvars{data}{ddpublish} = PublishSelect($tvars{data}{publish},1);
172 }
173  
174 0 ▶sub ReOrder {
Subroutine ReOrder: not called CC=3 SCAR=24.8
Pod documented
175 0 my @rows = $dbi->GetQuery('hash',$ALLSQL);
176 0 for my $row (@rows) {
177 0 ▶ next if($cgiparams{"ORDER$row->{mp3id}"} == $row->{orderno});
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::MP3s::cgiparams{qq[ORDER$row->{"mp3id"}]} == $row->{"orderno"} 0 0 0
178 0 $dbi->DoQuery('ReOrderMP3s',$cgiparams{"ORDER$row->{mp3id}"},$row->{mp3id});
179 }
180 }
181  
182 0 ▶sub Promote {
Subroutine Promote: not called CC=5 SCAR=34.0
Pod documented
183 0 my @ids = CGIArray('LISTED');
184 0 ▶ next unless(@ids);
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
185  
186 0 my @rows = $dbi->GetQuery('hash',$ALLSQL);
187 0 my %ids = map {$_->{mp3id} => $_->{publish}} @rows;
188  
189 0 for my $id (@ids) {
190 0 ▶ next unless(defined $ids{$id} && $ids{$id} < 4);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ids{$id} and $ids{$id} < 4 0 0 0
Condition0%0/3
defined $ids{$id} and $ids{$id} < 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ids{$id} and $ids{$id} < 4
defined $ids{$id} $ids{$id} < 4
Truth table0%0/3
A and B
A= defined $ids{$id}B= $ids{$id} < 4
ABresult
0X0
100
111
191 0 $dbi->DoQuery('PromoteMP3s',($ids{$id} + 1),$id);
192 }
193 }
194  
195 0 ▶sub Delete {
Subroutine Delete: not called CC=2 SCAR=17.9
Pod documented
196 0 my @ids = CGIArray('LISTED');
197 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
198 0 $dbi->DoQuery('DeleteMP3s',{ids=>join(",",@ids)});
199 }
200  
201 0 ▶sub Save {
Subroutine Save: not called CC=10 SCAR=47.0
Pod documented
202 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
203 0 ▶ return unless AuthorCheck($GETSQL,$INDEXKEY,$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck($GETSQL, $INDEXKEY, $LEVEL) 0 0 0
204
205 0 for(keys %fields) {
206 0 ▶ if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
elsif ($fields{$_}{'html'} == 3) { } 0 0 0
207 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
208 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanMP3s($cgiparams{$_}) }
209 }
210 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
211
212 # TODO upload Media file
213 0 ▶ if($cgiparams{mp3file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"mp3file"}) 0 0 0
214 0 my ($imageid,$imagelink) = SaveImageFile(
215 param => "FILEUPLOAD",
216 stock => 'mp3s'
217 );
218  
219 # TODO
220 }
221  
222 0 my @fields = map {$tvars{data}->{$_}} @savefields;
223 0 ▶ if( $cgiparams{$INDEXKEY}) { $dbi->DoQuery($SAVESQL,@fields,$cgiparams{$INDEXKEY}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{$INDEXKEY}) { } 0 0 0
224 0 else { $cgiparams{$INDEXKEY} = $dbi->IDQuery( $ADDSQL,@fields); }
225  
226 0 $tvars{thanks} = 1;
227 }
228  
229 =head2 Category Admin
230  
231 =over 4
232  
233 =item * CatAdmin
234  
235 List, and manages, all the MP3 categories within the system.
236  
237 =item * CatEdit
238  
239 Edit details of an existing MP3 category.
240  
241 =item * CatDelete
242  
243 Delete an MP3 category from the system.
244  
245 =item * CatSave
246  
247 Validates the fields returned from the edit page, and either saves or inserts
248 the record into the database.
249  
250 Note that there is no CatAdd, as this is purely a blank form, submitted to
251 CatSave method.
252  
253 =item * CatSelect
254  
255 Provides a drop down list of the currently available MP3 categories.
256 =back
257  
258 =cut
259  
260 0 ▶sub CatAdmin {
Subroutine CatAdmin: not called CC=5 SCAR=34.0
Pod documented
261 0 ▶ return unless(AccessUser($LEVEL));
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
262 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"}) 0 0 0
263 0 ▶ if($cgiparams{doaction} eq 'Delete' ) { CatDelete(); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{"doaction"} eq "Delete") 0 0 0
264 }
265 0 my @rows = $dbi->GetQuery('hash','GetAllMP3Cats');
266 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
267 }
268  
269 0 ▶sub CatEdit {
Subroutine CatEdit: not called CC=3 SCAR=24.8
Pod documented
270 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
271 0 ▶ return unless AuthorCheck('GetMP3CatByID','mp3catid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetMP3CatByID", "mp3catid", $LEVEL) 0 0 0
272 }
273  
274 0 ▶sub CatDelete {
Subroutine CatDelete: not called CC=3 SCAR=24.8
Pod documented
275 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
276 0 my @ids = CGIArray('LISTED');
277 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
278 0 $dbi->DoQuery('DeleteMP3Cats',{ids=>join(",",@ids)});
279 0 $dbi->DoQuery('DeleteMP3Categories',{ids=>join(",",@ids)});
280 }
281  
282 0 ▶sub CatSave {
Subroutine CatSave: not called CC=9 SCAR=45.0
Pod documented
283 0 ▶ return unless AccessUser($LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser($LEVEL) 0 0 0
284 0 ▶ return unless AuthorCheck('GetMP3CatByID','mp3catid',$LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
unless AuthorCheck("GetMP3CatByID", "mp3catid", $LEVEL) 0 0 0
285 0 for(keys %cat_fields) {
286 0 ▶ if($cat_fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($cat_fields{$_}{'html'} == 1) { } 0 0 0
elsif ($cat_fields{$_}{'html'} == 2) { } 0 0 0
elsif ($cat_fields{$_}{'html'} == 3) { } 0 0 0
287 0 elsif($cat_fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
288 0 elsif($cat_fields{$_}->{html} == 3) { $cgiparams{$_} = CleanMP3s($cgiparams{$_}) }
289 }
290 0 ▶ return if FieldCheck(\@cat_allfields,\@cat_mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@cat_allfields, \@cat_mandatory) 0 0 0
291 0 ▶ if($cgiparams{mp3catid}) { $dbi->DoQuery('SaveMP3Category',$tvars{data}->{category},$cgiparams{mp3catid}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::MP3s::cgiparams{'mp3catid'}) { } 0 0 0
292 0 else { $cgiparams{mp3catid} = $dbi->IDQuery('AddMP3Category',$tvars{data}->{category}); }
293 0 $tvars{thanks} = 1;
294 }
295  
296 0 ▶sub CatSelect {
Subroutine CatSelect: not called CC=1 SCAR=6.9
Pod documented
297 0 my $opt = shift;
298 0 my @rows = $dbi->GetQuery('hash','GetAllMP3Cats');
299 0 DropDownRows($opt,'mp3catid','mp3catid','category',@rows);
300 }
301  
302 5 1;
303  
304 __END__
↑ Summary