+++ /dev/null
-package C4::Category;
-
-# Copyright 2009 Liblime
-# Parts Copyright 2011 Tamil
-#
-# 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 3 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, see <http://www.gnu.org/licenses>.
-
-use strict;
-use warnings;
-use C4::Context;
-
-our $AUTOLOAD;
-
-
-
-
-=head1 NAME
-
-C4::Category - objects from the categories table
-
-=head1 SYNOPSIS
-
- use C4::Category;
- my @categories = C4::Category->all;
- print join("\n", map { $_->description } @categories), "\n";
-
-=head1 DESCRIPTION
-
-Objects of this class represent a row in the C<categories> table.
-
-Currently, the bare minimum for using this as a read-only data source has
-been implemented. The API was designed to make it easy to transition to
-an ORM later on.
-
-=head1 API
-
-=head2 Class Methods
-
-=cut
-
-=head3 C4::Category->new(\%opts)
-
-Given a hashref, a new (in-memory) C4::Category object will be instantiated.
-The database is not touched.
-
-=cut
-
-sub new {
- my ($class, $opts) = @_;
- bless $opts => $class;
-}
-
-
-
-
-=head3 C4::Category->all
-
-This returns all the categories as objects. By default they're ordered by
-C<description>.
-
-=cut
-
-sub all {
- my ( $class ) = @_;
- my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
- my $dbh = C4::Context->dbh;
- # The categories table is small enough for
- # `SELECT *` to be harmless.
- my $query = "SELECT categories.* FROM categories";
- $query .= qq{
- LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode
- WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL
- } if $branch_limit;
- $query .= " ORDER BY description";
- return map { $class->new($_) } @{
- $dbh->selectall_arrayref(
- $query,
- { Slice => {} },
- $branch_limit ? $branch_limit : ()
- )
- };
-}
-
-
-
-
-=head2 Object Methods
-
-These are read-only accessors for attributes of a C4::Category object.
-
-=head3 $category->categorycode
-
-=cut
-
-=head3 $category->description
-
-=cut
-
-=head3 $category->enrolmentperiod
-
-=cut
-
-=head3 $category->upperagelimit
-
-=cut
-
-=head3 $category->dateofbirthrequired
-
-=cut
-
-=head3 $category->finetype
-
-=cut
-
-=head3 $category->bulk
-
-=cut
-
-=head3 $category->enrolmentfee
-
-=cut
-
-=head3 $category->overduenoticerequired
-
-=cut
-
-=head3 $category->issuelimit
-
-=cut
-
-=head3 $category->reservefee
-
-=cut
-
-=head3 $category->category_type
-
-=cut
-
-sub AUTOLOAD {
- my $self = shift;
- my $attr = $AUTOLOAD;
- $attr =~ s/.*://;
- if (exists $self->{$attr}) {
- return $self->{$attr};
- } else {
- return undef;
- }
-}
-
-sub DESTROY { }
-
-
-
-
-=head1 SEE ALSO
-
-The following modules make reference to the C<categories> table.
-
-L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
-
-
-=head1 AUTHOR
-
-John Beppu <john.beppu@liblime.com>
-
-=cut
-
-1;
use strict;
use warnings;
use C4::Context;
-use C4::Category;
use Carp qw(carp croak);
use Koha::ItemTypes;
+use Koha::Patron::Categories;
our $AUTOLOAD;
my ($class, $where) = @_;
my @branch_prefs = $class->find($where);
my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} });
- my @cc = C4::Category->all;
+ my @cc = Koha::Patron::Categories->search_limited;
my @it = Koha::ItemTypes->search;
my $notification = $where->{notification};
my %disabled = map {
use Carp;
+use C4::Context; # Sigh...
+
use Koha::Database;
use Koha::Patron::Category;
=cut
+sub search_limited {
+ my ( $self ) = @_;
+ my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
+ return $self->search({}, {order_by => ['description']}) unless $branch_limit;
+ return $self->search({
+ 'categories_branches.branchcode' => [$branch_limit, undef]},
+ {
+ join => 'categories_branches',
+ order_by => ['description'],
+ }
+ );
+}
+
=head3 type
=cut
use Template::Plugin;
use base qw( Template::Plugin );
-use C4::Category;
use Koha::Patron::Categories;
-sub GetName {
- my ( $self, $categorycode ) = @_;
-
- return Koha::Patron::Categories->find( $categorycode )->description;
-}
-
sub all {
- my ( $self, $params ) = @_;
- my $selected = $params->{selected};
-
- my @categories = C4::Category->all;
- if ( $selected ) {
- for my $category ( @categories ) {
- if ( $category->{categorycode} eq $selected ) {
- $category->{selected} = 1;
- }
- }
- }
- return @categories;
+ return Koha::Patron::Categories->search_limited;
}
1;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Branch qw( GetBranches );
-use C4::Category;
use C4::Output;
use C4::Members;
+use Koha::Patron::Categories;
+
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $onlymine = C4::Branch::onlymine;
my $branches = C4::Branch::GetBranches( $onlymine );
+my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
json_template => 'acqui/tables/members_results.tt',
selection_type => 'add',
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
- categories => [ C4::Category->all ],
+ categories => $patron_categories,
branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Branch qw( GetBranches );
-use C4::Category;
use C4::Output;
use C4::Members;
+use Koha::Patron::Categories;
+
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $onlymine = C4::Branch::onlymine;
my $branches = C4::Branch::GetBranches( $onlymine );
+my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
json_template => 'acqui/tables/members_results.tt',
selection_type => $selection_type,
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
- categories => [ C4::Category->all ],
+ categories => $patron_categories,
branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
use C4::Auth;
use C4::Context;
use C4::Branch;
-use C4::Category;
use C4::ItemCirculationAlertPreference;
use C4::Output;
use Koha::ItemTypes;
+use Koha::Patron::Categories;
# shortcut for long package name
our $preferences = 'C4::ItemCirculationAlertPreference';
}
my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
- my @categories = (
- C4::Category->all
- );
+ my @categories = Koha::Patron::Categories->search_limited;
my @item_types = Koha::ItemTypes->search;
my $grid_checkout = $preferences->grid({ branchcode => $branch, notification => 'CHECKOUT' });
my $grid_checkin = $preferences->grid({ branchcode => $branch, notification => 'CHECKIN' });
#Â Pre-load libraries
use C4::Boolean;
use C4::Branch;
-use C4::Category;
use C4::Koha;
use C4::Languages;
use C4::Letters;
<p>
<label for="categorycode">Category: </label>
- [% SET categories = Categories.all( selected => categorycode_filter ) %]
+ [% SET categories = Categories.all() %]
<select name="categorycode_filter" id="categorycode">
<option value="">Any</option>
- [% FOREACH categorie IN categories %]
- [% IF ( categorie.selected ) %]
- <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>
+ [% FOREACH category IN categories %]
+ [% IF category.categorycode == categorycode_filter %]
+ <option value="[% category.categorycode %]" selected="selected">[% category.description %]</option>
[% ELSE %]
- <option value="[% categorie.categorycode %]">[% categorie.description %]</option>
+ <option value="[% category.categorycode %]">[% category.description %]</option>
[% END %]
[% END %]
</select>
</li>
<li>
<label for="categorycode_filter">Category:</label>
- [% SET categories = Categories.all( selected => categorycode_filter ) %]
+ [% SET categories = Categories.all() %]
<select id="categorycode_filter">
<option value="">Any</option>
[% FOREACH cat IN categories %]
- [% IF cat.selected %]
+ [% IF cat.categorycode == categorycode_filter %]
<option selected="selected" value="[% cat.categorycode %]">[% cat.description %]</option>
[% ELSE %]
<option value="[% cat.categorycode %]">[% cat.description %]</option>
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Branch qw( GetBranches );
-use C4::Category;
use C4::Output;
use C4::Members;
+use Koha::Patron::Categories;
+
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $onlymine = C4::Branch::onlymine;
my $branches = C4::Branch::GetBranches( $onlymine );
+my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ],
json_template => 'members/tables/guarantor_search.tt',
selection_type => 'select',
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
- categories => [ C4::Category->all ],
+ categories => $patron_categories,
branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
use C4::Output;
use CGI qw( -utf8 );
use C4::Branch;
-use C4::Category;
use C4::Members qw( GetMember );
use Koha::DateUtils;
use Koha::List::Patron;
use C4::Context;
use C4::Members;
use C4::Branch;
-use C4::Category;
use Koha::Patron::Modifications;
use Koha::Libraries;
use Koha::List::Patron;
+use Koha::Patron::Categories;
my $query = new CGI;
my $branch = $query->param('branchcode');
}
}
-my @categories;
my $no_add = 0;
if(scalar(@branchloop) < 1){
$no_add = 1;
$template->param(branchloop=>\@branchloop);
}
-@categories=C4::Category->all;
+my @categories = Koha::Patron::Categories->search_limited;
if(scalar(@categories) < 1){
$no_add = 1;
$template->param(no_categories => 1);
use C4::Context;
use C4::Members;
use C4::Branch;
-use C4::Category;
use Koha::Patron::Modifications;
my $query = new CGI;
use C4::Context;
use C4::Members;
use C4::Branch;
-use C4::Category;
use Koha::Patron::Modifications;
my $query = new CGI;
use Modern::Perl;
use CGI;
use C4::Auth;
-use C4::Category;
use C4::Context;
use C4::Output;
use C4::Members;
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLSearch NLDecodePin NLGetFirstname NLGetSurname NLSync );
use Koha::Database;
use Koha::DateUtils;
+use Koha::Patron::Categories;
my $cgi = CGI->new;
my $dbh = C4::Context->dbh;
my $result = NLSearch( $identifier );
unless ($result->fault) {
my $r = $result->result();
- # Send the data to the template
- my @categories = C4::Category->all;
+ my $categories = Koha::Patron::Categories->search_limited;
$template->param(
'result' => $r,
- 'categories' => \@categories,
+ 'categories' => $categories,
);
} else {
$template->param( 'error' => join ', ', $result->faultcode, $result->faultstring, $result->faultdetail );
use C4::Koha;
use C4::XSLT;
use C4::Branch;
-use C4::Category;
use Koha::DateUtils;
use Koha::Caches;
use Koha::Cache::Memory::Lite;
+use Koha::Patron::Categories;
+
=for preload
use C4::Tags; # FIXME
=cut
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Branch qw( GetBranches );
-use C4::Category;
use C4::Output;
use C4::Members;
+use Koha::Patron::Categories;
+
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $onlymine = C4::Branch::onlymine;
my $branches = C4::Branch::GetBranches( $onlymine );
+my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
columns => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'],
json_template => 'patroncards/tables/members_results.tt',
selection_type => 'add',
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
- categories => [ C4::Category->all ],
+ categories => $patron_categories,
branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
use C4::Output;
use C4::Reports;
use C4::Members;
-use C4::Category;
use Koha::DateUtils;
use List::MoreUtils qw/any/;
use YAML;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Branch qw( GetBranches );
-use C4::Category;
use C4::Output;
use C4::Members;
+use Koha::Patron::Categories;
+
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $onlymine = C4::Branch::onlymine;
my $branches = C4::Branch::GetBranches( $onlymine );
+my $patron_categories = Koha::Patron::Categories->search_limited;
$template->param(
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
json_template => 'serials/tables/members_results.tt',
selection_type => 'add',
alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
- categories => [ C4::Category->all ],
+ categories => $patron_categories,
branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
aaSorting => 1,
);
+++ /dev/null
-#!/usr/bin/perl
-
-# This file is part of Koha.
-#
-# Copyright 2014 - Koha Team
-#
-# 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 3 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, see <http://www.gnu.org/licenses>.
-
-use Modern::Perl;
-
-use t::lib::TestBuilder;
-use Test::More tests => 3;
-
-use Koha::Database;
-
-BEGIN {
- use_ok('C4::Category');
-}
-
-my $schema = Koha::Database->new->schema;
-$schema->storage->txn_begin;
-
-my $builder = t::lib::TestBuilder->new();
-
-my $nonexistent_categorycode = 'NONEXISTEN';
-$builder->build({
- source => 'Category',
- value => {
- categorycode => $nonexistent_categorycode,
- description => 'Desc',
- enrolmentperiod => 12,
- enrolementperioddate => '2014-01-02',
- upperagelimit => 99,
- dateofbirthrequired => 1,
- enrolmentfee => 1.5,
- reservefee => 2.5,
- hidelostitems => 0,
- overduenoticerequired => 0,
- category_type => 'A',
- },
-});
-
-my @categories = C4::Category->all;
-ok( @categories, 'all returns categories' );
-
-my $match = grep {$_->{categorycode} eq $nonexistent_categorycode } @categories;
-is( $match, 1, 'all returns the inserted category');
-
-$schema->storage->txn_rollback;
-
-1;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Category;
use Koha::Library;
use MARC::Record;
use C4::Items;
use C4::Members;
use C4::Branch;
-use C4::Category;
use C4::Circulation;
use Koha::Library;
+use Koha::Patron::Categories;
use MARC::Record;
my $dbh = C4::Context->dbh;
my $categorycode;
my $category_created;
-my @categories = C4::Category->all;
+my @categories = Koha::Patron::Categories->search_limited;
if (@categories) {
- $categorycode = $categories[0]->{categorycode}
+ $categorycode = $categories[0]->categorycode
} else {
$categorycode = 'C';
C4::Context->dbh->do(
use Modern::Perl;
-use Test::More tests => 7;
+use Test::More tests => 11;
+use C4::Context;
use Koha::Database;
use Koha::Patron::Category;
use Koha::Patron::Categories;
is( $retrieved_category_1->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' );
is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' );
+my $another_branch = $builder->build( { source => 'Branch', } );
+C4::Context->_new_userenv('my_new_userenv');
+C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
+my $new_category_3 = Koha::Patron::Category->new(
+ { categorycode => 'mycatcodeZ',
+ description => 'mycatdescZ',
+ }
+)->store;
+$new_category_3->add_branch_limitation( $another_branch->{branchcode} );
+is( Koha::Patron::Categories->search->count, $nb_of_categories + 3, 'The 3rd patron category should have been added' );
+my @limited_categories = Koha::Patron::Categories->search_limited;
+my @limited_category_codes = map { $_->categorycode } @limited_categories;
+is( scalar( grep { $_ eq $new_category_1->categorycode } @limited_category_codes ), 0, 'The first category is limited to another branch' );
+is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
+is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
+
$retrieved_category_1->delete;
-is( Koha::Patron::Categories->search->count, $nb_of_categories + 1, 'Delete should have deleted the patron category' );
+is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
$schema->storage->txn_rollback;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Category;
use C4::Circulation;
use Koha::Libraries;
use MARC::Record;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Category;
use C4::Circulation;
use Koha::Libraries;
use MARC::Record;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Category;
use C4::Circulation;
use Koha::Library;
use MARC::Record;
use C4::Biblio;
use C4::Items;
use C4::Members;
-use C4::Category;
use C4::Circulation;
use Koha::DateUtils qw( dt_from_string output_pref );
use C4::Biblio qw/AddBiblio/;
use C4::Members;
use C4::Context;
-use C4::Category;
use Koha::Database;
+use Koha::Patron::Categories;
use t::lib::TestBuilder;
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
-my @categories = C4::Category->all;
+my @categories = Koha::Patron::Categories->search_limited;
my $categorycode = $categories[0]->categorycode;
my $branchcode = $library->{branchcode};
use C4::Members::AttributeTypes;
use Koha::Library;
+use Koha::Patron::Categories;
use t::lib::Mocks;
$dbh->{RaiseError} = 1;
# Pick a categorycode from the DB
-my @categories = C4::Category->all;
+my @categories = Koha::Patron::Categories->search_limited;
my $categorycode = $categories[0]->categorycode;
# Add a new branch so we control what borrowers it has
my $branchcode = "UNC";
use C4::Members;
use Koha::Library;
+use Koha::Patron::Categories;
use Koha::Virtualshelf;
use Koha::Virtualshelves;
$dbh->do(q|DELETE FROM virtualshelves|);
# Pick a categorycode from the DB
-my @categories = C4::Category->all;
+my @categories = Koha::Patron::Categories->search_limited;
my $categorycode = $categories[0]->categorycode;
my $branchcode = "ABC";
my $branch_data = {