-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathLexicon.pm
64 lines (56 loc) · 2.04 KB
/
Lexicon.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
=head1 NAME
Tuba::Lexicon - Controller for lexcons.
=cut
package Tuba::Lexicon;
use Mojo::Base qw/Tuba::Controller/;
use Tuba::DB::Objects qw/-nicknames/;
use Tuba::Log qw/logger/;
sub show {
my $c = shift;
my $lexicon = $c->_this_object or return $c->render_not_found_or_redirect;
$c->stash(object => $lexicon);
$c->SUPER::show(@_);
}
sub update_rel_form {
my $c = shift;
my $lexicon = $c->_this_object or return $c->render_not_found_or_redirect;
my $terms;
if (my $context = $c->param('context')) {
$terms = $c->orm->{exterm}{mng}->get_objects(query => [lexicon_identifier => $lexicon->identifier, context => $context], sort_by => 'term' );
} else {
$terms = [];
}
$c->stash(terms => $terms);
$c->SUPER::update_rel_form(@_);
}
sub update_rel {
my $c = shift;
my $lexicon = $c->_this_object or return $c->render_not_found_or_redirect;
my $term = $c->param('new_term');
my $gcid = $c->param('new_gcid');
my $context = $c->param('context');
my $t = $c->param('delete_term');
$c->stash(tab => "update_rel_form");
$c->stash(redirect_params => [ context => $context ]);
if ($term && $context) {
my %entry = (
term => $term,
context => $context,
lexicon_identifier => $lexicon->identifier,
);
my $exterm = Exterm->new(%entry);
$exterm->load(speculative => 1);
$exterm->gcid($gcid);
$exterm->save(audit_user => $c->audit_user, audit_note => $c->audit_note) or return $c->update_error($exterm->error);
}
if (my @delete = @{ $c->every_param('delete_term') }) {
for my $term (@delete) {
logger->info("deleting $lexicon $context $term");
my $ex = Exterm->new(lexicon => $lexicon, term => $term, context => $context);
$ex->load(speculative => 1) or next;
$ex->delete(audit_user => $c->audit_user, audit_note => $c->audit_note) or return $c->update_error($ex->error);
}
}
return $c->redirect_without_error('update_rel_form');
}
1;