1 package C4
::CourseReserves
;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use List
::MoreUtils
qw(any);
23 use C4
::Items
qw(GetItem ModItem);
24 use C4
::Circulation
qw(GetOpenIssue);
26 use vars
qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
50 &GetItemCourseReservesInfo
52 %EXPORT_TAGS = ( 'all' => \
@EXPORT_OK );
55 @FIELDS = ( 'itype', 'ccode', 'holdingbranch', 'location' );
60 C4::CourseReserves - Koha course reserves module
64 use C4::CourseReserves;
68 This module deals with course reserves.
74 $course = GetCourse( $course_id );
80 warn whoami
() . "( $course_id )" if $DEBUG;
82 my $query = "SELECT * FROM courses WHERE course_id = ?";
83 my $dbh = C4
::Context
->dbh;
84 my $sth = $dbh->prepare($query);
85 $sth->execute($course_id);
87 my $course = $sth->fetchrow_hashref();
90 SELECT b.* FROM course_instructors ci
91 LEFT JOIN borrowers b ON ( ci.borrowernumber = b.borrowernumber )
94 $sth = $dbh->prepare($query);
95 $sth->execute($course_id);
96 $course->{'instructors'} = $sth->fetchall_arrayref( {} );
103 ModCourse( [ course_id => $id ] [, course_name => $course_name ] [etc...] );
109 warn identify_myself
(%params) if $DEBUG;
111 my $dbh = C4
::Context
->dbh;
114 if ( defined $params{'course_id'} ) {
115 $course_id = $params{'course_id'};
116 delete $params{'course_id'};
124 $query .= ($course_id) ?
' UPDATE ' : ' INSERT ';
125 $query .= ' courses SET ';
127 foreach my $key ( keys %params ) {
128 push( @query_keys, "$key=?" );
129 push( @query_values, $params{$key} );
131 $query .= join( ',', @query_keys );
134 $query .= " WHERE course_id = ?";
135 push( @query_values, $course_id );
138 $dbh->do( $query, undef, @query_values );
140 $course_id = $course_id
141 || $dbh->last_insert_id( undef, undef, 'courses', 'course_id' );
143 EnableOrDisableCourseItems
(
144 course_id
=> $course_id,
145 enabled
=> $params{'enabled'}
153 @courses = GetCourses( [ fieldname => $value ] [, fieldname2 => $value2 ] [etc...] );
159 warn identify_myself
(%params) if $DEBUG;
167 LEFT JOIN course_reserves ON course_reserves.course_id = courses.course_id
168 LEFT JOIN course_items ON course_items.ci_id = course_reserves.ci_id
171 if ( keys %params ) {
175 foreach my $key ( keys %params ) {
176 push( @query_keys, " $key LIKE ? " );
177 push( @query_values, $params{$key} );
180 $query .= join( ' AND ', @query_keys );
183 $query .= " GROUP BY courses.course_id ";
185 my $dbh = C4
::Context
->dbh;
186 my $sth = $dbh->prepare($query);
187 $sth->execute(@query_values);
189 my $courses = $sth->fetchall_arrayref( {} );
191 foreach my $c (@
$courses) {
192 $c->{'instructors'} = GetCourseInstructors
( $c->{'course_id'} );
200 DelCourse( $course_id );
205 my ($course_id) = @_;
207 my $course_reserves = GetCourseReserves
( course_id
=> $course_id );
209 foreach my $res (@
$course_reserves) {
210 DelCourseReserve
( cr_id
=> $res->{'cr_id'} );
214 DELETE FROM course_instructors
217 C4
::Context
->dbh->do( $query, undef, $course_id );
223 C4
::Context
->dbh->do( $query, undef, $course_id );
226 =head2 EnableOrDisableCourseItems
228 EnableOrDisableCourseItems( course_id => $course_id, enabled => $enabled );
230 For each item on reserve for this course,
231 if the course item has no active course reserves,
232 swap the fields for the item to make it 'normal'
235 enabled => 'yes' to enable course items
236 enabled => 'no' to disable course items
240 sub EnableOrDisableCourseItems
{
242 warn identify_myself
(%params) if $DEBUG;
244 my $course_id = $params{'course_id'};
245 my $enabled = $params{'enabled'} || 0;
247 my $lookfor = ( $enabled eq 'yes' ) ?
'no' : 'yes';
249 return unless ( $course_id && $enabled );
250 return unless ( $enabled eq 'yes' || $enabled eq 'no' );
252 my $course_reserves = GetCourseReserves
( course_id
=> $course_id );
254 if ( $enabled eq 'yes' ) {
255 foreach my $course_reserve (@
$course_reserves) {
256 if (CountCourseReservesForItem
(
257 ci_id
=> $course_reserve->{'ci_id'},
261 EnableOrDisableCourseItem
(
262 ci_id
=> $course_reserve->{'ci_id'},
267 if ( $enabled eq 'no' ) {
268 foreach my $course_reserve (@
$course_reserves) {
270 CountCourseReservesForItem
(
271 ci_id
=> $course_reserve->{'ci_id'},
275 EnableOrDisableCourseItem
(
276 ci_id
=> $course_reserve->{'ci_id'},
283 =head2 EnableOrDisableCourseItem
285 EnableOrDisableCourseItem( ci_id => $ci_id );
289 sub EnableOrDisableCourseItem
{
291 warn identify_myself
(%params) if $DEBUG;
293 my $ci_id = $params{'ci_id'};
295 return unless ( $ci_id );
297 my $course_item = GetCourseItem
( ci_id
=> $ci_id );
299 my $info = GetItemCourseReservesInfo
( itemnumber
=> $course_item->{itemnumber
} );
301 my $enabled = any
{ $_->{course
}->{enabled
} eq 'yes' } @
$info;
302 $enabled = $enabled ?
'yes' : 'no';
304 ## We don't want to 'enable' an already enabled item,
305 ## or disable and already disabled item,
306 ## as that would cause the fields to swap
307 if ( $course_item->{'enabled'} ne $enabled ) {
308 _SwapAllFields
($ci_id);
316 C4
::Context
->dbh->do( $query, undef, $enabled, $ci_id );
322 =head2 GetCourseInstructors
324 @$borrowers = GetCourseInstructors( $course_id );
328 sub GetCourseInstructors
{
329 my ($course_id) = @_;
330 warn "C4::CourseReserves::GetCourseInstructors( $course_id )"
334 SELECT * FROM borrowers
335 RIGHT JOIN course_instructors ON ( course_instructors.borrowernumber = borrowers.borrowernumber )
336 WHERE course_instructors.course_id = ?
339 my $dbh = C4
::Context
->dbh;
340 my $sth = $dbh->prepare($query);
341 $sth->execute($course_id);
343 return $sth->fetchall_arrayref( {} );
346 =head2 ModCourseInstructors
348 ModCourseInstructors( mode => $mode, course_id => $course_id, [ cardnumbers => $cardnumbers ] OR [ borrowernumbers => $borrowernumbers );
350 $mode can be 'replace', 'add', or 'delete'
352 $cardnumbers and $borrowernumbers are both references to arrays
354 Use either cardnumbers or borrowernumber, but not both.
358 sub ModCourseInstructors
{
360 warn identify_myself
(%params) if $DEBUG;
362 my $course_id = $params{'course_id'};
363 my $mode = $params{'mode'};
364 my $cardnumbers = $params{'cardnumbers'};
365 my $borrowernumbers = $params{'borrowernumbers'};
367 return unless ($course_id);
369 unless ( $mode eq 'replace'
371 || $mode eq 'delete' );
372 return unless ( $cardnumbers || $borrowernumbers );
373 return if ( $cardnumbers && $borrowernumbers );
375 my ( @cardnumbers, @borrowernumbers );
376 @cardnumbers = @
$cardnumbers if ( ref($cardnumbers) eq 'ARRAY' );
377 @borrowernumbers = @
$borrowernumbers
378 if ( ref($borrowernumbers) eq 'ARRAY' );
380 my $field = (@cardnumbers) ?
'cardnumber' : 'borrowernumber';
381 my @fields = (@cardnumbers) ?
@cardnumbers : @borrowernumbers;
382 my $placeholders = join( ',', ('?') x
scalar @fields );
384 my $dbh = C4
::Context
->dbh;
386 $dbh->do( "DELETE FROM course_instructors WHERE course_id = ?", undef, $course_id )
387 if ( $mode eq 'replace' );
391 if ( $mode eq 'add' || $mode eq 'replace' ) {
393 INSERT INTO course_instructors ( course_id, borrowernumber )
394 SELECT ?, borrowernumber
396 WHERE $field IN ( $placeholders )
400 DELETE FROM course_instructors
402 AND borrowernumber IN (
403 SELECT borrowernumber FROM borrowers WHERE $field IN ( $placeholders )
408 my $sth = $dbh->prepare($query);
410 $sth->execute( $course_id, @fields ) if (@fields);
413 =head2 GetCourseItem {
415 $course_item = GetCourseItem( itemnumber => $itemnumber [, ci_id => $ci_id );
421 warn identify_myself
(%params) if $DEBUG;
423 my $ci_id = $params{'ci_id'};
424 my $itemnumber = $params{'itemnumber'};
426 return unless ( $itemnumber || $ci_id );
428 my $field = ($itemnumber) ?
'itemnumber' : 'ci_id';
429 my $value = ($itemnumber) ?
$itemnumber : $ci_id;
431 my $query = "SELECT * FROM course_items WHERE $field = ?";
432 my $dbh = C4
::Context
->dbh;
433 my $sth = $dbh->prepare($query);
434 $sth->execute($value);
436 my $course_item = $sth->fetchrow_hashref();
439 $query = "SELECT * FROM course_reserves WHERE ci_id = ?";
440 $sth = $dbh->prepare($query);
441 $sth->execute( $course_item->{'ci_id'} );
442 my $course_reserves = $sth->fetchall_arrayref( {} );
444 $course_item->{'course_reserves'} = $course_reserves
445 if ($course_reserves);
450 =head2 ModCourseItem {
452 ModCourseItem( %params );
454 Creates or modifies an existing course item.
460 warn identify_myself
(%params) if $DEBUG;
462 my $itemnumber = $params{'itemnumber'};
463 my $itype = $params{'itype'};
464 my $ccode = $params{'ccode'};
465 my $holdingbranch = $params{'holdingbranch'};
466 my $location = $params{'location'};
468 return unless ($itemnumber);
470 my $course_item = GetCourseItem
( itemnumber
=> $itemnumber );
475 $ci_id = $course_item->{'ci_id'};
479 course_item
=> $course_item,
483 $ci_id = _AddCourseItem
(%params);
490 =head2 _AddCourseItem
492 my $ci_id = _AddCourseItem( %params );
498 warn identify_myself
(%params) if $DEBUG;
500 my ( @fields, @values );
502 push( @fields, 'itemnumber = ?' );
503 push( @values, $params{'itemnumber'} );
507 push( @fields, "$_ = ?" );
508 push( @values, $params{$_} );
512 my $query = "INSERT INTO course_items SET " . join( ',', @fields );
513 my $dbh = C4
::Context
->dbh;
514 $dbh->do( $query, undef, @values );
516 my $ci_id = $dbh->last_insert_id( undef, undef, 'course_items', 'ci_id' );
521 =head2 _UpdateCourseItem
523 _UpdateCourseItem( %params );
527 sub _UpdateCourseItem
{
529 warn identify_myself
(%params) if $DEBUG;
531 my $ci_id = $params{'ci_id'};
532 my $course_item = $params{'course_item'};
533 my $itype = $params{'itype'};
534 my $ccode = $params{'ccode'};
535 my $holdingbranch = $params{'holdingbranch'};
536 my $location = $params{'location'};
538 return unless ( $ci_id || $course_item );
540 $course_item = GetCourseItem
( ci_id
=> $ci_id )
541 unless ($course_item);
542 $ci_id = $course_item->{'ci_id'} unless ($ci_id);
544 ## Revert fields that had an 'original' value, but now don't
545 ## Update the item fields to the stored values from course_items
546 ## and then set those fields in course_items to NULL
547 my @fields_to_revert;
549 if ( !$params{$_} && $course_item->{$_} ) {
550 push( @fields_to_revert, $_ );
555 fields
=> \
@fields_to_revert,
556 course_item
=> $course_item
557 ) if (@fields_to_revert);
559 ## Update fields that still have an original value, but it has changed
560 ## This necessitates only changing the current item values, as we still
561 ## have the original values stored in course_items
565 && $course_item->{$_}
566 && $params{$_} ne $course_item->{$_} ) {
567 $mod_params{$_} = $params{$_};
570 ModItem
( \
%mod_params, undef, $course_item->{'itemnumber'} ) if %mod_params;
572 ## Update fields that didn't have an original value, but now do
573 ## We must save the original value in course_items, and also
574 ## update the item fields to the new value
575 my $item = GetItem
( $course_item->{'itemnumber'} );
579 if ( $params{$_} && !$course_item->{$_} ) {
580 $mod_params_new{$_} = $params{$_};
581 $mod_params_old{$_} = $item->{$_};
584 _ModStoredFields
( 'ci_id' => $params{'ci_id'}, %mod_params_old );
585 ModItem
( \
%mod_params_new, undef, $course_item->{'itemnumber'} ) if %mod_params_new;
589 =head2 _ModStoredFields
591 _ModStoredFields( %params );
593 Updates the values for the 'original' fields in course_items
598 sub _ModStoredFields
{
600 warn identify_myself
(%params) if $DEBUG;
602 return unless ( $params{'ci_id'} );
604 my ( @fields_to_update, @values_to_update );
608 push( @fields_to_update, $_ );
609 push( @values_to_update, $params{$_} );
613 my $query = "UPDATE course_items SET " . join( ',', map { "$_=?" } @fields_to_update ) . " WHERE ci_id = ?";
615 C4
::Context
->dbh->do( $query, undef, @values_to_update, $params{'ci_id'} )
616 if (@values_to_update);
622 _RevertFields( ci_id => $ci_id, fields => \@fields_to_revert );
628 warn identify_myself
(%params) if $DEBUG;
630 my $ci_id = $params{'ci_id'};
631 my $course_item = $params{'course_item'};
632 my $fields = $params{'fields'};
633 my @fields = @
$fields;
635 return unless ($ci_id);
637 $course_item = GetCourseItem
( ci_id
=> $params{'ci_id'} )
638 unless ($course_item);
642 foreach my $field (@fields) {
644 if ( $field eq $_ && $course_item->{$_} ) {
645 $mod_item_params->{$_} = $course_item->{$_};
646 push( @fields_to_null, $_ );
650 ModItem
( $mod_item_params, undef, $course_item->{'itemnumber'} ) if $mod_item_params && %$mod_item_params;
652 my $query = "UPDATE course_items SET " . join( ',', map { "$_=NULL" } @fields_to_null ) . " WHERE ci_id = ?";
654 C4
::Context
->dbh->do( $query, undef, $ci_id ) if (@fields_to_null);
657 =head2 _SwapAllFields
659 _SwapAllFields( $ci_id );
665 warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
667 my $course_item = GetCourseItem
( ci_id
=> $ci_id );
668 my $item = GetItem
( $course_item->{'itemnumber'} );
670 my %course_item_fields;
673 if ( $course_item->{$_} ) {
674 $course_item_fields{$_} = $course_item->{$_};
675 $item_fields{$_} = $item->{$_};
679 ModItem
( \
%course_item_fields, undef, $course_item->{'itemnumber'} ) if %course_item_fields;
680 _ModStoredFields
( %item_fields, ci_id
=> $ci_id );
683 =head2 GetCourseItems {
685 $course_items = GetCourseItems(
686 [course_id => $course_id]
687 [, itemnumber => $itemnumber ]
694 warn identify_myself
(%params) if $DEBUG;
696 my $course_id = $params{'course_id'};
697 my $itemnumber = $params{'itemnumber'};
699 return unless ($course_id);
704 my $query = "SELECT * FROM course_items";
706 if ( keys %params ) {
710 foreach my $key ( keys %params ) {
711 push( @query_keys, " $key LIKE ? " );
712 push( @query_values, $params{$key} );
715 $query .= join( ' AND ', @query_keys );
718 my $dbh = C4
::Context
->dbh;
719 my $sth = $dbh->prepare($query);
720 $sth->execute(@query_values);
722 return $sth->fetchall_arrayref( {} );
725 =head2 DelCourseItem {
727 DelCourseItem( ci_id => $cr_id );
733 warn identify_myself
(%params) if $DEBUG;
735 my $ci_id = $params{'ci_id'};
737 return unless ($ci_id);
739 _RevertFields
( ci_id
=> $ci_id, fields
=> \
@FIELDS );
742 DELETE FROM course_items
745 C4
::Context
->dbh->do( $query, undef, $ci_id );
748 =head2 GetCourseReserve {
750 $course_item = GetCourseReserve( %params );
754 sub GetCourseReserve
{
756 warn identify_myself
(%params) if $DEBUG;
758 my $cr_id = $params{'cr_id'};
759 my $course_id = $params{'course_id'};
760 my $ci_id = $params{'ci_id'};
762 return unless ( $cr_id || ( $course_id && $ci_id ) );
764 my $dbh = C4
::Context
->dbh;
769 SELECT * FROM course_reserves
772 $sth = $dbh->prepare($query);
773 $sth->execute($cr_id);
776 SELECT * FROM course_reserves
777 WHERE course_id = ? AND ci_id = ?
779 $sth = $dbh->prepare($query);
780 $sth->execute( $course_id, $ci_id );
783 my $course_reserve = $sth->fetchrow_hashref();
784 return $course_reserve;
787 =head2 ModCourseReserve
789 $id = ModCourseReserve( %params );
793 sub ModCourseReserve
{
795 warn identify_myself
(%params) if $DEBUG;
797 my $course_id = $params{'course_id'};
798 my $ci_id = $params{'ci_id'};
799 my $staff_note = $params{'staff_note'};
800 my $public_note = $params{'public_note'};
802 return unless ( $course_id && $ci_id );
804 my $course_reserve = GetCourseReserve
( course_id
=> $course_id, ci_id
=> $ci_id );
807 my $dbh = C4
::Context
->dbh;
809 if ($course_reserve) {
810 $cr_id = $course_reserve->{'cr_id'};
813 UPDATE course_reserves
814 SET staff_note = ?, public_note = ?
817 $dbh->do( $query, undef, $staff_note, $public_note, $cr_id );
820 INSERT INTO course_reserves SET
826 $dbh->do( $query, undef, $course_id, $ci_id, $staff_note, $public_note );
827 $cr_id = $dbh->last_insert_id( undef, undef, 'course_reserves', 'cr_id' );
830 EnableOrDisableCourseItem
(
831 ci_id
=> $params{'ci_id'},
837 =head2 GetCourseReserves {
839 $course_reserves = GetCourseReserves( %params );
846 include_courses => 1,
850 sub GetCourseReserves
{
852 warn identify_myself
(%params) if $DEBUG;
854 my $course_id = $params{'course_id'};
855 my $ci_id = $params{'ci_id'};
856 my $include_items = $params{'include_items'};
857 my $include_count = $params{'include_count'};
858 my $include_courses = $params{'include_courses'};
860 return unless ( $course_id || $ci_id );
862 my $field = ($course_id) ?
'course_id' : 'ci_id';
863 my $value = ($course_id) ?
$course_id : $ci_id;
866 SELECT cr.*, ci.itemnumber
867 FROM course_reserves cr, course_items ci
869 AND cr.ci_id = ci.ci_id
871 my $dbh = C4
::Context
->dbh;
872 my $sth = $dbh->prepare($query);
873 $sth->execute($value);
875 my $course_reserves = $sth->fetchall_arrayref( {} );
877 if ($include_items) {
878 foreach my $cr (@
$course_reserves) {
879 my $item = Koha
::Items
->find( $cr->{itemnumber
} );
880 my $biblio = $item->biblio;
881 my $biblioitem = $biblio->biblioitem;
882 $cr->{'course_item'} = GetCourseItem
( ci_id
=> $cr->{'ci_id'} );
883 $cr->{'item'} = $item;
884 $cr->{'biblio'} = $biblio;
885 $cr->{'biblioitem'} = $biblioitem;
886 $cr->{'issue'} = GetOpenIssue
( $cr->{'itemnumber'} );
890 if ($include_count) {
891 foreach my $cr (@
$course_reserves) {
892 $cr->{'reserves_count'} = CountCourseReservesForItem
( ci_id
=> $cr->{'ci_id'} );
896 if ($include_courses) {
897 foreach my $cr (@
$course_reserves) {
898 $cr->{'courses'} = GetCourses
( itemnumber
=> $cr->{'itemnumber'} );
902 return $course_reserves;
905 =head2 DelCourseReserve {
907 DelCourseReserve( cr_id => $cr_id );
911 sub DelCourseReserve
{
913 warn identify_myself
(%params) if $DEBUG;
915 my $cr_id = $params{'cr_id'};
917 return unless ($cr_id);
919 my $dbh = C4
::Context
->dbh;
921 my $course_reserve = GetCourseReserve
( cr_id
=> $cr_id );
924 DELETE FROM course_reserves
927 $dbh->do( $query, undef, $cr_id );
929 ## If there are no other course reserves for this item
930 ## delete the course_item as well
931 unless ( CountCourseReservesForItem
( ci_id
=> $course_reserve->{'ci_id'} ) ) {
932 DelCourseItem
( ci_id
=> $course_reserve->{'ci_id'} );
937 =head2 GetItemCourseReservesInfo
939 my $arrayref = GetItemCourseReservesInfo( itemnumber => $itemnumber );
941 For a given item, returns an arrayref of reserves hashrefs,
942 with a course hashref under the key 'course'
946 sub GetItemCourseReservesInfo
{
948 warn identify_myself
(%params) if $DEBUG;
950 my $itemnumber = $params{'itemnumber'};
952 return unless ($itemnumber);
954 my $course_item = GetCourseItem
( itemnumber
=> $itemnumber );
956 return unless ( keys %$course_item );
958 my $course_reserves = GetCourseReserves
( ci_id
=> $course_item->{'ci_id'} );
960 foreach my $cr (@
$course_reserves) {
961 $cr->{'course'} = GetCourse
( $cr->{'course_id'} );
964 return $course_reserves;
967 =head2 CountCourseReservesForItem
969 $bool = CountCourseReservesForItem( %params );
971 ci_id - course_item id
973 itemnumber - course_item itemnumber
975 enabled = 'yes' or 'no'
976 Optional, if not supplied, counts reserves
977 for both enabled and disabled courses
981 sub CountCourseReservesForItem
{
983 warn identify_myself
(%params) if $DEBUG;
985 my $ci_id = $params{'ci_id'};
986 my $itemnumber = $params{'itemnumber'};
987 my $enabled = $params{'enabled'};
989 return unless ( $ci_id || $itemnumber );
991 my $course_item = GetCourseItem
( ci_id
=> $ci_id, itemnumber
=> $itemnumber );
993 my @params = ( $course_item->{'ci_id'} );
994 push( @params, $enabled ) if ($enabled);
997 SELECT COUNT(*) AS count
998 FROM course_reserves cr
999 LEFT JOIN courses c ON ( c.course_id = cr.course_id )
1002 $query .= "AND c.enabled = ?" if ($enabled);
1004 my $dbh = C4
::Context
->dbh;
1005 my $sth = $dbh->prepare($query);
1006 $sth->execute(@params);
1008 my $row = $sth->fetchrow_hashref();
1010 return $row->{'count'};
1013 =head2 SearchCourses
1015 my $courses = SearchCourses( term => $search_term, enabled => 'yes' );
1021 warn identify_myself
(%params) if $DEBUG;
1023 my $term = $params{'term'};
1025 my $enabled = $params{'enabled'} || '%';
1028 my $query = "SELECT c.* FROM courses c";
1031 LEFT JOIN course_instructors ci
1032 ON ( c.course_id = ci.course_id )
1033 LEFT JOIN borrowers b
1034 ON ( ci.borrowernumber = b.borrowernumber )
1035 LEFT JOIN authorised_values av
1036 ON ( c.department = av.authorised_value )
1038 ( av.category = 'DEPARTMENT' OR av.category = 'TERM' )
1041 department LIKE ? OR
1042 course_number LIKE ? OR
1044 course_name LIKE ? OR
1046 public_note LIKE ? OR
1047 CONCAT(surname,' ',firstname) LIKE ? OR
1048 CONCAT(firstname,' ',surname) LIKE ? OR
1054 GROUP BY c.course_id
1059 @params = ($term) x
10;
1061 $query .= " ORDER BY department, course_number, section, term, course_name ";
1063 my $dbh = C4
::Context
->dbh;
1064 my $sth = $dbh->prepare($query);
1066 $sth->execute( @params, $enabled );
1068 my $courses = $sth->fetchall_arrayref( {} );
1070 foreach my $c (@
$courses) {
1071 $c->{'instructors'} = GetCourseInstructors
( $c->{'course_id'} );
1077 sub whoami
{ ( caller(1) )[3] }
1078 sub whowasi
{ ( caller(2) )[3] }
1080 sub stringify_params
{
1085 foreach my $key ( keys %params ) {
1086 $string .= " $key => " . $params{$key} . "\n";
1089 return "( $string )";
1092 sub identify_myself
{
1095 return whowasi
() . stringify_params
(%params);
1102 Kyle M Hall <kyle@bywatersolutions.com>