Permalink
Browse files

Replace "Serials" with "Periodicals"

Encompasses:
SCLS-SER-1027 - Adjust prediction when editing enumeration and chronology
SCLS-SER-1029 - Adding chronologies to issue prediction
SCLS-SER-1030 - Managing Subscriptions Centrally
SCLS-SER-1033 - Multiple agencies with separate subscriptions
  • Loading branch information...
1 parent f171652 commit 997962303df2e6ad009a7745961b40b040bcae0d @pjones9 pjones9 committed Nov 3, 2010
Showing with 3,748 additions and 9 deletions.
  1. +23 −1 C4/Auth.pm
  2. +2 −2 C4/Branch.pm
  3. +1 −1 C4/Context.pm
  4. +136 −0 C4/Control/Periodical.pm
  5. +154 −0 C4/Control/PeriodicalSerial.pm
  6. +116 −0 C4/Control/PeriodicalSerialFormats.pm
  7. +132 −0 C4/Control/Subscription.pm
  8. +97 −0 C4/Control/SubscriptionSerial.pm
  9. +44 −0 C4/Model/Biblio.pm
  10. +14 −0 C4/Model/Biblio/Manager.pm
  11. +64 −0 C4/Model/Biblioitem.pm
  12. +14 −0 C4/Model/Biblioitem/Manager.pm
  13. +9 −0 C4/Model/DB/Object/AutoBase1.pm
  14. +81 −0 C4/Model/Item.pm
  15. +14 −0 C4/Model/Item/Manager.pm
  16. +47 −0 C4/Model/Periodical.pm
  17. +14 −0 C4/Model/Periodical/Manager.pm
  18. +45 −0 C4/Model/PeriodicalSerial.pm
  19. +14 −0 C4/Model/PeriodicalSerial/Manager.pm
  20. +41 −0 C4/Model/Subscription.pm
  21. +14 −0 C4/Model/Subscription/Manager.pm
  22. +41 −0 C4/Model/SubscriptionSerial.pm
  23. +14 −0 C4/Model/SubscriptionSerial/Manager.pm
  24. +32 −0 C4/Model/SubscriptionSerialItem.pm
  25. +14 −0 C4/Model/SubscriptionSerialItem/Manager.pm
  26. +21 −0 C4/RoseDB.pm
  27. +272 −0 C4/View/Serials.pm
  28. +57 −0 C4/View/SerialsFormats.pm
  29. +1 −0 admin/systempreferences.pl
  30. +1 −0 installer/data/mysql/en/mandatory/sysprefs.sql
  31. +52 −0 installer/data/mysql/kohastructure.sql
  32. +67 −1 installer/data/mysql/updatedatabase.pl
  33. +2 −0 koha-tmpl/intranet-tmpl/prog/en/includes/periodicals-menu.inc
  34. +29 −0 koha-tmpl/intranet-tmpl/prog/en/includes/periodicals-search.inc
  35. +57 −0 koha-tmpl/intranet-tmpl/prog/en/includes/periodicals-toolbar.inc
  36. +5 −1 koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl
  37. +6 −2 koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tmpl
  38. +46 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/acqui-search-result.tmpl
  39. +31 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/acqui-search.tmpl
  40. +41 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/periodical-bib-search.tmpl
  41. +81 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/periodical_serial-edit.tmpl
  42. +288 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/periodicals-add.tmpl
  43. +87 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/periodicals-detail.tmpl
  44. +36 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/periodicals-home.tmpl
  45. +68 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/result.tmpl
  46. +213 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/subscription-add.tmpl
  47. +115 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/subscription-detail.tmpl
  48. +72 −0 koha-tmpl/intranet-tmpl/prog/en/modules/periodicals/subscription_serial-edit.tmpl
  49. +1 −1 kohaversion.pl
  50. +4 −0 mainpage.pl
  51. +23 −0 misc/rdb-mkschema.pl
  52. +93 −0 periodicals/acqui-search-result.pl
  53. +95 −0 periodicals/acqui-search.pl
  54. +56 −0 periodicals/format_sequence.pl
  55. +228 −0 periodicals/periodical-bib-search.pl
  56. +61 −0 periodicals/periodical_serial-edit.pl
  57. +46 −0 periodicals/periodicals-add.pl
  58. +46 −0 periodicals/periodicals-detail.pl
  59. +47 −0 periodicals/periodicals-home.pl
  60. +64 −0 periodicals/subscription-add.pl
  61. +53 −0 periodicals/subscription-detail.pl
  62. +54 −0 periodicals/subscription_serial-edit.pl
  63. +52 −0 t/Periodicals.t
View
@@ -38,7 +38,7 @@ BEGIN {
$VERSION = 3.02; # set version for version checking
$debug = $ENV{DEBUG} || 0 ;
@ISA = qw(Exporter);
- @EXPORT = qw(&checkauth &get_template_and_user &IsIpInLibrary);
+ @EXPORT = qw(&checkauth &get_template_and_user &IsIpInLibrary &GetUserGroupBranches);
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &check_override_perms &get_all_subpermissions &get_user_subpermissions);
%EXPORT_TAGS = (EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)]);
$ldap = C4::Context->config('useldapserver') || 0;
@@ -1586,6 +1586,28 @@ sub IsIpInLibrary {
return;
}
+sub _uniq {
+ return sort keys %{{ map { $_ => 1 } @_ }};
+}
+
+sub GetUserGroupBranches {
+ my $category = shift or die;
+ my $userid = shift || C4::Context::userenv->{id} or die;
+
+ my @branches;
+ my $flags = haspermission($userid);
+ if (defined $flags and $flags->{superlibrarian}) {
+ @branches = keys %{C4::Branch::GetBranches()};
+ } else {
+ my $borrower = GetMember($userid, 'userid') or return undef;
+ push @branches, $borrower->{branchcode};
+ my $categories = C4::Branch::GetBranchCategories($borrower->{branchcode}, $category);
+ push(@branches, map {@{C4::Branch::GetBranchesInCategory($_->{categorycode})}} @{$categories});
+ @branches = _uniq(@branches);
+ }
+ return @branches;
+}
+
END { } # module clean-up code here (global destructor)
1;
__END__
View
@@ -329,7 +329,7 @@ sub GetBranchCategories {
my (@where, @bind);
if($branchcode) {
$query .= ",branchrelations r, branches b ";
- push @where, "c.categorycode=r.categorycode and r.branchcode=? ";
+ push @where, "c.categorycode=r.categorycode AND r.branchcode=b.branchcode AND r.branchcode=?";
push @bind , $branchcode;
}
if ($categorytype) {
@@ -360,7 +360,7 @@ the categories were already here, and minimally used.
#TODO manage category types. rename possibly to 'agency domains' ? as borrowergroups are called categories.
sub GetCategoryTypes() {
- return ( 'searchdomain','properties');
+ return ( 'searchdomain','properties', 'subscriptions');
}
=head2 GetBranch
View
@@ -78,7 +78,7 @@ BEGIN {
$main::SIG{__DIE__} = \&CGI::Carp::confess;
}
} # else there is no browser to send fatals to!
- $VERSION = '4.03.00.007';
+ $VERSION = '4.03.00.008';
}
use DBI;
View
@@ -0,0 +1,136 @@
+package C4::Control::Periodical;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha 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.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use warnings;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(
+ UpdateOrCreate
+ SearchPeriodicals
+ );
+
+use Carp;
+use Try::Tiny;
+use CGI;
+use Rose::DB::Object::Helpers qw(column_value_pairs);
+use DateTime::Format::Strptime;
+
+use C4::Model::Periodical;
+use C4::Model::Periodical::Manager;
+use C4::Model::PeriodicalSerial;
+use C4::Model::PeriodicalSerial::Manager;
+use C4::Model::Biblio;
+use C4::Model::Biblio::Manager;
+use C4::Model::Biblioitem;
+use C4::Model::Biblioitem::Manager;
+use C4::Biblio;
+
+sub _create_first_periodicalserial($$) {
+ my ($query, $periodical_id) = @_;
+ my $periodical_serial = C4::Model::PeriodicalSerial->new;
+ $periodical_serial->periodical_id($periodical_id);
+ $periodical_serial->sequence($query->param('first_sequence'));
+ $periodical_serial->publication_date($query->param('firstacquidate'));
+ $periodical_serial->vintage(C4::Control::PeriodicalSerial::FormatSequence(
+ $periodical_serial->periodical->sequence_format, $periodical_serial->sequence,
+ $periodical_serial->publication_date(format => '%Y')));
+ $periodical_serial->save;
+ return $periodical_serial->id;
+}
+
+sub _set_biblio_as_periodical($) {
+ my $biblionumber = shift or croak;
+
+ my (undef, ($biblio)) = C4::Biblio::GetBiblio($biblionumber);
+ if(not $biblio->{'serial'}) {
+ my $record = C4::Biblio::GetMarcBiblio($biblionumber);
+ my ($tag, $subfield) = C4::Biblio::GetMarcFromKohaField('biblio.serial', $biblio->{frameworkcode});
+ if($tag) {
+ if ($record->field($tag)) {
+ $record->field($tag)->update($subfield => 1);
+ } else {
+ $record->append_fields(MARC::Field->new($tag, '', '', $subfield => 1));
+ }
+ C4::Biblio::ModBiblio($record, $biblionumber, $biblio->{'frameworkcode'});
+ }
+ }
+ return 1;
+}
+
+sub UpdateOrCreate($) {
+ my $query = shift;
+ my $periodical_id = $query->param('periodical_id');
+
+ $periodical_id = try {
+ my $periodical = C4::Model::Periodical->new;
+ if ($periodical_id) {
+ $periodical->id($periodical_id);
+ $periodical->load;
+ }
+ $periodical->biblionumber($query->param('biblionumber'));
+ $periodical->iterator($query->param('iterator'));
+ $periodical->sequence_format($query->param('sequence_format'));
+ $periodical->chronology_format($query->param('chronology_format'));
+ $periodical->frequency($query->param('frequency'));
+ $periodical->save;
+
+ _create_first_periodicalserial($query, $periodical->id) if (not defined $query->param('periodical_id'));
+ _set_biblio_as_periodical($periodical->biblionumber);
+
+ print $query->redirect("periodicals-detail.pl?periodical_id=".$periodical->id);
+ $periodical->id;
+ } catch {
+ my $message = "Error creating or updating periodical: $_\n";
+ carp $message;
+ $query->param(error => $message);
+ undef;
+ };
+
+ return $periodical_id;
+}
+
+sub SearchPeriodicals {
+ my ($key, $value) = @_;
+
+ $value = '%'.$value.'%';
+ $value =~ s/\s/%/g;
+ my $rows;
+ if ($key eq 'issn') {
+ $rows = C4::Model::Biblioitem::Manager->get_biblioitems(
+ query => [ $key => { like => $value } ],
+ select => [ 'biblionumber' ],
+ );
+ } elsif ($key eq 'title') {
+ $rows = C4::Model::Biblio::Manager->get_biblio(
+ query => [ $key => { like => $value } ],
+ select => [ 'biblionumber' ],
+ );
+ }
+ my @biblionumbers = map {$_->biblionumber} @{$rows};
+ return undef if not @biblionumbers;
+
+ my $periodicals = C4::Model::Periodical::Manager->get_periodicals(
+ with_object => [ 'biblio' ],
+ query => [ biblionumber => { in_set => \@biblionumbers } ],
+ );
+
+ return $periodicals;
+}
+
+1;
@@ -0,0 +1,154 @@
+package C4::Control::PeriodicalSerial;
+
+use strict;
+use warnings;
+
+use Carp;
+use Try::Tiny;
+use DateTime;
+
+use C4::Model::Periodical;
+use C4::Model::PeriodicalSerial;
+use C4::Model::PeriodicalSerial::Manager;
+
+use C4::Control::PeriodicalSerialFormats
+ qw(PredictNextSequenceFromSeed
+ PredictNextChronologyFromSeed
+ FormatSequence
+ FormatChronology
+ FormatVintage
+ );
+
+sub GenerateNextInSeries($) {
+ my $p = shift or croak;
+
+ $p = C4::Model::Periodical->new(id => $p)->load if not ref $p;
+
+ my $pslist = C4::Model::PeriodicalSerial::Manager->get_periodical_serials(
+ query => [
+ periodical_id => $p->id,
+ '!sequence' => undef,
+ '!sequence' => '',
+ ],
+ sort_by => 'publication_date DESC',
+ limit => 1
+ );
+
+ my $new_seq_string = PredictNextSequenceFromSeed($p->iterator, $pslist->[0]->sequence);
+ my $new_date = PredictNextChronologyFromSeed($p->frequency, $pslist->[0]->publication_date);
+
+ my $new_ps = C4::Model::PeriodicalSerial->new(periodical_id => $p->id, sequence => $new_seq_string, publication_date => $new_date->clone);
+ $new_ps->vintage(FormatVintage(
+ FormatSequence($p->sequence_format, $new_seq_string, $new_date->year),
+ FormatChronology($p->chronology_format, $new_date)
+ ));
+ $new_ps->save;
+
+ return $new_ps;
+}
+
+sub FormatSequenceOfSerial($) {
+ my $ps = shift or croak;
+
+ $ps = C4::Model::PeriodicalSerial->new(id => $ps)->load if not ref $ps;
+ return FormatSequence($ps->periodical->sequence_format, $ps->sequence, $ps->publication_date(format => '%Y'));
+}
+
+sub FormatChronologyOfSerial($) {
+ my $ps = shift or croak;
+
+ $ps = C4::Model::PeriodicalSerial->new(id => $ps)->load if not ref $ps;
+ return FormatChronology($ps->periodical->chronology_format, $ps->publication_date);
+}
+
+sub FormatVintageOfSerial($) {
+ my $ps = shift or croak;
+
+ $ps = C4::Model::PeriodicalSerial->new(id => $ps)->load if not ref $ps;
+ return FormatVintage(FormatSequenceOfSerial($ps), FormatChronologyOfSerial($ps));
+}
+
+sub Update($) {
+ my $query = shift or croak;
+ my $periodical_serial_id = $query->param('periodical_serial_id') // croak;
+
+ my $periodical_serial = try {
+ my $periodical_serial = C4::Model::PeriodicalSerial->new(id => $periodical_serial_id)->load;;
+ $periodical_serial->sequence($query->param('sequence'));
+ $periodical_serial->vintage($query->param('vintage'));
+ $periodical_serial->publication_date($query->param('publication_date'));
+ $periodical_serial->save;
+
+ print $query->redirect("periodicals-detail.pl?periodical_id=".$periodical_serial->periodical_id);
+ $periodical_serial;
+ } catch {
+ my $message = "Error creating or updating periodical: $_\n";
+ carp $message;
+ $query->param(error => $message);
+ undef;
+ };
+
+ return $periodical_serial;
+}
+
+sub CombineSequences($$;$) {
+ my $ps = shift or croak;
+ my $count = shift or croak;
+ my $options = shift // {};
+
+ $ps = C4::Model::PeriodicalSerial->new(id => $ps)->load if not ref $ps;
+
+ # Create new format with least significant sequence element set to +$count.
+ my $format = $ps->periodical->sequence_format;
+ $format =~ /({.*})?.*({.*})?.*{(.*)}/;
+ my $newseq = sprintf '{%s+%s}', $3, $count-1;
+ $format =~ s/{$3}/$newseq/;
+ $ps->periodical->sequence_format($format);
+
+ # Express a new vintage string.
+ $ps->vintage(FormatVintageOfSerial($ps));
+
+ # Incrementing this issue is done.
+ $ps->save;
+
+ # Multiply the frequency.
+ my $freq = $ps->periodical->frequency;
+ $freq =~ /^(\d+)(\/\d+)?([dwmy])/;
+ $freq = sprintf '%d%s%s', $1*$count, $2 // '', $3;
+ $ps->periodical->frequency($freq);
+
+ # Update the iterator such that it will skip the appropriate number
+ # of iterations.
+ my @itr;
+ for (split(/:/, $ps->periodical->iterator)) {
+ my @i = (split(/,/, $_));
+ push @itr, \@i;
+ }
+ for (reverse @itr) {
+ $_->[1] *= $count and last if ($_->[1] != 0);
+ }
+ my @tmp_itr = map {join(',', @{$_})} (@itr);
+ my $new_itr = join(':', @tmp_itr);
+ $ps->periodical->iterator($new_itr);
+
+ if ($options->{permanent}) {
+ # If permanent, just save the updated periodical with its new qualities.
+ $ps->periodical->save;
+ } else {
+ # If not permanent, then immediately generate the next $ps in the sequence
+ # after resetting the sequence formatting.
+ # This preseves the sequence skip for future issues.
+ # Note that we do *not* save the periodical.
+ $ps->periodical->load;
+ $ps->periodical->iterator($new_itr);
+ $ps->periodical->frequency($freq);
+ GenerateNextInSeries($ps->periodical);
+ }
+ return $ps->id;
+}
+
+sub UncombineSequences($) {
+ croak 'Not yet implemented';
+}
+
+1;
Oops, something went wrong.

0 comments on commit 9979623

Please sign in to comment.