Revision 3e2892b1
Von Sven Schöling vor etwa 15 Jahren hinzugefügt
SL/CVar.pm | ||
---|---|---|
1 | 1 |
package CVar; |
2 | 2 |
|
3 | 3 |
use List::Util qw(first); |
4 |
use Data::Dumper; |
|
4 | 5 |
|
5 | 6 |
use SL::DBUtils; |
7 |
use SL::MoreCommon qw(listify); |
|
6 | 8 |
|
7 | 9 |
sub get_configs { |
8 | 10 |
$main::lxdebug->enter_sub(); |
... | ... | |
228 | 230 |
|
229 | 231 |
do_statement($form, $h_var, $q_var, @values); |
230 | 232 |
$act_var = $h_var->fetchrow_hashref(); |
233 |
|
|
234 |
$act_var->{valid} = $self->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{trans_id}); |
|
231 | 235 |
} |
232 | 236 |
|
233 | 237 |
if ($act_var) { |
... | ... | |
236 | 240 |
: $cvar->{type} eq 'number' ? $act_var->{number_value} |
237 | 241 |
: $cvar->{type} eq 'bool' ? $act_var->{bool_value} |
238 | 242 |
: $act_var->{text_value}; |
239 |
|
|
243 |
$cvar->{valid} = $act_var->{valid}; |
|
240 | 244 |
} else { |
241 | 245 |
if ($cvar->{type} eq 'date') { |
242 | 246 |
if ($cvar->{default_value} eq 'NOW') { |
... | ... | |
329 | 333 |
} |
330 | 334 |
|
331 | 335 |
do_statement($form, $sth, $query, @values); |
336 |
|
|
337 |
$self->save_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id}, |
|
338 |
validity => ($params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"} ? 1 : 0) |
|
339 |
); |
|
332 | 340 |
} |
333 | 341 |
|
334 | 342 |
$sth->finish(); |
... | ... | |
356 | 364 |
|
357 | 365 |
foreach my $var (@{ $params{variables} }) { |
358 | 366 |
$var->{HTML_CODE} = $form->parse_html_template('amcvar/render_inputs', { 'var' => $var, %options }); |
367 |
$var->{VALID_BOX} = "<input type=checkbox name='$options{name_prefix}cvar_$var->{name}$options{name_postfix}_valid'@{[!$var->{valid} ? ' checked' : '']}>"; |
|
359 | 368 |
} |
360 | 369 |
|
361 | 370 |
$main::lxdebug->leave_sub(); |
... | ... | |
587 | 596 |
return ($date_fields, $number_fields); |
588 | 597 |
} |
589 | 598 |
|
599 |
=head2 VALIDITY |
|
600 |
|
|
601 |
Suppose the following scenario: |
|
602 |
|
|
603 |
You have a lot of parts in your database, and a set of properties cofigured. Now not every part has every of these properties, some combinations will just make no sense. In order to clean up your inputs a bit, you want to mark certain combinations as invalid, blocking them from modification and possibly display. |
|
604 |
|
|
605 |
Validity is assumed. If you modify validity, you actually save B<invalidity>. |
|
606 |
validity is saved as a function of config_id, and the trans_id |
|
607 |
|
|
608 |
In the naive way, disable an attribute for a specific id (simple) |
|
609 |
|
|
610 |
=cut |
|
611 |
sub save_custom_variables_validity { |
|
612 |
$main::lxdebug->enter_sub(); |
|
613 |
|
|
614 |
my $self = shift; |
|
615 |
my %params = @_; |
|
616 |
|
|
617 |
Common::check_params(\%params, qw(config_id trans_id validity)); |
|
618 |
|
|
619 |
my $myconfig = \%main::myconfig; |
|
620 |
my $form = $main::form; |
|
621 |
|
|
622 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
623 |
|
|
624 |
my (@where, @values); |
|
625 |
add_token(\@where, \@values, col => "config_id", val => $params{config_id}, esc => \&conv_i); |
|
626 |
add_token(\@where, \@values, col => "trans_id", val => $params{trans_id}, esc => \&conv_i); |
|
627 |
|
|
628 |
my $where = scalar @where ? "WHERE " . join ' AND ', @where : ''; |
|
629 |
my $query = qq|DELETE FROM custom_variables_validity $where|; |
|
630 |
|
|
631 |
do_query($form, $dbh, $query, @values); |
|
632 |
|
|
633 |
$query = |
|
634 |
qq|INSERT INTO custom_variables_validity (config_id, trans_id) |
|
635 |
VALUES (?, ? )|; |
|
636 |
my $sth = prepare_query($form, $dbh, $query); |
|
637 |
|
|
638 |
unless ($params{validity}) { |
|
639 |
foreach my $config_id (listify $params{config_id}) { |
|
640 |
foreach my $trans_id (listify $params{trans_id}) { |
|
641 |
do_statement($form, $sth, $query, conv_i($config_id), conv_i($trans_id)); |
|
642 |
} |
|
643 |
} |
|
644 |
} |
|
645 |
|
|
646 |
$sth->finish(); |
|
647 |
|
|
648 |
$dbh->commit(); |
|
649 |
|
|
650 |
$main::lxdebug->leave_sub(); |
|
651 |
} |
|
652 |
|
|
653 |
sub get_custom_variables_validity { |
|
654 |
$main::lxdebug->enter_sub(); |
|
655 |
|
|
656 |
my $self = shift; |
|
657 |
my %params = @_; |
|
658 |
|
|
659 |
Common::check_params(\%params, qw(config_id trans_id)); |
|
660 |
|
|
661 |
my $myconfig = \%main::myconfig; |
|
662 |
my $form = $main::form; |
|
663 |
|
|
664 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
665 |
|
|
666 |
my $query = qq|SELECT COUNT(*) FROM custom_variables_validity WHERE config_id = ? AND trans_id = ?|; |
|
667 |
|
|
668 |
my ($validity) = selectfirst_array_query($form, $dbh, $query, conv_i($params{config_id}), conv_i($params{trans_id})); |
|
669 |
|
|
670 |
$main::lxdebug->leave_sub(); |
|
671 |
|
|
672 |
return $validity; |
|
673 |
} |
|
590 | 674 |
|
591 | 675 |
1; |
Auch abrufbar als: Unified diff
Valid Flag für Custom Variables in Artikeln.
Ausserdem gefixte Locales.