File Coverage

blib/lib/Labyrinth/Plugin/Release.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Labyrinth::Plugin::Release;
2              
3 5     5   75831 use warnings;
  5         9  
  5         188  
4 5     5   22 use strict;
  5         5  
  5         156  
5              
6 5     5   18 use vars qw($VERSION);
  5         10  
  5         276  
7              
8             $VERSION = '0.03';
9              
10             =head1 NAME
11              
12             Labyrinth::Plugin::Release - Release plugin handler for Labyrinth
13              
14             =head1 DESCRIPTION
15              
16             Contains all the release handling functionality for the Labyrinth Web
17             Framework.
18              
19             =cut
20              
21             # -------------------------------------
22             # Library Modules
23              
24 5     5   19 use base qw(Labyrinth::Plugin::Articles);
  5         12  
  5         4428  
25              
26             use Clone qw(clone);
27              
28             use Labyrinth::Audit;
29             use Labyrinth::DBUtils;
30             use Labyrinth::DTUtils;
31             use Labyrinth::Media;
32             use Labyrinth::MLUtils;
33             use Labyrinth::Support;
34             use Labyrinth::Users;
35             use Labyrinth::Variables;
36              
37             # -------------------------------------
38             # Variables
39              
40             # type: 0 = optional, 1 = mandatory
41             # html: 0 = none, 1 = text, 2 = textarea
42              
43             my %fields = (
44             articleid => { type => 0, html => 0 },
45             releaseid => { type => 0, html => 0 },
46             title => { type => 1, html => 1 },
47             quickname => { type => 1, html => 0 },
48             reldate => { type => 1, html => 0 },
49             publish => { type => 1, html => 0 },
50             reltypeid => { type => 1, html => 0 },
51             );
52              
53             my (@mandatory,@allfields);
54             for(keys %fields) {
55             push @mandatory, $_ if($fields{$_}->{type});
56             push @allfields, $_;
57             }
58              
59             my $ALLSQL = 'AllReleases';
60             my $SECTIONID = 8;
61             my $SECTION_ALBUM = 8;
62             my $SECTION_LYRIC = 7;
63             my $SECTION_PROFILE = 5;
64             my $LEVEL = ADMIN;
65              
66             # -------------------------------------
67             # The Subs
68              
69             =head1 PUBLIC INTERFACE METHODS
70              
71             =over 4
72              
73             =item * List
74              
75             Provides basic information for each published release.
76              
77             =item * Item
78              
79             Retrieves the basic release data, liner notes and a list of the lyrics,
80             profiles and mp3s associated with the release.
81              
82             =item * Lyrics
83              
84             Calls Item(), and provides the full content of each lyric of a release.
85              
86             =item * Profiles
87              
88             Calls Item(), and provides the full content of each profile of a release.
89              
90             =back
91              
92             =cut
93              
94             sub List {
95             my $self = shift;
96             my @releases;
97              
98             my @rows = $dbi->GetQuery('hash','ListReleases');
99             for my $row (@rows) {
100             my @release = $dbi->GetQuery('hash','GetReleaseByID',$row->{releaseid});
101             my @article = $dbi->GetQuery('hash','GetArticleByName',$row->{quickname});
102             $release[0]->{$_} = $article[0]->{$_} for(qw(link tag));
103             my @formats = $dbi->GetQuery('hash','ListFormats',$row->{releaseid});
104             $release[0]->{formats} = \@formats if(@formats);
105              
106             my @lyrics = $dbi->GetQuery('hash','ListLyrics',$row->{releaseid});
107             $release[0]->{lyrics} = \@lyrics if(@lyrics);
108             my @profiles = $dbi->GetQuery('hash','ListProfiles',$row->{releaseid});
109             $release[0]->{profiles} = \@profiles if(@profiles);
110             my @mp3s = $dbi->GetQuery('hash','ListMp3s',$row->{releaseid});
111             $release[0]->{mp3s} = \@mp3s if(@mp3s);
112            
113             $release[0]->{postyear} = formatDate(1,$release[0]->{releasedate});
114              
115             $cgiparams{articleid} = $release[0]->{articleid};
116             $cgiparams{sectionid} = $SECTION_ALBUM;
117             $self->SUPER::Item;
118             $release[0]->{data} = clone($tvars{articles}{$tvars{primary}});
119              
120             push @releases, $release[0];
121             }
122              
123             my @types = $dbi->GetQuery('hash','ListAllTypes');
124              
125             $tvars{types} = \@types if(@types);
126             $tvars{releases} = \@releases if(@releases);
127             }
128              
129             sub Item {
130             my @release = $dbi->GetQuery('hash','GetReleaseByID',$cgiparams{releaseid});
131             if(@release) {
132             my @lyrics = $dbi->GetQuery('hash','ListLyrics',$cgiparams{releaseid});
133             $release[0]->{lyrics} = \@lyrics if(@lyrics);
134             my @profiles = $dbi->GetQuery('hash','ListProfiles',$cgiparams{releaseid});
135             $release[0]->{profiles} = \@profiles if(@profiles);
136             my @mp3s = $dbi->GetQuery('hash','ListMp3s',$cgiparams{releaseid});
137             $release[0]->{mp3s} = \@mp3s if(@mp3s);
138              
139             $release[0]->{postyear} = formatDate(1,$release[0]->{releasedate});
140             $tvars{release} = $release[0];
141             }
142              
143             $cgiparams{articleid} = $tvars{release}->{articleid};
144             $cgiparams{sectionid} = $SECTION_ALBUM;
145             shift->SUPER::Item;
146             $tvars{release}{notes} = clone($tvars{articles}{$tvars{primary}});
147             }
148              
149             sub Lyrics {
150             my $self = shift;
151             return unless($cgiparams{articleid});
152              
153             $self->Item;
154              
155             for my $lyric (sort {$a->{orderno} <=> $b->{orderno}} @{$tvars{release}{lyrics}}) {
156             $cgiparams{articleid} = $lyric->{articleid};
157             $cgiparams{sectionid} = $SECTION_LYRIC;
158             shift->SUPER::Item;
159             $lyric->{data} = clone($tvars{articles}{$tvars{primary}});
160             }
161             }
162              
163             sub Profiles {
164             my $self = shift;
165             return unless($cgiparams{articleid});
166              
167             $self->Item;
168              
169             for my $profile (sort {$a->{orderno} <=> $b->{orderno}} @{$tvars{release}{profiles}}) {
170             $cgiparams{articleid} = $profile->{articleid};
171             $cgiparams{sectionid} = $SECTION_PROFILE;
172             shift->SUPER::Item;
173             $profile->{data} = clone($tvars{articles}{$tvars{primary}});
174             }
175             }
176              
177             =head1 ADMIN INTERFACE METHODS
178              
179             =over 4
180              
181             =item * Admin
182              
183             Manage current list of releases.
184              
185             =item * Add
186              
187             Add a release.
188              
189             =item * Edit
190              
191             Edit existing release.
192              
193             =item * Save
194              
195             Save a release.
196              
197             =item * SaveFormat
198              
199             Save release format.
200              
201             =item * SaveLyric
202              
203             Attach a lyric associated with this release.
204              
205             =item * SaveProfile
206              
207             Attach a profile associated with this release.
208              
209             =item * Promote
210              
211             Promote the publish status of a release.
212              
213             =item * Delete
214              
215             Delete one or more releases.
216              
217             =item * TypeSelect
218              
219             Provide a drop down list of release types.
220              
221             =back
222              
223             =cut
224              
225             sub Admin {
226             return unless(AccessUser($LEVEL));
227             if($cgiparams{doaction}) {
228             if($cgiparams{doaction} eq 'Promote' ) { Promote(); }
229             if($cgiparams{doaction} eq 'Delete' ) { Delete(); }
230             }
231              
232             my @rows = $dbi->GetQuery('hash','ListAllReleases');
233             for my $row (@rows) {
234             $row->{publishstate} = PublishState($row->{publish});
235             }
236             $tvars{data} = \@rows;
237             $tvars{sectionid} = $SECTION_ALBUM;
238             }
239              
240             sub Add {
241             return unless(AccessUser($LEVEL));
242             $cgiparams{sectionid} = $SECTION_ALBUM;
243             shift->SUPER::Add;
244              
245             my %data = (
246             releaseid => 0,
247             title => 'DRAFT',
248             reldate => formatDate(3),
249             ddpublish => PublishSelect(1),
250             ddtypes => TypeSelect(),
251             quickname => $tvars{article}{data}{quickname}
252             );
253              
254             my @allformats = $dbi->GetQuery('hash','ListAllFormats');
255             $tvars{allformats} = \@allformats if(@allformats);
256             my @alltracks = $dbi->GetQuery('hash','ListAllLyrics');
257             $tvars{alltracks} = \@alltracks if(@alltracks);
258              
259             $tvars{release} = \%data;
260             }
261              
262             sub Edit {
263             return unless(AccessUser($LEVEL));
264             my @release = $dbi->GetQuery('hash','GetReleaseByID',$cgiparams{releaseid});
265             return unless(@release);
266             $tvars{release} = $release[0];
267             $tvars{release}{reldate} = formatDate(3,$tvars{release}{releasedate});
268             $tvars{release}{ddtypes} = TypeSelect($cgiparams{releaseid});
269              
270             my @formats = $dbi->GetQuery('hash','ListFormats',$cgiparams{releaseid});
271             $tvars{formats} = \@formats if(@formats);
272             my @lyrics = $dbi->GetQuery('hash','ListLyrics',$cgiparams{releaseid});
273             $tvars{lyrics} = \@lyrics if(@lyrics);
274              
275             my @allformats = $dbi->GetQuery('hash','ListAllFormats');
276             $tvars{allformats} = \@allformats if(@allformats);
277             my @alltracks = $dbi->GetQuery('hash','ListAllLyrics');
278             $tvars{alltracks} = \@alltracks if(@alltracks);
279              
280             $cgiparams{articleid} ||= $tvars{release}{articleid};
281             $cgiparams{sectionid} = $SECTION_ALBUM;
282             shift->SUPER::Edit;
283             }
284              
285             sub Save {
286             return unless(AccessUser($LEVEL));
287             # save content
288             $cgiparams{sectionid} = $SECTION_ALBUM;
289             shift->SUPER::Save;
290              
291             # check details
292             return unless AuthorCheck('GetReleaseByID','releaseid',EDITOR);
293             my $publish = $tvars{data}->{publish} || 0;
294             $tvars{release} = $tvars{data};
295              
296             for(keys %fields) {
297             if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
298             elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
299             elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
300             }
301             return if FieldCheck(\@allfields,\@mandatory);
302              
303             # save release data
304             $tvars{data}->{releasedate} = unformatDate(3,$tvars{data}->{reldate});
305              
306             my @fields = ( $tvars{data}->{title},
307             $tvars{data}->{quickname},
308             $tvars{data}->{publish},
309             $tvars{data}->{releasedate},
310             $tvars{data}->{reltypeid},
311             );
312              
313             if($tvars{data}->{releaseid})
314             { $dbi->DoQuery('UpdateRelease',@fields,$tvars{data}->{releaseid}); }
315             else { $cgiparams{releaseid} = $dbi->IDQuery('InsertRelease',@fields); }
316              
317             # save formats
318             for my $key ( keys %cgiparams ) {
319             if($key =~ /^frm_(\d+)/) {
320             $cgiparams{ixformatid} = $1;
321             $cgiparams{'relformid'} = $cgiparams{'frm_'.$1};
322             $cgiparams{'catalogue'} = $cgiparams{'cat_'.$1};
323             $cgiparams{'label'} = $cgiparams{'lab_'.$1};
324             SaveFormat();
325             } elsif($key =~ /^frm_(x\d+)/) {
326             $cgiparams{ixformatid} = 0;
327             $cgiparams{'relformid'} = $cgiparams{'frm_'.$1};
328             $cgiparams{'catalogue'} = $cgiparams{'cat_'.$1};
329             $cgiparams{'label'} = $cgiparams{'lab_'.$1};
330             SaveFormat();
331             }
332             }
333              
334             if($cgiparams{FORMATS}) {
335             my @ids = CGIArray('FORMATS');
336             $dbi->DoQuery('DeleteFormats',{ids=>join(',',@ids)},$cgiparams{releaseid});
337             }
338              
339             # save track list
340             my %ids;
341             if($cgiparams{LISTED}) {
342             my @ids = CGIArray('LISTED');
343             %ids = map {$_ => 1} @ids;
344             }
345             $dbi->DoQuery('DeleteLyricLinks',{ids => $cgiparams{releaseid}});
346             for my $ord ( keys %cgiparams ) {
347             if($ord =~ /^ord_(\d+)/) {
348             $cgiparams{lyricid} = $1;
349             $cgiparams{orderno} = $cgiparams{$ord};
350             $dbi->DoQuery('InsertLyricLink',$cgiparams{orderno},$cgiparams{releaseid},$cgiparams{lyricid}) unless($ids{$cgiparams{lyricid}});
351             } elsif($ord =~ /^ord_(x\d+)/) {
352             $cgiparams{lyricid} = $cgiparams{'trk_'.$1};
353             $cgiparams{orderno} = $cgiparams{$ord};
354             $dbi->DoQuery('InsertLyricLink',$cgiparams{orderno},$cgiparams{releaseid},$cgiparams{lyricid});
355             }
356             }
357              
358             if($cgiparams{lyric_title} && $cgiparams{lyric_name}) {
359             SaveLyric();
360             }
361             }
362              
363             sub SaveFormat {
364             return unless(AccessUser($LEVEL));
365             if($cgiparams{ixformatid}) {
366             $dbi->DoQuery('UpdateFormat',$cgiparams{releaseid},$cgiparams{relformid},$cgiparams{catalogue},$cgiparams{label},$cgiparams{ixformatid});
367             } else {
368             $dbi->DoQuery('InsertFormat',$cgiparams{releaseid},$cgiparams{relformid},$cgiparams{catalogue},$cgiparams{label});
369             }
370             }
371              
372             sub SaveLyric {
373             return unless(AccessUser($LEVEL));
374             my $id = $dbi->IDQuery('InsertLyric',$cgiparams{lyric_title},$cgiparams{lyric_name},$SECTION_LYRIC);
375             $dbi->DoQuery('InsertLyricLink',$cgiparams{lyric_order},$cgiparams{releaseid},$id);
376             }
377              
378             sub SaveProfile {
379             return unless(AccessUser($LEVEL));
380             my $id = $dbi->IDQuery('InsertProfile',$cgiparams{profile_title},$cgiparams{profile_name},$SECTION_PROFILE);
381             $dbi->DoQuery('InsertProfileLink',$cgiparams{profile_order},$cgiparams{releaseid},$id);
382             }
383              
384             sub Promote {
385             return unless(AccessUser($LEVEL));
386             my @ids = CGIArray('LISTED');
387             next unless(@ids);
388              
389             my @rows = $dbi->GetQuery('hash',$ALLSQL);
390             my %ids = map {$_->{mp3id} => $_->{publish}} @rows;
391              
392             for my $id (@ids) {
393             next unless(defined $ids{$id} && $ids{$id} < 4);
394             $dbi->DoQuery('PromoteReleases',($ids{$id} + 1),$id);
395             }
396             }
397              
398             sub Delete {
399             return unless(AccessUser($LEVEL));
400             my @arts;
401             my @ids = CGIArray('LISTED');
402             return unless @ids;
403             my $ids = join(",",@ids);
404             my @rows = $dbi->GetQuery('hash','GetReleases',{ids => $ids});
405             for my $row (@rows) {
406             push @arts, $row->{articleid};
407             }
408             if(@arts) {
409             my $arts = join(",",@arts);
410             $dbi->DoQuery('DeleteArticleContent',{ids => $arts});
411             $dbi->DoQuery('DeleteArticle', {ids => $arts});
412             }
413             $dbi->DoQuery('DeleteReleases', {ids => $ids});
414             $dbi->DoQuery('DeleteReleaseLinks', {ids => $ids});
415             $dbi->DoQuery('DeleteReleaseFormats',{ids => $ids});
416             }
417              
418             sub TypeSelect {
419             my $opt = shift;
420             my @rows = $dbi->GetQuery('hash','ListAllTypes');
421             DropDownRows($opt,'reltypeid','reltypeid','type',@rows);
422             }
423              
424             1;
425              
426             __END__