Lines 142-147
my $output_formats = [
Link Here
|
142 |
{type => 'csv', desc => 'CSV File'}, |
142 |
{type => 'csv', desc => 'CSV File'}, |
143 |
]; |
143 |
]; |
144 |
|
144 |
|
|
|
145 |
sub _build_query { |
146 |
my ( $params, $table ) = @_; |
147 |
my @fields = exists $params->{fields} ? @{ $params->{fields} } : (); |
148 |
my $query = "SELECT " . ( @fields ? join(', ', @fields ) : '*' ) . " FROM $table"; |
149 |
my @where_args; |
150 |
if ( exists $params->{filters} ) { |
151 |
$query .= ' WHERE 1 '; |
152 |
while ( my ( $field, $values ) = each %{ $params->{filters} } ) { |
153 |
if ( ref( $values ) ) { |
154 |
$query .= " AND $field IN ( " . ( ('?') x scalar( @$values ) ) . " ) "; |
155 |
push @where_args, @$values; |
156 |
} else { |
157 |
$query .= " AND $field = ? "; |
158 |
push @where_args, $values; |
159 |
} |
160 |
} |
161 |
} |
162 |
$query .= (exists $params->{orderby} ? " ORDER BY $params->{orderby} " : ''); |
163 |
return ( $query, @where_args ); |
164 |
} |
165 |
|
145 |
=head2 C4::Creators::Lib::get_all_templates() |
166 |
=head2 C4::Creators::Lib::get_all_templates() |
146 |
|
167 |
|
147 |
my $templates = get_all_templates(); |
168 |
my $templates = get_all_templates(); |
Lines 151-163
This function returns a reference to a hash containing all templates upon succes
Link Here
|
151 |
=cut |
172 |
=cut |
152 |
|
173 |
|
153 |
sub get_all_templates { |
174 |
sub get_all_templates { |
154 |
my %params = @_; |
175 |
my ( $params ) = @_; |
155 |
my @templates = (); |
176 |
my @templates = (); |
156 |
my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM creator_templates"; |
177 |
my ( $query, @where_args ) = _build_query( $params, 'creator_templates' ); |
157 |
$query .= ($params{'filter'} ? " WHERE $params{'filter'} " : ''); |
|
|
158 |
$query .= ($params{'orderby'} ? " ORDER BY $params{'orderby'} " : ''); |
159 |
my $sth = C4::Context->dbh->prepare($query); |
178 |
my $sth = C4::Context->dbh->prepare($query); |
160 |
$sth->execute(); |
179 |
$sth->execute( @where_args ); |
161 |
if ($sth->err) { |
180 |
if ($sth->err) { |
162 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
181 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
163 |
return -1; |
182 |
return -1; |
Lines 178-190
This function returns a reference to a hash containing all layouts upon success
Link Here
|
178 |
=cut |
197 |
=cut |
179 |
|
198 |
|
180 |
sub get_all_layouts { |
199 |
sub get_all_layouts { |
181 |
my %params = @_; |
200 |
my ( $params ) = @_; |
182 |
my @layouts = (); |
201 |
my @layouts = (); |
183 |
my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM creator_layouts"; |
202 |
my ( $query, @where_args ) = _build_query( $params, 'creator_layouts' ); |
184 |
$query .= ($params{'filter'} ? " WHERE $params{'filter'} " : ''); |
|
|
185 |
$query .= ($params{'orderby'} ? " ORDER BY $params{'orderby'} " : ''); |
186 |
my $sth = C4::Context->dbh->prepare($query); |
203 |
my $sth = C4::Context->dbh->prepare($query); |
187 |
$sth->execute(); |
204 |
$sth->execute( @where_args ); |
188 |
if ($sth->err) { |
205 |
if ($sth->err) { |
189 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
206 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
190 |
return -1; |
207 |
return -1; |
Lines 200-206
sub get_all_layouts {
Link Here
|
200 |
|
217 |
|
201 |
my $profiles = get_all_profiles(); |
218 |
my $profiles = get_all_profiles(); |
202 |
|
219 |
|
203 |
my $profiles = get_all_profiles(field_list => field_list, filter => filter_string); |
220 |
my $profiles = get_all_profiles({ fields => [@fields], filters => { filters => [$value1, $value2] } }); |
204 |
|
221 |
|
205 |
This function returns an arrayref whose elements are hashes containing all profiles upon success and 1 upon failure. Errors are logged |
222 |
This function returns an arrayref whose elements are hashes containing all profiles upon success and 1 upon failure. Errors are logged |
206 |
to the Apache log. Two parameters are accepted. The first limits the field(s) returned. This parameter should be string of comma separted |
223 |
to the Apache log. Two parameters are accepted. The first limits the field(s) returned. This parameter should be string of comma separted |
Lines 211-223
NOTE: Do not pass in the keyword 'WHERE.'
Link Here
|
211 |
=cut |
228 |
=cut |
212 |
|
229 |
|
213 |
sub get_all_profiles { |
230 |
sub get_all_profiles { |
214 |
my %params = @_; |
231 |
my ( $params ) = @_; |
215 |
my @profiles = (); |
232 |
my @profiles = (); |
216 |
my $query = "SELECT " . ($params{'field_list'} ? $params{'field_list'} : '*') . " FROM printers_profile"; |
233 |
my ( $query, @where_args ) = _build_query( $params, 'printers_profile' ); |
217 |
$query .= ($params{'filter'} ? " WHERE $params{'filter'};" : ';'); |
|
|
218 |
my $sth = C4::Context->dbh->prepare($query); |
234 |
my $sth = C4::Context->dbh->prepare($query); |
219 |
# $sth->{'TraceLevel'} = 3 if $debug; |
235 |
$sth->execute( @where_args ); |
220 |
$sth->execute(); |
|
|
221 |
if ($sth->err) { |
236 |
if ($sth->err) { |
222 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
237 |
warn sprintf('Database returned the following error: %s', $sth->errstr); |
223 |
return -1; |
238 |
return -1; |
Lines 262-275
NOTE: Do not pass in the keyword 'WHERE.'
Link Here
|
262 |
=cut |
277 |
=cut |
263 |
|
278 |
|
264 |
sub get_batch_summary { |
279 |
sub get_batch_summary { |
265 |
my %params = @_; |
280 |
my ( $params ) = @_; |
266 |
my @batches = (); |
281 |
my @batches = (); |
267 |
my $query = "SELECT batch_id,count(batch_id) as _item_count FROM creator_batches WHERE creator=?"; |
282 |
$params->{fields} = ['batch_id', 'count(batch_id) as _item_count']; |
268 |
$query .= ($params{'filter'} ? " AND $params{'filter'}" : ''); |
283 |
my ( $query, @where_args ) = _build_query( $params, 'creator_batches' ); |
269 |
$query .= " GROUP BY batch_id"; |
284 |
$query .= " GROUP BY batch_id"; |
270 |
my $sth = C4::Context->dbh->prepare($query); |
285 |
my $sth = C4::Context->dbh->prepare($query); |
271 |
# $sth->{'TraceLevel'} = 3; |
286 |
$sth->execute( @where_args ); |
272 |
$sth->execute($params{'creator'}); |
|
|
273 |
if ($sth->err) { |
287 |
if ($sth->err) { |
274 |
warn sprintf('Database returned the following error on attempted SELECT: %s', $sth->errstr); |
288 |
warn sprintf('Database returned the following error on attempted SELECT: %s', $sth->errstr); |
275 |
return -1; |
289 |
return -1; |