Koha/C4/Utils/DataTables/ColumnsSettings.pm
Stefan Weil 64925f7522 Bug 14383: C4: Fix some typos (mostly in comments and documentation)
Most of them were found and fixed using codespell.
Fix also some related grammar issues.

In C4/Serials.pm a variable was renamed to make future codespelling
checks easier.

Signed-off-by: Stefan Weil <sw@weilnetz.de>

http://bugs.koha-community.org/show_bug.cgi?id=14383
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-06-22 17:34:45 -03:00

83 lines
2.2 KiB
Perl

package C4::Utils::DataTables::ColumnsSettings;
use Modern::Perl;
use List::Util qw( first );
use YAML;
use C4::Context;
use Koha::Database;
sub get_yaml {
my $yml_path =
C4::Context->config('intranetdir') . '/admin/columns_settings.yml';
my $yaml = eval { YAML::LoadFile($yml_path) };
warn
"ERROR: the yaml file for DT::ColumnsSettings is not correctly formatted: $@"
if $@;
return $yaml;
}
sub get_columns {
my ( $module, $page, $tablename ) = @_;
my $list = get_yaml;
my $schema = Koha::Database->new->schema;
my $rs = $schema->resultset('ColumnsSetting')->search(
{
module => $module,
page => $page,
tablename => $tablename,
}
);
while ( my $c = $rs->next ) {
my $column = first { $c->columnname eq $_->{columnname} }
@{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
$column->{is_hidden} = $c->is_hidden;
$column->{cannot_be_toggled} = $c->cannot_be_toggled;
}
return $list->{modules}{$module}{$page}{$tablename} || [];
}
sub get_modules {
my $list = get_yaml;
my $schema = Koha::Database->new->schema;
my $rs = $schema->resultset('ColumnsSetting')->search;
while ( my $c = $rs->next ) {
my $column = first { $c->columnname eq $_->{columnname} }
@{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } };
$column->{is_hidden} = $c->is_hidden;
$column->{cannot_be_toggled} = $c->cannot_be_toggled;
}
return $list->{modules};
}
sub update_columns {
my ($params) = @_;
my $columns = $params->{columns};
my $schema = Koha::Database->new->schema;
for my $c (@$columns) {
$c->{is_hidden} //= 0;
$c->{cannot_be_toggled} //= 0;
$schema->resultset('ColumnsSetting')->update_or_create(
{
module => $c->{module},
page => $c->{page},
tablename => $c->{tablename},
columnname => $c->{columnname},
is_hidden => $c->{is_hidden},
cannot_be_toggled => $c->{cannot_be_toggled},
}
);
}
}
1;