Revision 2737667a
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/CVar.pm | ||
---|---|---|
64 | 64 |
return $::form->{CVAR_CONFIGS}->{$params{module}}; |
65 | 65 |
} |
66 | 66 |
|
67 |
sub get_config { |
|
68 |
$main::lxdebug->enter_sub(); |
|
69 |
|
|
70 |
my $self = shift; |
|
71 |
my %params = @_; |
|
72 |
|
|
73 |
Common::check_params(\%params, qw(id)); |
|
74 |
|
|
75 |
my $myconfig = \%main::myconfig; |
|
76 |
my $form = $main::form; |
|
77 |
|
|
78 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
79 |
|
|
80 |
my $query = qq|SELECT * FROM custom_variable_configs WHERE id = ?|; |
|
81 |
|
|
82 |
my $config = selectfirst_hashref_query($form, $dbh, $query, conv_i($params{id})) || { }; |
|
83 |
|
|
84 |
$self->_unpack_flags($config); |
|
85 |
|
|
86 |
$main::lxdebug->leave_sub(); |
|
87 |
|
|
88 |
return $config; |
|
89 |
} |
|
90 |
|
|
91 | 67 |
sub _unpack_flags { |
92 | 68 |
$main::lxdebug->enter_sub(); |
93 | 69 |
|
... | ... | |
105 | 81 |
$main::lxdebug->leave_sub(); |
106 | 82 |
} |
107 | 83 |
|
108 |
sub save_config { |
|
109 |
$main::lxdebug->enter_sub(); |
|
110 |
|
|
111 |
my $self = shift; |
|
112 |
my %params = @_; |
|
113 |
|
|
114 |
Common::check_params(\%params, qw(module config)); |
|
115 |
|
|
116 |
my $myconfig = \%main::myconfig; |
|
117 |
my $form = $main::form; |
|
118 |
|
|
119 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
120 |
|
|
121 |
my $q_id = qq|SELECT nextval('custom_variable_configs_id')|; |
|
122 |
my $h_id = prepare_query($form, $dbh, $q_id); |
|
123 |
|
|
124 |
my $q_new = |
|
125 |
qq|INSERT INTO custom_variable_configs (name, description, type, default_value, options, searchable, includeable, included_by_default, module, flags, id, sortkey) |
|
126 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, |
|
127 |
(SELECT COALESCE(MAX(sortkey) + 1, 1) FROM custom_variable_configs))|; |
|
128 |
my $h_new = prepare_query($form, $dbh, $q_new); |
|
129 |
|
|
130 |
my $q_update = |
|
131 |
qq|UPDATE custom_variable_configs SET |
|
132 |
name = ?, description = ?, |
|
133 |
type = ?, default_value = ?, |
|
134 |
options = ?, searchable = ?, |
|
135 |
includeable = ?, included_by_default = ?, |
|
136 |
module = ?, flags = ? |
|
137 |
WHERE id = ?|; |
|
138 |
my $h_update = prepare_query($form, $dbh, $q_update); |
|
139 |
|
|
140 |
my @configs; |
|
141 |
if ('ARRAY' eq ref $params{config}) { |
|
142 |
@configs = @{ $params{config} }; |
|
143 |
} else { |
|
144 |
@configs = ($params{config}); |
|
145 |
} |
|
146 |
|
|
147 |
foreach my $config (@configs) { |
|
148 |
my ($h_actual, $q_actual); |
|
149 |
|
|
150 |
if (!$config->{id}) { |
|
151 |
do_statement($form, $h_id, $q_id); |
|
152 |
($config->{id}) = $h_id->fetchrow_array(); |
|
153 |
|
|
154 |
$h_actual = $h_new; |
|
155 |
$q_actual = $q_new; |
|
156 |
|
|
157 |
} else { |
|
158 |
$h_actual = $h_update; |
|
159 |
$q_actual = $q_update; |
|
160 |
} |
|
161 |
|
|
162 |
do_statement($form, $h_actual, $q_actual, @{$config}{qw(name description type default_value options)}, |
|
163 |
$config->{searchable} ? 't' : 'f', $config->{includeable} ? 't' : 'f', $config->{included_by_default} ? 't' : 'f', |
|
164 |
$params{module}, $config->{flags}, conv_i($config->{id})); |
|
165 |
} |
|
166 |
|
|
167 |
$h_id->finish(); |
|
168 |
$h_new->finish(); |
|
169 |
$h_update->finish(); |
|
170 |
|
|
171 |
$dbh->commit(); |
|
172 |
|
|
173 |
$main::lxdebug->leave_sub(); |
|
174 |
} |
|
175 |
|
|
176 |
sub delete_config { |
|
177 |
$main::lxdebug->enter_sub(); |
|
178 |
|
|
179 |
my $self = shift; |
|
180 |
my %params = @_; |
|
181 |
|
|
182 |
Common::check_params(\%params, qw(id)); |
|
183 |
|
|
184 |
my $myconfig = \%main::myconfig; |
|
185 |
my $form = $main::form; |
|
186 |
|
|
187 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
188 |
|
|
189 |
do_query($form, $dbh, qq|DELETE FROM custom_variables WHERE config_id = ?|, conv_i($params{id})); |
|
190 |
do_query($form, $dbh, qq|DELETE FROM custom_variables_validity WHERE config_id = ?|, conv_i($params{id})); |
|
191 |
do_query($form, $dbh, qq|DELETE FROM custom_variable_configs WHERE id = ?|, conv_i($params{id})); |
|
192 |
|
|
193 |
$dbh->commit(); |
|
194 |
|
|
195 |
$main::lxdebug->leave_sub(); |
|
196 |
} |
|
197 |
|
|
198 | 84 |
sub get_custom_variables { |
199 | 85 |
$main::lxdebug->enter_sub(); |
200 | 86 |
|
... | ... | |
768 | 654 |
# dealing with configs |
769 | 655 |
|
770 | 656 |
my $all_configs = CVar->get_configs() |
771 |
my $config = CVar->get_config(id => '1234') |
|
772 |
|
|
773 |
CVar->save_config($config); |
|
774 |
CVar->delete->config($config) |
|
775 | 657 |
|
776 | 658 |
# dealing with custom vars |
777 | 659 |
|
Auch abrufbar als: Unified diff
Verwaltung von benutzerdefinierten Variablen auf Controller umgestellt