|
Lines 5-18
use List::Util qw( first );
Link Here
|
| 5 |
use YAML; |
5 |
use YAML; |
| 6 |
use C4::Context; |
6 |
use C4::Context; |
| 7 |
use Koha::Database; |
7 |
use Koha::Database; |
|
|
8 |
use Koha::Cache; |
| 8 |
|
9 |
|
| 9 |
sub get_yaml { |
10 |
sub get_yaml { |
| 10 |
my $yml_path = |
11 |
my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; |
| 11 |
C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; |
12 |
|
| 12 |
my $yaml = eval { YAML::LoadFile($yml_path) }; |
13 |
my $cache = Koha::Cache->get_instance(); |
| 13 |
warn |
14 |
my $yaml = $cache->get_from_cache('ColumnsSettingsYaml'); |
| 14 |
"ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@" |
15 |
unless ($yaml) { |
| 15 |
if $@; |
16 |
$yaml = eval { YAML::LoadFile($yml_path) }; |
|
|
17 |
warn "############################# Not In Cache #############################" if $ENV{DEBUG}; |
| 18 |
warn "ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@" |
| 19 |
if $@; |
| 20 |
$cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } ); |
| 21 |
} else { |
| 22 |
warn "############################# In Cache #############################" if $ENV{DEBUG}; |
| 23 |
} |
| 16 |
return $yaml; |
24 |
return $yaml; |
| 17 |
} |
25 |
} |
| 18 |
|
26 |
|
|
Lines 24-39
sub get_columns {
Link Here
|
| 24 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
| 25 |
|
33 |
|
| 26 |
my $rs = $schema->resultset('ColumnsSetting')->search( |
34 |
my $rs = $schema->resultset('ColumnsSetting')->search( |
| 27 |
{ |
35 |
{ module => $module, |
| 28 |
module => $module, |
|
|
| 29 |
page => $page, |
36 |
page => $page, |
| 30 |
tablename => $tablename, |
37 |
tablename => $tablename, |
| 31 |
} |
38 |
} |
| 32 |
); |
39 |
); |
| 33 |
|
40 |
|
| 34 |
while ( my $c = $rs->next ) { |
41 |
while ( my $c = $rs->next ) { |
| 35 |
my $column = first { $c->columnname eq $_->{columnname} } |
42 |
my $column = first { $c->columnname eq $_->{columnname} } @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; |
| 36 |
@{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; |
|
|
| 37 |
$column->{is_hidden} = $c->is_hidden; |
43 |
$column->{is_hidden} = $c->is_hidden; |
| 38 |
$column->{cannot_be_toggled} = $c->cannot_be_toggled; |
44 |
$column->{cannot_be_toggled} = $c->cannot_be_toggled; |
| 39 |
} |
45 |
} |
|
Lines 48-55
sub get_modules {
Link Here
|
| 48 |
my $rs = $schema->resultset('ColumnsSetting')->search; |
54 |
my $rs = $schema->resultset('ColumnsSetting')->search; |
| 49 |
|
55 |
|
| 50 |
while ( my $c = $rs->next ) { |
56 |
while ( my $c = $rs->next ) { |
| 51 |
my $column = first { $c->columnname eq $_->{columnname} } |
57 |
my $column = first { $c->columnname eq $_->{columnname} } @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; |
| 52 |
@{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; |
|
|
| 53 |
$column->{is_hidden} = $c->is_hidden; |
58 |
$column->{is_hidden} = $c->is_hidden; |
| 54 |
$column->{cannot_be_toggled} = $c->cannot_be_toggled; |
59 |
$column->{cannot_be_toggled} = $c->cannot_be_toggled; |
| 55 |
} |
60 |
} |
|
Lines 68-78
sub update_columns {
Link Here
|
| 68 |
$c->{cannot_be_toggled} //= 0; |
73 |
$c->{cannot_be_toggled} //= 0; |
| 69 |
|
74 |
|
| 70 |
$schema->resultset('ColumnsSetting')->update_or_create( |
75 |
$schema->resultset('ColumnsSetting')->update_or_create( |
| 71 |
{ |
76 |
{ module => $c->{module}, |
| 72 |
module => $c->{module}, |
77 |
page => $c->{page}, |
| 73 |
page => $c->{page}, |
78 |
tablename => $c->{tablename}, |
| 74 |
tablename => $c->{tablename}, |
79 |
columnname => $c->{columnname}, |
| 75 |
columnname => $c->{columnname}, |
|
|
| 76 |
is_hidden => $c->{is_hidden}, |
80 |
is_hidden => $c->{is_hidden}, |
| 77 |
cannot_be_toggled => $c->{cannot_be_toggled}, |
81 |
cannot_be_toggled => $c->{cannot_be_toggled}, |
| 78 |
} |
82 |
} |
| 79 |
- |
|
|