From a29879838456f1a0454f5568ac20b8027b0b6746 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 10 Feb 2026 09:27:27 +0000 Subject: [PATCH] Bug 35972: Add course_type column for flexible course displays This patch adds database infrastructure to support multiple course display types (course reserves, research tables, on display, etc.) instead of hardcoding "thesis tables" via department='TT'. Database changes: - Add course_type VARCHAR(80) column to courses table - Migrate existing department='TT' records to course_type='RESEARCH_TABLE' - Create CR_TYPE authorized value category with default values: * COURSE - Regular course reserves * RESEARCH_TABLE - Research/thesis tables * ON_DISPLAY - On display collections Schema changes: - Update kohastructure.sql with course_type column - Add CR_TYPE authorized values to sample data - Update Koha::Schema::Result::Course DBIx::Class schema This flexible architecture allows libraries to: - Customize terminology via authorized values (lib/lib_opac fields) - Add new display types without code changes - Support future features like Bug 12141 (On Display module) The course_type column uses authorized values from CR_TYPE category, with separate display text for staff interface (lib) and OPAC (lib_opac). --- Koha/Schema/Result/Course.pm | 11 +++ .../data/mysql/atomicupdate/bug_35972.pl | 70 +++++++++++++++++++ .../data/mysql/en/mandatory/auth_values.yml | 15 ++++ installer/data/mysql/kohastructure.sql | 1 + 4 files changed, 97 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_35972.pl diff --git a/Koha/Schema/Result/Course.pm b/Koha/Schema/Result/Course.pm index 29823d75dfd..fb28c0f977f 100644 --- a/Koha/Schema/Result/Course.pm +++ b/Koha/Schema/Result/Course.pm @@ -31,6 +31,15 @@ __PACKAGE__->table("courses"); unique id for the course +=head2 course_type + + data_type: 'varchar' + default_value: 'COURSE' + is_nullable: 1 + size: 80 + +the authorised value for CR_TYPE - determines display context (course reserve, research table, on display, etc.) + =head2 department data_type: 'varchar' @@ -114,6 +123,8 @@ determines whether the course is active __PACKAGE__->add_columns( "course_id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "course_type", + { data_type => "varchar", default_value => "COURSE", is_nullable => 1, size => 80 }, "department", { data_type => "varchar", is_nullable => 1, size => 80 }, "course_number", diff --git a/installer/data/mysql/atomicupdate/bug_35972.pl b/installer/data/mysql/atomicupdate/bug_35972.pl new file mode 100644 index 00000000000..b4b2fbdccd1 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35972.pl @@ -0,0 +1,70 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => "35972", + description => "Add course_type column to courses table for flexible course displays", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + unless ( column_exists( 'courses', 'course_type' ) ) { + say_info( $out, "Adding course_type column to courses table..." ); + + # Add the course_type column with default value 'COURSE' + $dbh->do( + q{ + ALTER TABLE courses + ADD COLUMN course_type VARCHAR(80) DEFAULT 'COURSE' + AFTER course_id + } + ); + + say_success( $out, "Added column 'courses.course_type'" ); + + # Migrate existing 'thesis tables' (department='TT') to new system + my $migrated_courses = $dbh->do( + q{ + UPDATE courses + SET course_type = 'RESEARCH_TABLE' + WHERE department = 'TT' + } + ); + + if ( $migrated_courses && $migrated_courses > 0 ) { + say_success( $out, "Migrated $migrated_courses thesis table(s) to course_type='RESEARCH_TABLE'" ); + } else { + say_info( $out, "No thesis tables (department='TT') found to migrate" ); + } + + # Add authorized value category for course types + $dbh->do( + q{ + INSERT IGNORE INTO authorised_value_categories (category_name, is_system) + VALUES ('CR_TYPE', 1) + } + ); + say_success( $out, "Added authorized value category 'CR_TYPE'" ); + + # Add default authorized values for course types + $dbh->do( + q{ + INSERT IGNORE INTO authorised_values (category, authorised_value, lib, lib_opac) + VALUES + ('CR_TYPE', 'COURSE', 'Course reserve', 'Course reserve'), + ('CR_TYPE', 'RESEARCH_TABLE', 'Research table', 'Research table'), + ('CR_TYPE', 'ON_DISPLAY', 'On display', 'On display') + } + ); + say_success( $out, "Added default course type authorized values" ); + + say_info( $out, "Course types can be customized in Administration > Authorized values > CR_TYPE" ); + say_info( $out, "The 'lib' field controls staff interface display text" ); + say_info( $out, "The 'lib_opac' field controls OPAC display text" ); + say_success( $out, "Migration complete: Course reserves now supports multiple display types" ); + + } else { + say_info( $out, "The course_type column already exists in the courses table." ); + } + }, +}; diff --git a/installer/data/mysql/en/mandatory/auth_values.yml b/installer/data/mysql/en/mandatory/auth_values.yml index 79897bc843b..c7d560d13bc 100644 --- a/installer/data/mysql/en/mandatory/auth_values.yml +++ b/installer/data/mysql/en/mandatory/auth_values.yml @@ -5739,3 +5739,18 @@ tables: authorised_value: "770" lib: "Writer of accompanying material" lib_opac: "Writer of accompanying material" + + - category: "CR_TYPE" + authorised_value: "COURSE" + lib: "Course reserve" + lib_opac: "Course reserve" + + - category: "CR_TYPE" + authorised_value: "RESEARCH_TABLE" + lib: "Research table" + lib_opac: "Research table" + + - category: "CR_TYPE" + authorised_value: "ON_DISPLAY" + lib: "On display" + lib_opac: "On display" diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index afbf3f58854..89cf5294783 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2311,6 +2311,7 @@ DROP TABLE IF EXISTS `courses`; /*!40101 SET character_set_client = utf8mb4 */; CREATE TABLE `courses` ( `course_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique id for the course', + `course_type` varchar(80) DEFAULT 'COURSE' COMMENT 'the authorised value for CR_TYPE - determines display context (course reserve, research table, on display, etc.)', `department` varchar(80) DEFAULT NULL COMMENT 'the authorised value for the DEPARTMENT', `course_number` varchar(255) DEFAULT NULL COMMENT 'the ''course number'' assigned to a course', `section` varchar(255) DEFAULT NULL COMMENT 'the ''section'' of a course', -- 2.53.0