1 package C4::Utils::DataTables::ColumnsSettings;
4 use List::Util qw( first );
11 my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
12 my $cache = Koha::Cache->get_instance();
13 my $yaml = $cache->get_from_cache('ColumnsSettingsYaml');
16 $yaml = eval { YAML::LoadFile($yml_path) };
17 warn "ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@"
19 $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
26 my ( $module, $page, $tablename ) = @_;
30 my $schema = Koha::Database->new->schema;
32 my $rs = $schema->resultset('ColumnsSetting')->search(
36 tablename => $tablename,
40 while ( my $c = $rs->next ) {
41 my $column = first { $c->columnname eq $_->{columnname} }
42 @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
43 $column->{is_hidden} = $c->is_hidden;
44 $column->{cannot_be_toggled} = $c->cannot_be_toggled;
47 my $columns = $list->{modules}{$module}{$page}{$tablename} || [];
49 # Assign default value if does not exist
52 cannot_be_toggled => exists $_->{cannot_be_toggled} ? $_->{cannot_be_toggled} : 0,
53 cannot_be_modified => exists $_->{cannot_be_modified} ? $_->{cannot_be_modified} : 0,
54 is_hidden => exists $_->{is_hidden} ? $_->{is_hidden} : 0,
55 columnname => $_->{columnname},
65 my $schema = Koha::Database->new->schema;
66 my $rs = $schema->resultset('ColumnsSetting')->search;
68 while ( my $c = $rs->next ) {
69 my $column = first { $c->columnname eq $_->{columnname} }
70 @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
71 $column->{is_hidden} = $c->is_hidden;
72 $column->{cannot_be_toggled} = $c->cannot_be_toggled;
73 $column->{cannot_be_modified} = 0
74 unless exists $column->{cannot_be_modified};
77 return $list->{modules};
82 my $columns = $params->{columns};
84 my $schema = Koha::Database->new->schema;
86 for my $c (@$columns) {
87 $c->{is_hidden} //= 0;
88 $c->{cannot_be_toggled} //= 0;
90 $schema->resultset('ColumnsSetting')->update_or_create(
92 module => $c->{module},
94 tablename => $c->{tablename},
95 columnname => $c->{columnname},
96 is_hidden => $c->{is_hidden},
97 cannot_be_toggled => $c->{cannot_be_toggled},