Bugzilla – Attachment 18074 Details for
Bug 9836
Filtering sort1 list according to patron category in patron data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9836 Filtering sort1 list according to patron category in patron data
0001-Bug-9836-Filtering-sort1-list-according-to-patron-ca.patch (text/plain), 15.83 KB, created by
Koha Team University Lyon 3
on 2013-05-10 15:36:35 UTC
(
hide
)
Description:
Bug 9836 Filtering sort1 list according to patron category in patron data
Filename:
MIME Type:
Creator:
Koha Team University Lyon 3
Created:
2013-05-10 15:36:35 UTC
Size:
15.83 KB
patch
obsolete
>From 08c95fc841b38429b77c1153e30673210c12ff8e Mon Sep 17 00:00:00 2001 >From: Lyon3 Team <koha@univ-lyon3.fr> >Date: Wed, 8 May 2013 13:58:09 -0400 >Subject: [PATCH] Bug 9836 Filtering sort1 list according to patron category in patron data > >Sort1 criterias are often used as subcategories of patron ones >This patch adds the possibility to link a sort1 criteria to a patron category in the Bsort1 authorised_values settings. >Then in the patron edition Library management block, the sort1 list is filtered according to the selected patron category >and displays only the criterias linked with it. >--- > admin/authorised_values.pl | 54 +++++++++++++++++--- > installer/data/mysql/kohastructure.sql | 1 + > installer/data/mysql/updatedatabase.pl | 8 +++ > .../prog/en/modules/admin/authorised_values.tt | 39 ++++++++++++++- > .../prog/en/modules/members/memberentrygen.tt | 32 +++++++++++- > members/memberentry.pl | 8 ++-- > 6 files changed, 127 insertions(+), 15 deletions(-) > >diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl >index c00bb64..fa4d443 100755 >--- a/admin/authorised_values.pl >+++ b/admin/authorised_values.pl >@@ -27,14 +27,13 @@ use C4::Context; > use C4::Koha; > use C4::Output; > >- > sub AuthorizedValuesForCategory { > my ($searchstring) = shift or return; > my $dbh = C4::Context->dbh; > $searchstring=~ s/\'/\\\'/g; > my @data=split(' ',$searchstring); > my $sth=$dbh->prepare(' >- SELECT id, category, authorised_value, lib, lib_opac, imageurl >+ SELECT * > FROM authorised_values > WHERE (category = ?) > ORDER BY category, authorised_value >@@ -70,7 +69,7 @@ if ($op eq 'add_form') { > my $data; > my @selected_branches; > if ($id) { >- my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?"); >+ my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, linked_with, imageurl from authorised_values where id=?"); > $sth->execute($id); > $data=$sth->fetchrow_hashref; > $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;"); >@@ -114,7 +113,36 @@ if ($op eq 'add_form') { > offset => $offset, > branches_loop => \@branches_loop, > ); >- >+ # Add borrower's categories select list, in case we'd like to bind a sort1 criteria to categories >+ my @linked_with = split ('\|', $data->{'linked_with'} ); >+ my @typeloop; >+ $template->param('allcatcodes'=>1) unless $data->{'linked_with'}; >+ if ($id){ >+ foreach (qw(C A S P I X)) { >+ my $action="WHERE category_type=?"; >+ my ($categories,$labels) = C4::Members::GetborCatFromCatType($_,$action); >+ my @categoryloop; >+ foreach my $cat (@$categories){ >+ my $selected = grep (/$cat/, @linked_with ) ? 1 : 0; >+ push @categoryloop,{ >+ 'categorycode' => $cat, >+ 'categoryname' => $labels->{$cat}, >+ 'selected' => $selected, >+ }; >+ } >+ my %typehash; >+ $typehash{'typename'}=$_; >+ my $typedescription = "typename_".$typehash{'typename'}; >+ $typehash{'categoryloop'}=\@categoryloop; >+ push @typeloop,{ >+ 'typename' => $_, >+ $typedescription => 1, >+ 'categoryloop' => \@categoryloop >+ }; >+ } >+ } >+ $template->param('typeloop' => \@typeloop); >+ > ################## ADD_VALIDATE ################################## > # called by add_form, used to insert/modify data in DB > } elsif ($op eq 'add_validate') { >@@ -141,13 +169,17 @@ if ($op eq 'add_form') { > authorised_value = ?, > lib = ?, > lib_opac = ?, >+ linked_with = ?, > imageurl = ? > WHERE id=?' ); > my $lib = $input->param('lib'); > my $lib_opac = $input->param('lib_opac'); > undef $lib if ($lib eq ""); # to insert NULL instead of a blank string > undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string >- $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id); >+ my @linked_with = $input->param('categorycode'); >+ # pipe after each code is necessary for correct filtering in memberentrygen.tt >+ my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; >+ $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl, $id); > if ( @branches ) { > $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?"); > $sth->execute( $id ); >@@ -173,13 +205,15 @@ if ($op eq 'add_form') { > ($duplicate_entry) = $sth->fetchrow_array(); > unless ( $duplicate_entry ) { > my $sth=$dbh->prepare( 'INSERT INTO authorised_values >- ( category, authorised_value, lib, lib_opac, imageurl ) >- values (?, ?, ?, ?, ?)' ); >+ ( category, authorised_value, lib, lib_opac, linked_with, imageurl ) >+ values (?, ?, ?, ?, ?, ?)' ); > my $lib = $input->param('lib'); > my $lib_opac = $input->param('lib_opac'); > undef $lib if ($lib eq ""); # to insert NULL instead of a blank string > undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string >- $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl ); >+ my @linked_with = $input->param('categorycode'); >+ my $linked_with = $linked_with[0] ne '' ? join ('|',@linked_with).'|' : ''; >+ $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $linked_with, $imageurl ); > $id = $dbh->{'mysql_insertid'}; > if ( @branches ) { > $sth = $dbh->prepare( >@@ -275,11 +309,15 @@ sub default_form { > while ( my $branch = $sth->fetchrow_hashref ) { > push @selected_branches, $branch; > } >+ >+ >+ > my %row_data; # get a fresh hash for the row data > $row_data{category} = $results->[$i]{'category'}; > $row_data{authorised_value} = $results->[$i]{'authorised_value'}; > $row_data{lib} = $results->[$i]{'lib'}; > $row_data{lib_opac} = $results->[$i]{'lib_opac'}; >+ $row_data{linked_with} = substr($results->[$i]{'linked_with'},0,-1) if $results->[$i]{'linked_with'} ;# remove last pipe just for display > $row_data{imageurl} = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} ); > $row_data{edit} = "$script_name?op=add_form&id=".$results->[$i]{'id'}."&offset=$offset"; > $row_data{delete} = "$script_name?op=delete_confirm&searchfield=$searchfield&id=".$results->[$i]{'id'}."&offset=$offset"; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index eddfc3e..c256e07 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -101,6 +101,7 @@ CREATE TABLE `authorised_values` ( -- stores values for authorized values catego > `authorised_value` varchar(80) NOT NULL default '', -- code use to identify the authorized value > `lib` varchar(200) default NULL, -- authorized value description as printed in the staff client > `lib_opac` varchar(200) default NULL, -- authorized value description as printed in the OPAC >+ `linked_with` varchar(200) default NULL, -- borrower categorycode with it may be linked > `imageurl` varchar(200) default NULL, -- authorized value URL > PRIMARY KEY (`id`), > KEY `name` (`category`), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 35f575a..184d3b3 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -6834,6 +6834,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > SetVersion($DBversion); > } > >+$DBversion = "3.11.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do("ALTER TABLE authorised_values ADD linked_with VARCHAR(200) default NULL AFTER lib_opac;"); >+ print "Upgrade to $DBversion done (Added linked_with to the authorised_values table)\n"; >+ SetVersion($DBversion); >+} >+ >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >index 5ba3072..d1940c6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >@@ -103,6 +103,39 @@ $(document).ready(function() { > <label for="lib_opac">Description (OPAC): </label> > <input type="text" name="lib_opac" id="lib_opac" value="[% lib_opac %]" maxlength="200" /> > </li> >+ [% IF ( category == 'Bsort1' ) %] >+ <li> >+ <label for="categorycode">Linked to (patron category)</label> >+ <select id="categorycode" name="categorycode" multiple size="10"> >+ >+ [% FOREACH typeloo IN typeloop %] >+ [% FOREACH categoryloo IN typeloo.categoryloop %] >+ [% IF ( loop.first ) %] >+ [% IF ( typeloo.typename_C ) %]<optgroup label="Child" value="C">[% END %] >+ [% IF ( typeloo.typename_A ) %]<optgroup label="Adult" value="A">[% END %] >+ [% IF ( typeloo.typename_S ) %]<optgroup label="Staff" value="S">[% END %] >+ [% IF ( typeloo.typename_I ) %]<optgroup label="Organization" value="I">[% END %] >+ [% IF ( typeloo.typename_P ) %]<optgroup label="Professional" value="P">[% END %] >+ [% IF ( typeloo.typename_X ) %]<optgroup label="Statistical" value="X">[% END %] >+ [% IF ( allcatcodes ) %] >+ <option value="" selected="selected' data-typename="[% typeloo.typename %]">All Categories</option> >+ [% ELSE %] >+ <option value="" data-typename="[% typeloo.typename %]">All Categories</option> >+ [% END %] >+ [% END %] >+ [% IF ( categoryloo.selected ) %] >+ <option value="[% categoryloo.categorycode %]" selected="selected" data-typename="[% typeloo.typename %]">[% categoryloo.categoryname %]</option> >+ [% ELSE %] >+ <option value="[% categoryloo.categorycode %]" data-typename="[% typeloo.typename %]">[% categoryloo.categoryname %]</option> >+ [% END %] >+ [% IF ( loop.last ) %] >+ </optgroup> >+ [% END %] >+ [% END %] >+ [% END %] >+ </select><div style="margin-left:400px;position:relative;bottom:100px"><p>Select one or more categories (Ctrl key pressed) if you want this authorised value to be a subcategory of them only.</p></div> >+ </li> >+ [% END %] > <li><label for="branches">Libraries limitation: </label> > <select id="branches" name="branches" multiple size="10"> > <option value="">All libraries</option> >@@ -238,7 +271,7 @@ $(document).ready(function() { > [% END %] > <h3>Authorized values for category [% category %]:</h3> > >-[% IF ( loop ) %]<div id="pagertable_authorized_values"> >+[% IF ( looploop ) %]<div id="pagertable_authorized_values"> > </div>[% END %] > > [% IF ( loop ) %]<table id="table_authorized_values" class="tablesorter"> >@@ -246,6 +279,9 @@ $(document).ready(function() { > <th>Authorized value</th> > <th>Description</th> > <th>Description (OPAC)</th> >+ [% IF ( category == 'Bsort1' ) %] >+ <th>Linked category codes</th> >+ [% END %] > <th>Icon</th> > <th>Branches limitations</th> > <th>Edit</th> >@@ -261,6 +297,7 @@ $(document).ready(function() { > <td>[% loo.authorised_value %]</td> > <td>[% loo.lib %]</td> > <td>[% loo.lib_opac %]</td> >+ <td>[% IF ( loo.linked_with ) %][% loo.linked_with %][% ELSE %]All categories[% END %]</td> > <td>[% IF ( loo.imageurl ) %]<img src="[% loo.imageurl %]" alt=""/>[% ELSE %] [% END %]</td> > <td> > [% IF loo.branches.size > 0 %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >index 0098c09..8e36c46 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -6,6 +6,25 @@ > <script type="text/javascript"> > //<![CDATA[ > $(document).ready(function() { >+ $("#categorycode").change(filterSort1).change(); >+ function filterSort1 (){ >+ var catlec= $("#categorycode").find("option:selected").val()+'\\|'; >+ var links=$("#sort1").find("option[title*="+catlec+"]"); >+ if (links.length){ >+ $("#sort1 option").attr('selected', false); >+ $("#sort1 option").each(function(){ >+ $(this).hide() ; >+ }); >+ $(links).each(function(){ >+ $(this).show() ; >+ }); >+ } else { >+ $("#sort1 option").each(function(){ >+ $(this).show() ; >+ }); >+ } >+ } >+ > $("fieldset.rows input").keydown(function(e){ return checkEnter(e); }); > $("#guarantordelete").click(function() { > $("#contact-details").hide().find('a').remove(); >@@ -1042,8 +1061,17 @@ > <label for="sort1"> > [% END %] > Sort 1: </label> >- [% IF ( CGIsort1 ) %] >- [% CGIsort1 %] >+ [% IF ( sort1loop ) %] >+ <select id="sort1" name="sort1" > >+ <option value="" ></option> >+ [% FOREACH sort1loo IN sort1loop %] >+ [% IF ( sort1loo.selected ) %] >+ <option value="[% sort1loo.authorised_value %]" selected="selected" title="[% sort1loo.linked_with %]">[% sort1loo.lib %]</option> >+ [% ELSE %] >+ <option value="[% sort1loo.authorised_value %]" title="[% sort1loo.linked_with %]">[% sort1loo.lib %]</option> >+ [% END %] >+ [% END %] >+ </select> > [% ELSE %] > [% IF ( opduplicate ) %] > <input type="text" id="sort1" name="sort1" size="20" value="[% sort1 %]" onclick="this.value=''" /> >diff --git a/members/memberentry.pl b/members/memberentry.pl >index d2b701d..09eb26a 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -627,13 +627,13 @@ if (C4::Context->preference("memberofinstitution")){ > > # -------------------------------------------------------------------------------------------------------- > >-my $CGIsort = buildCGIsort("Bsort1","sort1",$data{'sort1'}); >-if ($CGIsort) { >- $template->param(CGIsort1 => $CGIsort); >+my $sort1auth = GetAuthorisedValues('Bsort1',$data{'sort1'}); >+if ($sort1auth) { >+ $template->param(sort1loop => $sort1auth); > } > $template->param( sort1 => $data{'sort1'}); # shouldn't this be in an "else" statement like the 2nd one? > >-$CGIsort = buildCGIsort("Bsort2","sort2",$data{'sort2'}); >+my $CGIsort = buildCGIsort("Bsort2","sort2",$data{'sort2'}); > if ($CGIsort) { > $template->param(CGIsort2 => $CGIsort); > } else { >-- >1.7.2.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9836
:
16255
|
16258
|
16301
|
17929
|
18074
|
18426
|
18461
|
18541