Bugzilla – Attachment 192859 Details for
Bug 35972
Add a 'Research tables' feature, that builds upon Course reserves
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35972: Refactor C4::CourseReserves to use course_type
94dc6cf.patch (text/plain), 6.57 KB, created by
Martin Renvoize (ashimema)
on 2026-02-10 11:29:21 UTC
(
hide
)
Description:
Bug 35972: Refactor C4::CourseReserves to use course_type
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-10 11:29:21 UTC
Size:
6.57 KB
patch
obsolete
>From 94dc6cf8eb9c10baf9723562129e0ba81c44aa7d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Tue, 10 Feb 2026 09:27:42 +0000 >Subject: [PATCH] Bug 35972: Refactor C4::CourseReserves to use course_type >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch refactors the CourseReserves module to use the new >course_type column instead of hardcoded department='TT' checks. > >Changes to C4::CourseReserves: > >1. SearchCourses(): > - Now accepts course_type parameter instead of thesis_table > - Added backward compatibility for thesis_table parameter > - Removed hardcoded department='TT' filtering > - Updated SELECT to include course_type column > - Updated GROUP BY and ORDER BY to include course_type > >2. GetCourses(): > - Updated SELECT to include course_type column > - Updated GROUP BY to include course_type > >3. New function HasCoursesOfType(): > - Returns true if any courses of specified type exist > - Useful for conditional navigation display > - Respects enabled parameter > >Backward compatibility: >- thesis_table='yes' â course_type='RESEARCH_TABLE' >- thesis_table='no' â course_type='COURSE' >- Existing code using thesis_table parameter continues to work > >The refactoring removes all hardcoded assumptions about "thesis tables" >and makes the system flexible to support any course type defined via >authorized values. >--- > C4/CourseReserves.pm | 72 +++++++++++++++++++++++++++++++------------- > 1 file changed, 51 insertions(+), 21 deletions(-) > >diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm >index 27e7e3615ce..52bcdda6b77 100644 >--- a/C4/CourseReserves.pm >+++ b/C4/CourseReserves.pm >@@ -38,6 +38,7 @@ BEGIN { > DelCourseReserve > > SearchCourses >+ HasCoursesOfType > > GetItemCourseReservesInfo > ); >@@ -157,7 +158,7 @@ sub GetCourses { > my @query_values; > > my $query = " >- 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 >+ SELECT c.course_id, c.course_type, 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 > FROM courses c > LEFT JOIN course_reserves ON course_reserves.course_id = c.course_id > LEFT JOIN course_items ON course_items.ci_id = course_reserves.ci_id >@@ -176,7 +177,7 @@ sub GetCourses { > } > > $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 "; >+ " GROUP BY c.course_id, c.course_type, 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 "; > > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare($query); >@@ -1017,7 +1018,11 @@ sub CountCourseReservesForItem { > > =head2 SearchCourses > >- my $courses = SearchCourses( term => $search_term, enabled => 'yes', thesis_table => 'no' ); >+ my $courses = SearchCourses( term => $search_term, enabled => 'yes', course_type => 'COURSE' ); >+ my $courses = SearchCourses( term => $search_term, enabled => 'yes', course_type => 'RESEARCH_TABLE' ); >+ >+ # For backward compatibility (deprecated): >+ my $courses = SearchCourses( term => $search_term, enabled => 'yes', thesis_table => 'yes' ); > > =cut > >@@ -1026,12 +1031,25 @@ sub SearchCourses { > > my $term = $params{'term'}; > >- my $enabled = $params{'enabled'} || '%'; >- my $thesis_table = $params{'thesis_table'} || 'no'; >+ my $enabled = $params{'enabled'} || '%'; >+ >+ # Handle course_type parameter (new) or thesis_table parameter (deprecated for backward compatibility) >+ my $course_type; >+ if ( exists $params{'course_type'} ) { >+ $course_type = $params{'course_type'}; >+ } elsif ( exists $params{'thesis_table'} ) { >+ >+ # Backward compatibility: translate thesis_table to course_type >+ $course_type = $params{'thesis_table'} eq 'yes' ? 'RESEARCH_TABLE' : 'COURSE'; >+ } else { >+ >+ # Default to showing regular courses >+ $course_type = '%'; >+ } > > my @params; > my $query = " >- 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 >+ SELECT c.course_id, c.course_type, 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 > FROM courses c > LEFT JOIN course_instructors ci > ON ( c.course_id = ci.course_id ) >@@ -1056,34 +1074,24 @@ sub SearchCourses { > ) > AND > c.enabled LIKE ? >+ AND >+ c.course_type LIKE ? > "; > >- if ( $thesis_table eq 'no' ) { >- $query .= " >- AND >- c.department != 'TT' >- "; >- } else { >- $query .= " >- AND >- c.department = 'TT' >- "; >- } >- > $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 >+ GROUP BY c.course_id, c.course_type, 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 > "; > > $term //= ''; > $term = "%$term%"; > @params = ($term) x 10; > >- $query .= " ORDER BY department, course_number, section, term, course_name "; >+ $query .= " ORDER BY course_type, department, course_number, section, term, course_name "; > > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare($query); > >- $sth->execute( @params, $enabled ); >+ $sth->execute( @params, $enabled, $course_type ); > > my $courses = $sth->fetchall_arrayref( {} ); > >@@ -1094,6 +1102,28 @@ sub SearchCourses { > return $courses; > } > >+=head2 HasCoursesOfType >+ >+ my $has_research_tables = HasCoursesOfType( course_type => 'RESEARCH_TABLE', enabled => 'yes' ); >+ >+Returns true if any courses of the specified type exist. >+ >+=cut >+ >+sub HasCoursesOfType { >+ my (%params) = @_; >+ >+ my $course_type = $params{'course_type'} || return 0; >+ my $enabled = $params{'enabled'} || '%'; >+ >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare("SELECT COUNT(*) FROM courses WHERE course_type LIKE ? AND enabled LIKE ?"); >+ $sth->execute( $course_type, $enabled ); >+ >+ my ($count) = $sth->fetchrow_array(); >+ return $count > 0; >+} >+ > =head2 whoami > > Missing POD for whoami. >-- >2.53.0 >
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 35972
:
161714
|
161802
|
161803
|
192856
|
192857
|
192858
| 192859 |
192860
|
192861