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::Circulation qw(GetOpenIssue);
26 use Koha::Course::Instructors;
27 use Koha::Course::Items;
28 use Koha::Course::Reserves;
30 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
54 &GetItemCourseReservesInfo
56 %EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
59 @FIELDS = ( 'itype', 'ccode', 'homebranch', 'holdingbranch', 'location' );
64 C4::CourseReserves - Koha course reserves module
68 use C4::CourseReserves;
72 This module deals with course reserves.
78 $course = GetCourse( $course_id );
84 warn whoami() . "( $course_id )" if $DEBUG;
86 my $course = Koha::Courses->find( $course_id );
87 return undef unless $course;
88 $course = $course->unblessed;
90 my $dbh = C4::Context->dbh;
92 SELECT b.* FROM course_instructors ci
93 LEFT JOIN borrowers b ON ( ci.borrowernumber = b.borrowernumber )
96 my $sth = $dbh->prepare($query);
97 $sth->execute($course_id);
98 $course->{'instructors'} = $sth->fetchall_arrayref( {} );
105 ModCourse( [ course_id => $id ] [, course_name => $course_name ] [etc...] );
111 warn identify_myself(%params) if $DEBUG;
113 my $dbh = C4::Context->dbh;
116 if ( defined $params{'course_id'} ) {
117 $course_id = $params{'course_id'};
118 delete $params{'course_id'};
126 $query .= ($course_id) ? ' UPDATE ' : ' INSERT ';
127 $query .= ' courses SET ';
129 foreach my $key ( keys %params ) {
130 push( @query_keys, "$key=?" );
131 push( @query_values, $params{$key} );
133 $query .= join( ',', @query_keys );
136 $query .= " WHERE course_id = ?";
137 push( @query_values, $course_id );
140 $dbh->do( $query, undef, @query_values );
142 $course_id = $course_id
143 || $dbh->last_insert_id( undef, undef, 'courses', 'course_id' );
145 EnableOrDisableCourseItems(
146 course_id => $course_id,
147 enabled => $params{'enabled'}
155 @courses = GetCourses( [ fieldname => $value ] [, fieldname2 => $value2 ] [etc...] );
161 warn identify_myself(%params) if $DEBUG;
167 SELECT c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp
169 LEFT JOIN course_reserves ON course_reserves.course_id = c.course_id
170 LEFT JOIN course_items ON course_items.ci_id = course_reserves.ci_id
173 if ( keys %params ) {
177 foreach my $key ( keys %params ) {
178 push( @query_keys, " $key LIKE ? " );
179 push( @query_values, $params{$key} );
182 $query .= join( ' AND ', @query_keys );
185 $query .= " GROUP BY c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp ";
187 my $dbh = C4::Context->dbh;
188 my $sth = $dbh->prepare($query);
189 $sth->execute(@query_values);
191 my $courses = $sth->fetchall_arrayref( {} );
193 foreach my $c (@$courses) {
194 $c->{'instructors'} = GetCourseInstructors( $c->{'course_id'} );
202 DelCourse( $course_id );
207 my ($course_id) = @_;
209 my $course_reserves = GetCourseReserves( course_id => $course_id );
211 foreach my $res (@$course_reserves) {
212 DelCourseReserve( cr_id => $res->{'cr_id'} );
216 DELETE FROM course_instructors
219 C4::Context->dbh->do( $query, undef, $course_id );
225 C4::Context->dbh->do( $query, undef, $course_id );
228 =head2 EnableOrDisableCourseItems
230 EnableOrDisableCourseItems( course_id => $course_id, enabled => $enabled );
232 For each item on reserve for this course,
233 if the course item has no active course reserves,
234 swap the fields for the item to make it 'normal'
237 enabled => 'yes' to enable course items
238 enabled => 'no' to disable course items
242 sub EnableOrDisableCourseItems {
244 warn identify_myself(%params) if $DEBUG;
246 my $course_id = $params{'course_id'};
247 my $enabled = $params{'enabled'} || 0;
249 my $lookfor = ( $enabled eq 'yes' ) ? 'no' : 'yes';
251 return unless ( $course_id && $enabled );
252 return unless ( $enabled eq 'yes' || $enabled eq 'no' );
254 my $course_reserves = GetCourseReserves( course_id => $course_id );
256 if ( $enabled eq 'yes' ) {
257 foreach my $course_reserve (@$course_reserves) {
258 if (CountCourseReservesForItem(
259 ci_id => $course_reserve->{'ci_id'},
263 EnableOrDisableCourseItem(
264 ci_id => $course_reserve->{'ci_id'},
269 if ( $enabled eq 'no' ) {
270 foreach my $course_reserve (@$course_reserves) {
272 CountCourseReservesForItem(
273 ci_id => $course_reserve->{'ci_id'},
277 EnableOrDisableCourseItem(
278 ci_id => $course_reserve->{'ci_id'},
285 =head2 EnableOrDisableCourseItem
287 EnableOrDisableCourseItem( ci_id => $ci_id );
291 sub EnableOrDisableCourseItem {
293 warn identify_myself(%params) if $DEBUG;
295 my $ci_id = $params{'ci_id'};
297 return unless ( $ci_id );
299 my $course_item = GetCourseItem( ci_id => $ci_id );
301 my $info = GetItemCourseReservesInfo( itemnumber => $course_item->{itemnumber} );
303 my $enabled = any { $_->{course}->{enabled} eq 'yes' } @$info;
304 $enabled = $enabled ? 'yes' : 'no';
306 ## We don't want to 'enable' an already enabled item,
307 ## or disable and already disabled item,
308 ## as that would cause the fields to swap
309 if ( $course_item->{'enabled'} ne $enabled ) {
310 _SwapAllFields($ci_id, $enabled );
318 C4::Context->dbh->do( $query, undef, $enabled, $ci_id );
324 =head2 GetCourseInstructors
326 @$borrowers = GetCourseInstructors( $course_id );
330 sub GetCourseInstructors {
331 my ($course_id) = @_;
332 warn "C4::CourseReserves::GetCourseInstructors( $course_id )"
336 SELECT * FROM borrowers
337 RIGHT JOIN course_instructors ON ( course_instructors.borrowernumber = borrowers.borrowernumber )
338 WHERE course_instructors.course_id = ?
341 my $dbh = C4::Context->dbh;
342 my $sth = $dbh->prepare($query);
343 $sth->execute($course_id);
345 return $sth->fetchall_arrayref( {} );
348 =head2 ModCourseInstructors
350 ModCourseInstructors( mode => $mode, course_id => $course_id, [ cardnumbers => $cardnumbers ] OR [ borrowernumbers => $borrowernumbers );
352 $mode can be 'replace', 'add', or 'delete'
354 $cardnumbers and $borrowernumbers are both references to arrays
356 Use either cardnumbers or borrowernumber, but not both.
360 sub ModCourseInstructors {
362 warn identify_myself(%params) if $DEBUG;
364 my $course_id = $params{'course_id'};
365 my $mode = $params{'mode'};
366 my $cardnumbers = $params{'cardnumbers'};
367 my $borrowernumbers = $params{'borrowernumbers'};
369 return unless ($course_id);
371 unless ( $mode eq 'replace'
373 || $mode eq 'delete' );
374 return unless ( $cardnumbers || $borrowernumbers );
375 return if ( $cardnumbers && $borrowernumbers );
377 my ( @cardnumbers, @borrowernumbers );
378 @cardnumbers = @$cardnumbers if ( ref($cardnumbers) eq 'ARRAY' );
379 @borrowernumbers = @$borrowernumbers
380 if ( ref($borrowernumbers) eq 'ARRAY' );
382 my $field = (@cardnumbers) ? 'cardnumber' : 'borrowernumber';
383 my @fields = (@cardnumbers) ? @cardnumbers : @borrowernumbers;
384 my $placeholders = join( ',', ('?') x scalar @fields );
386 my $dbh = C4::Context->dbh;
388 $dbh->do( "DELETE FROM course_instructors WHERE course_id = ?", undef, $course_id )
389 if ( $mode eq 'replace' );
393 if ( $mode eq 'add' || $mode eq 'replace' ) {
395 INSERT INTO course_instructors ( course_id, borrowernumber )
396 SELECT ?, borrowernumber
398 WHERE $field IN ( $placeholders )
402 DELETE FROM course_instructors
404 AND borrowernumber IN (
405 SELECT borrowernumber FROM borrowers WHERE $field IN ( $placeholders )
410 my $sth = $dbh->prepare($query);
412 $sth->execute( $course_id, @fields ) if (@fields);
415 =head2 GetCourseItem {
417 $course_item = GetCourseItem( itemnumber => $itemnumber [, ci_id => $ci_id );
423 warn identify_myself(%params) if $DEBUG;
425 my $ci_id = $params{'ci_id'};
426 my $itemnumber = $params{'itemnumber'};
428 return unless ( $itemnumber || $ci_id );
430 my $field = ($itemnumber) ? 'itemnumber' : 'ci_id';
431 my $value = ($itemnumber) ? $itemnumber : $ci_id;
433 my $query = "SELECT * FROM course_items WHERE $field = ?";
434 my $dbh = C4::Context->dbh;
435 my $sth = $dbh->prepare($query);
436 $sth->execute($value);
438 my $course_item = $sth->fetchrow_hashref();
441 $query = "SELECT * FROM course_reserves WHERE ci_id = ?";
442 $sth = $dbh->prepare($query);
443 $sth->execute( $course_item->{'ci_id'} );
444 my $course_reserves = $sth->fetchall_arrayref( {} );
446 $course_item->{'course_reserves'} = $course_reserves
447 if ($course_reserves);
452 =head2 ModCourseItem {
454 ModCourseItem( %params );
456 Creates or modifies an existing course item.
462 warn identify_myself(%params) if $DEBUG;
464 my $itemnumber = $params{'itemnumber'};
466 return unless ($itemnumber);
468 my $course_item = GetCourseItem( itemnumber => $itemnumber );
473 $ci_id = $course_item->{'ci_id'};
477 course_item => $course_item,
481 $ci_id = _AddCourseItem(%params);
488 =head2 _AddCourseItem
490 my $ci_id = _AddCourseItem( %params );
496 warn identify_myself(%params) if $DEBUG;
498 $params{homebranch} ||= undef; # Can't be empty string, FK constraint
499 $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint
501 my %data = map { $_ => $params{$_} } @FIELDS;
502 my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS;
504 my $ci = Koha::Course::Item->new(
506 itemnumber => $params{itemnumber},
515 =head2 _UpdateCourseItem
517 _UpdateCourseItem( %params );
521 sub _UpdateCourseItem {
523 warn identify_myself(%params) if $DEBUG;
525 my $ci_id = $params{'ci_id'};
526 my $course_item = $params{'course_item'};
528 $params{homebranch} ||= undef; # Can't be empty string, FK constraint
529 $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint
531 return unless ( $ci_id || $course_item );
533 $course_item = Koha::Course::Items->find( $ci_id || $course_item->{ci_id} );
535 my %data = map { $_ => $params{$_} } @FIELDS;
536 my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS;
538 $course_item->update( { %data, %enabled } );
539 if ( $course_item->is_enabled ) {
540 my $item_fields = {};
541 $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled;
542 $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled;
543 $item_fields->{location} = $course_item->location if $course_item->location_enabled;
544 $item_fields->{homebranch} = $course_item->homebranch if $course_item->homebranch_enabled;
545 $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled;
547 Koha::Items->find( $course_item->itemnumber )
548 ->set( $item_fields )
550 if keys %$item_fields;
558 _RevertFields( ci_id => $ci_id, fields => \@fields_to_revert );
560 Copies fields from course item storage back to the actual item
566 warn identify_myself(%params) if $DEBUG;
568 my $ci_id = $params{'ci_id'};
570 return unless $ci_id;
572 my $course_item = Koha::Course::Items->find( $ci_id );
574 my $item_fields = {};
575 $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled;
576 $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled;
577 $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled;
578 $item_fields->{homebranch} = $course_item->homebranch_storage if $course_item->homebranch_enabled;
579 $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled;
581 Koha::Items->find( $course_item->itemnumber )
582 ->set( $item_fields )
584 if keys %$item_fields;
586 $course_item->itype_storage(undef);
587 $course_item->ccode_storage(undef);
588 $course_item->location_storage(undef);
589 $course_item->homebranch_storage(undef);
590 $course_item->holdingbranch_storage(undef);
591 $course_item->store();
594 =head2 _SwapAllFields
596 _SwapAllFields( $ci_id );
601 my ( $ci_id, $enabled ) = @_;
602 warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
604 my $course_item = Koha::Course::Items->find( $ci_id );
605 my $item = Koha::Items->find( $course_item->itemnumber );
607 if ( $enabled eq 'yes' ) { # Copy item fields to course item storage, course item fields to item
608 $course_item->itype_storage( $item->effective_itemtype ) if $course_item->itype_enabled;
609 $course_item->ccode_storage( $item->ccode ) if $course_item->ccode_enabled;
610 $course_item->location_storage( $item->location ) if $course_item->location_enabled;
611 $course_item->homebranch_storage( $item->homebranch ) if $course_item->homebranch_enabled;
612 $course_item->holdingbranch_storage( $item->holdingbranch ) if $course_item->holdingbranch_enabled;
613 $course_item->store();
615 my $item_fields = {};
616 $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled;
617 $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled;
618 $item_fields->{location} = $course_item->location if $course_item->location_enabled;
619 $item_fields->{homebranch} = $course_item->homebranch if $course_item->homebranch_enabled;
620 $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled;
622 Koha::Items->find( $course_item->itemnumber )
623 ->set( $item_fields )
625 if keys %$item_fields;
627 } else { # Copy course item storage to item
628 my $item_fields = {};
629 $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled;
630 $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled;
631 $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled;
632 $item_fields->{homebranch} = $course_item->homebranch_storage if $course_item->homebranch_enabled;
633 $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled;
635 Koha::Items->find( $course_item->itemnumber )
636 ->set( $item_fields )
638 if keys %$item_fields;
640 $course_item->itype_storage(undef);
641 $course_item->ccode_storage(undef);
642 $course_item->location_storage(undef);
643 $course_item->homebranch_storage(undef);
644 $course_item->holdingbranch_storage(undef);
645 $course_item->store();
649 =head2 GetCourseItems {
651 $course_items = GetCourseItems(
652 [course_id => $course_id]
653 [, itemnumber => $itemnumber ]
660 warn identify_myself(%params) if $DEBUG;
662 my $course_id = $params{'course_id'};
663 my $itemnumber = $params{'itemnumber'};
665 return unless ($course_id);
670 my $query = "SELECT * FROM course_items";
672 if ( keys %params ) {
676 foreach my $key ( keys %params ) {
677 push( @query_keys, " $key LIKE ? " );
678 push( @query_values, $params{$key} );
681 $query .= join( ' AND ', @query_keys );
684 my $dbh = C4::Context->dbh;
685 my $sth = $dbh->prepare($query);
686 $sth->execute(@query_values);
688 return $sth->fetchall_arrayref( {} );
691 =head2 DelCourseItem {
693 DelCourseItem( ci_id => $cr_id );
699 warn identify_myself(%params) if $DEBUG;
701 my $ci_id = $params{'ci_id'};
703 return unless ($ci_id);
705 my $course_item = Koha::Course::Items->find( $ci_id );
706 return unless $course_item;
708 _RevertFields( ci_id => $ci_id ) if $course_item->enabled eq 'yes';
711 DELETE FROM course_items
714 C4::Context->dbh->do( $query, undef, $ci_id );
717 =head2 GetCourseReserve {
719 $course_item = GetCourseReserve( %params );
723 sub GetCourseReserve {
725 warn identify_myself(%params) if $DEBUG;
727 my $cr_id = $params{'cr_id'};
728 my $course_id = $params{'course_id'};
729 my $ci_id = $params{'ci_id'};
731 return unless ( $cr_id || ( $course_id && $ci_id ) );
733 my $dbh = C4::Context->dbh;
738 SELECT * FROM course_reserves
741 $sth = $dbh->prepare($query);
742 $sth->execute($cr_id);
745 SELECT * FROM course_reserves
746 WHERE course_id = ? AND ci_id = ?
748 $sth = $dbh->prepare($query);
749 $sth->execute( $course_id, $ci_id );
752 my $course_reserve = $sth->fetchrow_hashref();
753 return $course_reserve;
756 =head2 ModCourseReserve
758 $id = ModCourseReserve( %params );
762 sub ModCourseReserve {
764 warn identify_myself(%params) if $DEBUG;
766 my $course_id = $params{'course_id'};
767 my $ci_id = $params{'ci_id'};
768 my $staff_note = $params{'staff_note'};
769 my $public_note = $params{'public_note'};
771 return unless ( $course_id && $ci_id );
773 my $course_reserve = GetCourseReserve( course_id => $course_id, ci_id => $ci_id );
776 my $dbh = C4::Context->dbh;
778 if ($course_reserve) {
779 $cr_id = $course_reserve->{'cr_id'};
782 UPDATE course_reserves
783 SET staff_note = ?, public_note = ?
786 $dbh->do( $query, undef, $staff_note, $public_note, $cr_id );
789 INSERT INTO course_reserves SET
795 $dbh->do( $query, undef, $course_id, $ci_id, $staff_note, $public_note );
796 $cr_id = $dbh->last_insert_id( undef, undef, 'course_reserves', 'cr_id' );
799 EnableOrDisableCourseItem(
800 ci_id => $params{'ci_id'},
806 =head2 GetCourseReserves {
808 $course_reserves = GetCourseReserves( %params );
815 include_courses => 1,
819 sub GetCourseReserves {
821 warn identify_myself(%params) if $DEBUG;
823 my $course_id = $params{'course_id'};
824 my $ci_id = $params{'ci_id'};
825 my $include_items = $params{'include_items'};
826 my $include_count = $params{'include_count'};
827 my $include_courses = $params{'include_courses'};
829 return unless ( $course_id || $ci_id );
831 my $field = ($course_id) ? 'course_id' : 'ci_id';
832 my $value = ($course_id) ? $course_id : $ci_id;
835 SELECT cr.*, ci.itemnumber
836 FROM course_reserves cr, course_items ci
838 AND cr.ci_id = ci.ci_id
840 my $dbh = C4::Context->dbh;
841 my $sth = $dbh->prepare($query);
842 $sth->execute($value);
844 my $course_reserves = $sth->fetchall_arrayref( {} );
846 if ($include_items) {
847 foreach my $cr (@$course_reserves) {
848 my $item = Koha::Items->find( $cr->{itemnumber} );
849 my $biblio = $item->biblio;
850 my $biblioitem = $biblio->biblioitem;
851 $cr->{'course_item'} = GetCourseItem( ci_id => $cr->{'ci_id'} );
852 $cr->{'item'} = $item;
853 $cr->{'biblio'} = $biblio;
854 $cr->{'biblioitem'} = $biblioitem;
855 $cr->{'issue'} = GetOpenIssue( $cr->{'itemnumber'} );
859 if ($include_count) {
860 foreach my $cr (@$course_reserves) {
861 $cr->{'reserves_count'} = CountCourseReservesForItem( ci_id => $cr->{'ci_id'} );
865 if ($include_courses) {
866 foreach my $cr (@$course_reserves) {
867 $cr->{'courses'} = GetCourses( itemnumber => $cr->{'itemnumber'} );
871 return $course_reserves;
874 =head2 DelCourseReserve {
876 DelCourseReserve( cr_id => $cr_id );
880 sub DelCourseReserve {
882 warn identify_myself(%params) if $DEBUG;
884 my $cr_id = $params{'cr_id'};
886 return unless ($cr_id);
888 my $dbh = C4::Context->dbh;
890 my $course_reserve = GetCourseReserve( cr_id => $cr_id );
893 DELETE FROM course_reserves
896 $dbh->do( $query, undef, $cr_id );
898 ## If there are no other course reserves for this item
899 ## delete the course_item as well
900 unless ( CountCourseReservesForItem( ci_id => $course_reserve->{'ci_id'} ) ) {
901 DelCourseItem( ci_id => $course_reserve->{'ci_id'} );
906 =head2 GetItemCourseReservesInfo
908 my $arrayref = GetItemCourseReservesInfo( itemnumber => $itemnumber );
910 For a given item, returns an arrayref of reserves hashrefs,
911 with a course hashref under the key 'course'
915 sub GetItemCourseReservesInfo {
917 warn identify_myself(%params) if $DEBUG;
919 my $itemnumber = $params{'itemnumber'};
921 return unless ($itemnumber);
923 my $course_item = GetCourseItem( itemnumber => $itemnumber );
925 return unless ( keys %$course_item );
927 my $course_reserves = GetCourseReserves( ci_id => $course_item->{'ci_id'} );
929 foreach my $cr (@$course_reserves) {
930 $cr->{'course'} = GetCourse( $cr->{'course_id'} );
933 return $course_reserves;
936 =head2 CountCourseReservesForItem
938 $bool = CountCourseReservesForItem( %params );
940 ci_id - course_item id
942 itemnumber - course_item itemnumber
944 enabled = 'yes' or 'no'
945 Optional, if not supplied, counts reserves
946 for both enabled and disabled courses
950 sub CountCourseReservesForItem {
952 warn identify_myself(%params) if $DEBUG;
954 my $ci_id = $params{'ci_id'};
955 my $itemnumber = $params{'itemnumber'};
956 my $enabled = $params{'enabled'};
958 return unless ( $ci_id || $itemnumber );
960 my $course_item = GetCourseItem( ci_id => $ci_id, itemnumber => $itemnumber );
962 my @params = ( $course_item->{'ci_id'} );
963 push( @params, $enabled ) if ($enabled);
966 SELECT COUNT(*) AS count
967 FROM course_reserves cr
968 LEFT JOIN courses c ON ( c.course_id = cr.course_id )
971 $query .= "AND c.enabled = ?" if ($enabled);
973 my $dbh = C4::Context->dbh;
974 my $sth = $dbh->prepare($query);
975 $sth->execute(@params);
977 my $row = $sth->fetchrow_hashref();
979 return $row->{'count'};
984 my $courses = SearchCourses( term => $search_term, enabled => 'yes' );
990 warn identify_myself(%params) if $DEBUG;
992 my $term = $params{'term'};
994 my $enabled = $params{'enabled'} || '%';
998 SELECT c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp
1000 LEFT JOIN course_instructors ci
1001 ON ( c.course_id = ci.course_id )
1002 LEFT JOIN borrowers b
1003 ON ( ci.borrowernumber = b.borrowernumber )
1004 LEFT JOIN authorised_values av
1005 ON ( c.department = av.authorised_value )
1007 ( av.category = 'DEPARTMENT' OR av.category = 'TERM' )
1010 department LIKE ? OR
1011 course_number LIKE ? OR
1013 course_name LIKE ? OR
1015 public_note LIKE ? OR
1016 CONCAT(surname,' ',firstname) LIKE ? OR
1017 CONCAT(firstname,' ',surname) LIKE ? OR
1023 GROUP BY c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp
1028 @params = ($term) x 10;
1030 $query .= " ORDER BY department, course_number, section, term, course_name ";
1032 my $dbh = C4::Context->dbh;
1033 my $sth = $dbh->prepare($query);
1035 $sth->execute( @params, $enabled );
1037 my $courses = $sth->fetchall_arrayref( {} );
1039 foreach my $c (@$courses) {
1040 $c->{'instructors'} = GetCourseInstructors( $c->{'course_id'} );
1046 sub whoami { ( caller(1) )[3] }
1047 sub whowasi { ( caller(2) )[3] }
1049 sub stringify_params {
1054 foreach my $key ( keys %params ) {
1055 $string .= " $key => " . $params{$key} . "\n";
1058 return "( $string )";
1061 sub identify_myself {
1064 return whowasi() . stringify_params(%params);
1071 Kyle M Hall <kyle@bywatersolutions.com>