lib/Strehler/Element.pm

filter: Statementstmt 52.0% 301 / 578 Branchbran 44.1% 120 / 272 Conditioncond 44.9% 44 / 98 MC/DCmcdc 26.3% 15 / 57 Subroutinesub 58.7% 27 / 46 Podpod 65.7% 25 / 38 totaltotal 48.8% 532 / 1089 CC 196 SCAR 39.1
CC
196
Cov
49%
get_form_data
306.0
fields_list
56.0
save_form
47.8
CRAP 49.9
« lib/Strehler/Dancer2/Plugin/EX.pm ↑ Summary lib/Strehler/Admin.pm »
1 package Strehler::Element;
2 12 $Strehler::Element::VERSION = '1.6.8';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Carp 'carp';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Dancer2 0.166001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Dancer2::Plugin::DBIC;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Strehler::Meta::Tag;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Strehler::Meta::Category;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Strehler::Helpers;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 with 'Strehler::Element::Role::Configured';
13  
14 12 has row => (
15 is => 'ro',
16 );
17  
18 98 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=6.9
Pod undocumented
19 98 my ( $class, @args ) = @_;
20 98 my $id = shift @args;
21 98 my $article;
22 98 ▶ if(! $id)
Branch: 1 branch
BranchTrueFalseTotal
if (not $id) { } 32 66 98
23 {
24 32 $article = undef;
25 }
26 else
27 {
28 66 $article = $class->get_schema()->resultset($class->ORMObj())->find($id);
29 }
30 98 return { row => $article };
31 };
32  
33 sub metaclass_data
34 0 ▶{
Subroutine metaclass_data: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my $self = shift;
36 0 my $param = shift;
37 0 my %element_conf = ( item_type => 'element',
38 ORMObj => undef,
39 category_accessor => undef,
40 multilang_children => undef );
41 0 return $element_conf{$param};
42 }
43  
44 sub exists
45 305 ▶{
Subroutine exists: called CC=2 SCAR=6.9
Pod documented
46 305 my $self = shift;
47 305 ▶ if($self->row)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row) { } 271 34 305
48 {
49 271 return 1;
50 }
51 else
52 {
53 34 return 0;
54 }
55 }
56 sub delete
57 2 ▶{
Subroutine delete: called CC=2 SCAR=6.9
Pod documented
58 2 my $self = shift;
59 2 my $children = $self->row->can($self->multilang_children());
60 2 ▶ $self->row->$children->delete_all() if($children);
Branch: 1 branch
BranchTrueFalseTotal
if $children 1 1 2
61  
62 2 return $self->row->delete();
63 }
64  
65 sub category
66 35 ▶{
Subroutine category: called CC=2 SCAR=7.6
Pod undocumented
67 35 my $self = shift;
68 35 ▶ if($self->row->category)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row->category) { } 35 0 35
69 {
70 35 return $self->row->category->category;
71 }
72 else
73 {
74 0 return undef;
75 }
76 }
77  
78 sub get_attr
79 266 ▶{
Subroutine get_attr: called CC=13 SCAR=31.7
Pod documented
80 266 my $self = shift;
81 266 my $attribute = shift;
82 266 ▶ my $bare = shift || 0;
Condition50%1/2
shift() || 0
l!l
0266
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
83 266 ▶ return undef if(! $self->exists);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->exists 0 266 266
84 266 my $accessor = $self->can($attribute);
85 266 ▶ if($accessor && ! $bare)
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor and not $bare) 66 200 266
Condition66%2/3
$accessor and not $bare
!ll&&!rl&&r
200066
MC/DC50%1/2
$accessor and not $bare
$accessor not $bare
Truth table66%2/3
A and not(B)
A= $accessorB= not $bare
ABresult
0X0
100
111
86 {
87 66 ▶ if($self->row->result_source->has_column($attribute))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row->result_source->has_column($attribute)) { } 66 0 66
88 {
89 66 return $self->$accessor($self->row->$attribute);
90 }
91 else
92 {
93 0 return $self->$accessor(undef);
94 }
95 }
96 200 ▶ if($attribute eq 'main-title')
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute eq "main-title") 0 200 200
97 {
98 0 return $self->main_title();
99 }
100 200 ▶ if($attribute eq 'category-name')
Branch: 1 branch
BranchTrueFalseTotal
if ($attribute eq 'category-name') { } 0 200 200
101 {
102 0 return $self->get_category_name();
103 }
104 else
105 {
106 200 ▶ if($self->row->result_source->has_column($attribute))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row->result_source->has_column($attribute)) { } 194 6 200
107 {
108 194 ▶ if($self->row->result_source->column_info($attribute)->{'data_type'} eq 'timestamp' || $self->row->result_source->column_info($attribute)->{'data_type'} eq 'datetime')
Branch: 2 branches
BranchTrueFalseTotal
if ($self->row->result_source->column_info($attribute)->{'data_type'} eq 'timestamp' or $self->row->result_source->column_info($attribute)->{'data_type'} eq 'datetime') { } 0 194 194
elsif ($self->row->result_source->column_info($attribute)->{'data_type'} eq 'date') { } 34 160 194
Condition33%1/3
$self->row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $self->row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
l!l&&r!l&&!r
00194
MC/DC0%0/2
$self->row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $self->row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
$self->row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" $self->row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
Truth table33%1/3
A or B
A= $self->row->result_source->column_info($attribute)->{"data_type"} eq "timestamp"B= $self->row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
ABresult
1X1
011
000
109 {
110 0 my $ts = $self->row->$attribute;
111 0 ▶ if($ts)
Branch: 1 branch
BranchTrueFalseTotal
if ($ts) { } 0 0 0
112 {
113 0 $ts->set_time_zone('UTC');
114 0 $ts->set_time_zone(config->{'Strehler'}->{'timezone'});
115 0 return $ts;
116 }
117 else
118 {
119 0 return undef;
120 }
121 }
122 elsif($self->row->result_source->column_info($attribute)->{'data_type'} eq 'date')
123 {
124 34 return $self->row->$attribute;
125 }
126 else
127 {
128 160 return $self->row->get_column($attribute);
129 }
130 }
131 else
132 {
133 6 return undef;
134 }
135 }
136 }
137 sub get_attr_multilang
138 46 ▶{
Subroutine get_attr_multilang: called CC=14 SCAR=37.5
Pod documented
139 46 my $self = shift;
140 46 my $attribute = shift;
141 46 my $lang = shift;
142 46 ▶ my $bare = shift || 0;
Condition50%1/2
shift() || 0
l!l
046
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
143 46 my $accessor = $self->can($attribute);
144 46 my $children = $self->row->can($self->multilang_children());
145 45 ▶ return undef if not $children;
Branch: 1 branch
BranchTrueFalseTotal
unless $children 0 45 45
146 45 my $content = $self->row->$children->find({'language' => $lang});
147 45 my $content_attribute = undef;
148 45 ▶ if($content && $content->result_source->has_column($attribute))
Branch: 1 branch
BranchTrueFalseTotal
if ($content and $content->result_source->has_column($attribute)) 45 0 45
Condition33%1/3
$content and $content->result_source->has_column($attribute)
!ll&&!rl&&r
0045
MC/DC0%0/2
$content and $content->result_source->has_column($attribute)
$content $content->result_source->has_column($attribute)
Truth table33%1/3
A and B
A= $contentB= $content->result_source->has_column($attribute)
ABresult
0X0
100
111
149 {
150 45 $content_attribute = $content->$attribute;
151 }
152 45 ▶ if($accessor && ! $bare)
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor and not $bare) 0 45 45
Condition33%1/3
$accessor and not $bare
!ll&&!rl&&r
4500
MC/DC0%0/2
$accessor and not $bare
$accessor not $bare
Truth table33%1/3
A and not(B)
A= $accessorB= not $bare
ABresult
0X0
100
111
153 {
154 0 ▶ if($content_attribute)
Branch: 1 branch
BranchTrueFalseTotal
if ($content_attribute) { } 0 0 0
155 {
156 0 return $self->$accessor($content_attribute, $lang);
157 }
158 else
159 {
160 0 return $self->$accessor($lang);
161 }
162 }
163 45 ▶ if($content)
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 45 0 45
164 {
165 45 ▶ if($content->result_source->has_column($attribute))
Branch: 1 branch
BranchTrueFalseTotal
if ($content->result_source->has_column($attribute)) { } 45 0 45
166 {
167 45 ▶ if($content->result_source->column_info($attribute)->{'data_type'} eq 'timestamp' || $content->result_source->column_info($attribute)->{'data_type'} eq 'datetime')
Branch: 2 branches
BranchTrueFalseTotal
if ($content->result_source->column_info($attribute)->{'data_type'} eq 'timestamp' or $content->result_source->column_info($attribute)->{'data_type'} eq 'datetime') { } 0 45 45
elsif ($content->result_source->column_info($attribute)->{'data_type'} eq 'date') { } 0 45 45
Condition33%1/3
$content->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $content->result_source->column_info($attribute)->{"data_type"} eq "datetime"
l!l&&r!l&&!r
0045
MC/DC0%0/2
$content->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $content->result_source->column_info($attribute)->{"data_type"} eq "datetime"
$content->result_source->column_info($attribute)->{"data_type"} eq "timestamp" $content->result_source->column_info($attribute)->{"data_type"} eq "datetime"
Truth table33%1/3
A or B
A= $content->result_source->column_info($attribute)->{"data_type"} eq "timestamp"B= $content->result_source->column_info($attribute)->{"data_type"} eq "datetime"
ABresult
1X1
011
000
168 {
169 0 my $ts = $content->$attribute;
170 0 ▶ if($ts)
Branch: 1 branch
BranchTrueFalseTotal
if ($ts) { } 0 0 0
171 {
172 0 $ts->set_time_zone('UTC');
173 0 $ts->set_time_zone(config->{'Strehler'}->{'timezone'});
174 0 return $ts;
175 }
176 else
177 {
178 0 return undef;
179 }
180 }
181 elsif($content->result_source->column_info($attribute)->{'data_type'} eq 'date')
182 {
183 0 return $content->$attribute;
184 }
185 else
186 {
187 45 return $content->get_column($attribute);
188 }
189 }
190 else
191 {
192 0 return undef;
193 }
194 }
195 else
196 {
197 0 return undef;
198 }
199 }
200 sub has_language
201 7 ▶{
Subroutine has_language: called CC=3 SCAR=11.0
Pod documented
202 7 my $self = shift;
203 7 my $language = shift;
204 7 my $children = $self->row->can($self->multilang_children());
205 7 ▶ return 1 if not $children;
Branch: 1 branch
BranchTrueFalseTotal
unless $children 0 7 7
206 7 my $content = $self->row->$children->find({language => $language});
207 7 ▶ if($content)
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 4 3 7
208 {
209 4 return 1;
210 }
211 else
212 {
213 3 return 0;
214 }
215 }
216 sub get_tags
217 0 ▶{
Subroutine get_tags: not called CC=1 SCAR=6.9
Pod documented
218 0 my $self = shift;
219 0 my $tags = Strehler::Meta::Tag->tags_to_string($self->get_attr('id'), $self->item_type());
220 0 return $tags;
221 }
222 sub get_category_name
223 38 ▶{
Subroutine get_category_name: called CC=4 SCAR=14.2
Pod documented
224 38 my $self = shift;
225 38 ▶ if($self->row && $self->row->can('category'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row and $self->row->can('category')) { } 35 3 38
Condition66%2/3
$self->row and $self->row->can("category")
!ll&&!rl&&r
0335
MC/DC50%1/2
$self->row and $self->row->can("category")
$self->row $self->row->can("category")
Truth table66%2/3
A and B
A= $self->rowB= $self->row->can("category")
ABresult
0X0
100
111
226 {
227 35 ▶ if($self->row->category)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row->category) { } 35 0 35
228 {
229 35 my $category = Strehler::Meta::Category->new($self->row->category->id);
230 35 return $category->ext_name();
231 }
232 else
233 {
234 0 return undef;
235 }
236 }
237 else
238 {
239 3 return undef;
240 }
241 }
242 sub get_category_id
243 0 ▶{
Subroutine get_category_id: not called CC=2 SCAR=17.9
Pod undocumented
244 0 my $self = shift;
245 0 ▶ if($self->row->can('category'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->row->can('category')) { } 0 0 0
246 {
247 0 return $self->row->category->id;
248 }
249 else
250 {
251 0 return undef;
252 }
253 }
254 sub max_category_order
255 0 ▶{
Subroutine max_category_order: not called CC=5 SCAR=34.0
Pod undocumented
256 0 my $self = shift;
257 0 my $category_id = shift;
258 0 my $max = 0;
259 0 my $max_found = 0;
260 0 ▶ if($category_id)
Branch: 1 branch
BranchTrueFalseTotal
if ($category_id) 0 0 0
261 {
262 0 my $category = Strehler::Meta::Category->new($category_id);
263 0 my $category_accessor = undef;
264 0 ▶ if($category)
Branch: 1 branch
BranchTrueFalseTotal
if ($category) 0 0 0
265 {
266 0 $category_accessor = $self->category_accessor($category->row);
267 0 ▶ if($category_accessor)
Branch: 1 branch
BranchTrueFalseTotal
if ($category_accessor) 0 0 0
268 {
269 0 $max = $category->row->$category_accessor->search()->get_column('display_order')->max();
270 0 $max_found = 1;
271 }
272 }
273
274 }
275 0 ▶ if(! $max_found)
Branch: 1 branch
BranchTrueFalseTotal
unless ($max_found) 0 0 0
276 {
277 0 $max = $self->get_schema()->resultset($self->ORMObj())->search()->get_column('display_order')->max();
278 }
279 0 return $max;
280 }
281 sub get_basic_data
282 38 ▶{
Subroutine get_basic_data: called CC=2 SCAR=6.9
Pod documented
283 38 my $self = shift;
284 38 my %data;
285 38 foreach my $c ($self->data_fields())
286 {
287 225 $data{$c} = $self->get_attr($c);
288 }
289 38 $data{'title'} = $self->main_title;
290 38 $data{'category_name'} = $self->get_category_name();
291 38 return %data;
292 }
293 sub get_ext_data
294 18 ▶{
Subroutine get_ext_data: called CC=2 SCAR=6.9
Pod documented
295 18 my $self = shift;
296 18 my $language = shift;
297 18 my %data;
298 18 %data = $self->get_basic_data();
299 18 foreach my $c ($self->multilang_data_fields())
300 {
301 45 $data{$c} = $self->get_attr_multilang($c, $language);
302 }
303 18 return %data;
304 }
305  
306 sub get_json_data
307 14 ▶{
Subroutine get_json_data: called CC=3 SCAR=11.0
Pod undocumented
308 14 my $self = shift;
309 14 my $language = shift;
310 14 my %data = $self->get_ext_data($language);
311 14 foreach my $key (keys %data)
312 {
313 137 ▶ if(ref $data{$key} eq 'DateTime')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data{$key} eq "DateTime") 8 129 137
314 {
315 8 $data{$key} = $data{$key}->epoch();
316 }
317 }
318 14 return %data;
319 }
320  
321 sub main_title
322 3 ▶{
Subroutine main_title: called CC=3 SCAR=13.3
Pod documented
323 3 my $self = shift;
324 3 ▶ if($self->get_attr('title'))
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_attr('title')) { } 0 3 3
elsif ($self->get_attr('name')) { } 0 3 3
325 {
326 0 return $self->get_attr('title');
327 }
328 elsif($self->get_attr('name'))
329 {
330 0 return $self->get_attr('name');
331 }
332 else
333 {
334 3 return "[". $self->get_attr('id') . "]";
335 }
336 }
337 sub fields_list
338 0 ▶{
Subroutine fields_list: not called CC=7 SCAR=40.3
Pod documented
339 0 my $self = shift;
340 0 my $item = $self->metaclass_data('item_type');
341 0 my $class = Strehler::Helpers::class_from_entity($item);
342 0 my %attributes = $class->entity_data();
343 0 my $resultset = $self->get_schema()->resultset($self->ORMObj());
344 0 my $title_id = $self->default_field();
345 0 ▶ my $title_label = $title_id ? ucfirst($title_id) : 'Title';
Branch: 1 branch
BranchTrueFalseTotal
$title_id ? : 0 0 0
346 0 ▶ my $title_ordinable = $title_id ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$title_id ? : 0 0 0
347 0 my @fields = ( { 'id' => 'id',
348 'label' => 'ID',
349 'ordinable' => 1 },
350 { 'id' => $title_id,
351 'label' => $title_label,
352 'ordinable' => $title_ordinable } );
353 0 ▶ if($attributes{'categorized'})
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"categorized"}) 0 0 0
354 {
355 0 push @fields, { 'id' => 'category',
356 'label' => 'Category',
357 'ordinable' => 0 };
358 }
359 0 ▶ if($attributes{'ordered'})
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"ordered"}) 0 0 0
360 {
361 0 push @fields, { 'id' => 'display_order',
362 'label' => 'Order',
363 'ordinable' => 1 };
364 }
365 0 ▶ if($attributes{'dated'})
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"dated"}) 0 0 0
366 {
367 0 push @fields, { 'id' => 'publish_date',
368 'label' => 'Date',
369 'ordinable' => 1 };
370 }
371 0 ▶ if($attributes{'publishable'})
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"publishable"}) 0 0 0
372 {
373 0 push @fields, { 'id' => 'published',
374 'label' => 'Status',
375 'ordinable' => 1 };
376 }
377 0 return \@fields;
378
379 }
380 sub default_field
381 0 ▶{
Subroutine default_field: not called CC=3 SCAR=24.8
Pod undocumented
382 0 my $self = shift;
383 0 my $resultset = $self->get_schema()->resultset($self->ORMObj());
384 0 ▶ if($resultset->result_source->has_column('title'))
Branch: 2 branches
BranchTrueFalseTotal
if ($resultset->result_source->has_column('title')) { } 0 0 0
elsif ($resultset->result_source->has_column('name')) { } 0 0 0
385 {
386 0 return 'title';
387 }
388 elsif($resultset->result_source->has_column('name'))
389 {
390 0 return 'name';
391 }
392 else
393 {
394 0 return undef;
395 }
396  
397 }
398 sub publish
399 6 ▶{
Subroutine publish: called CC=2 SCAR=7.0
Pod documented
400 6 my $self = shift;
401 6 ▶ return if ! $self->publishable();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->publishable 0 6 6
402 6 $self->row->published(1);
403 6 $self->row->update();
404 6 return 0;
405 }
406 sub unpublish
407 0 ▶{
Subroutine unpublish: not called CC=2 SCAR=17.9
Pod documented
408 0 my $self = shift;
409 0 ▶ return if ! $self->publishable();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->publishable 0 0 0
410 0 $self->row->published(0);
411 0 $self->row->update();
412 0 return 0;
413 }
414 sub next_in_category_by_order
415 0 ▶{
Subroutine next_in_category_by_order: not called CC=6 SCAR=37.4
Pod documented
416 0 my $self = shift;
417 0 my $language = shift;
418 0 my $category = $self->get_schema()->resultset('Category')->find($self->get_category_id());
419 0 my $category_access = $self->category_accessor($category);
420 0 ▶ my $my_order = $self->get_attr('display_order') || 0;
Condition0%0/2
$self->get_attr('display_order') || 0
l!l
00
MC/DC0%0/1
$self->get_attr('display_order') || 0
$self->get_attr('display_order')
Truth table0%0/2
A
A= $self->get_attr('display_order')
Aresult
11
00
421 0 my $criteria = { display_order => { '>', $my_order}};
422 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
423 {
424 0 $criteria->{'published'} = 1;
425 }
426
427 0 my @nexts = $category->$category_access->search($criteria, { order_by => {-asc => 'display_order' }});
428 0 ▶ if($#nexts >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#nexts >= 0) 0 0 0
429 {
430 0 for(@nexts)
431 {
432 0 my $el = $self->new($_->id);
433 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
434 {
435 0 return $el;
436 }
437 }
438 }
439 0 return $self->new(undef);
440 }
441 sub prev_in_category_by_order
442 0 ▶{
Subroutine prev_in_category_by_order: not called CC=6 SCAR=37.4
Pod documented
443 0 my $self = shift;
444 0 my $language = shift;
445 0 my $category = $self->get_schema()->resultset('Category')->find($self->get_category_id());
446 0 my $category_access = $self->category_accessor($category);
447 0 ▶ my $my_order = $self->get_attr('display_order') || 0;
Condition0%0/2
$self->get_attr('display_order') || 0
l!l
00
MC/DC0%0/1
$self->get_attr('display_order') || 0
$self->get_attr('display_order')
Truth table0%0/2
A
A= $self->get_attr('display_order')
Aresult
11
00
448 0 my $criteria = { display_order => { '<', $my_order }};
449 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
450 {
451 0 $criteria->{'published'} = 1;
452 }
453 0 my @nexts = $category->$category_access->search($criteria, { order_by => {-desc => 'display_order' }});
454 0 ▶ if($#nexts >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#nexts >= 0) 0 0 0
455 {
456 0 for(@nexts)
457 {
458 0 my $el = $self->new($_->id);
459 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
460 {
461 0 return $el;
462 }
463 }
464 }
465 0 return $self->new(undef);
466 }
467 sub next_in_category_by_date
468 0 ▶{
Subroutine next_in_category_by_date: not called CC=6 SCAR=37.4
Pod documented
469 0 my $self = shift;
470 0 my $language = shift;
471 0 my $category = $self->get_schema()->resultset('Category')->find($self->get_category_id());
472 0 ▶ my $my_date = $self->get_attr('publish_date') || DateTime->from_epoch( epoch => 0);
Condition0%0/3
$self->get_attr('publish_date') || 'DateTime'->from_epoch('epoch', 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_attr('publish_date') || 'DateTime'->from_epoch('epoch', 0)
$self->get_attr('publish_date') 'DateTime'->from_epoch('epoch', 0)
Truth table0%0/3
A || B
A= $self->get_attr('publish_date')B= 'DateTime'->from_epoch('epoch', 0)
ABresult
1X1
011
000
473 0 my $category_access = $self->category_accessor($category);
474 0 my $criteria = {publish_date => { '>', $my_date }};
475 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
476 {
477 0 $criteria->{'published'} = 1;
478 }
479 0 my @nexts = $category->$category_access->search($criteria, { order_by => {-asc => 'publish_date' }});
480 0 ▶ if($#nexts >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#nexts >= 0) 0 0 0
481 {
482 0 for(@nexts)
483 {
484 0 my $el = $self->new($_->id);
485 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
486 {
487 0 return $el;
488 }
489 }
490 }
491 0 return $self->new(undef);
492 }
493 sub prev_in_category_by_date
494 0 ▶{
Subroutine prev_in_category_by_date: not called CC=6 SCAR=37.4
Pod documented
495 0 my $self = shift;
496 0 my $language = shift;
497 0 my $category = $self->get_schema()->resultset('Category')->find($self->get_category_id());
498 0 my $category_access = $self->category_accessor($category);
499 0 ▶ my $my_date = $self->get_attr('publish_date') || DateTime->from_epoch( epoch => 0);
Condition0%0/3
$self->get_attr('publish_date') || 'DateTime'->from_epoch('epoch', 0)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_attr('publish_date') || 'DateTime'->from_epoch('epoch', 0)
$self->get_attr('publish_date') 'DateTime'->from_epoch('epoch', 0)
Truth table0%0/3
A || B
A= $self->get_attr('publish_date')B= 'DateTime'->from_epoch('epoch', 0)
ABresult
1X1
011
000
500 0 my $criteria = { publish_date => { '<', $my_date }};
501 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
502 {
503 0 $criteria->{'published'} = 1;
504 }
505 0 my @nexts = $category->$category_access->search($criteria , { order_by => {-desc => 'publish_date' }});
506 0 ▶ if($#nexts >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#nexts >= 0) 0 0 0
507 {
508 0 for(@nexts)
509 {
510 0 my $el = $self->new($_->id);
511 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
512 {
513 0 return $el;
514 }
515 }
516 }
517 0 return $self->new(undef);
518 }
519 sub get_last_by_order
520 0 ▶{
Subroutine get_last_by_order: not called CC=6 SCAR=37.4
Pod documented
521 0 my $self = shift;
522 0 my $cat = shift;
523 0 my $language = shift;
524 0 my $category = Strehler::Meta::Category->explode_name($cat);
525 0 ▶ return undef if(! $category->exists());
Branch: 1 branch
BranchTrueFalseTotal
unless $category->exists 0 0 0
526 0 my $category_access = $self->category_accessor($category->row);
527 0 my $criteria = {};
528 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
529 {
530 0 $criteria->{'published'} = 1;
531 }
532 0 my @chapters = $category->row->$category_access->search($criteria , { order_by => { -desc => 'display_order' } });
533 0 ▶ if($chapters[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($chapters[0]) 0 0 0
534 {
535 0 for(@chapters)
536 {
537 0 my $el = $self->new($_->id);
538 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
539 {
540 0 return $el;
541 }
542 }
543 }
544 0 return undef;
545 }
546 sub get_last_by_date
547 0 ▶{
Subroutine get_last_by_date: not called CC=6 SCAR=37.4
Pod documented
548 0 my $self = shift;
549 0 my $cat = shift;
550 0 my $language = shift;
551 0 my $category = Strehler::Meta::Category->explode_name($cat);
552 0 ▶ return undef if(! $category->exists());
Branch: 1 branch
BranchTrueFalseTotal
unless $category->exists 0 0 0
553 0 my $category_access = $self->category_accessor($category->row);
554 0 my $criteria = {};
555 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
556 {
557 0 $criteria->{'published'} = 1;
558 }
559 0 my @chapters = $category->row->$category_access->search( $criteria, { order_by => { -desc => 'publish_date' } });
560 0 ▶ if($chapters[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($chapters[0]) 0 0 0
561 {
562 0 for(@chapters)
563 {
564 0 my $el = $self->new($_->id);
565 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
566 {
567 0 return $el;
568 }
569 }
570 }
571 0 return undef;
572 }
573 sub get_last_pubunpub
574 4 ▶{
Subroutine get_last_pubunpub: called CC=15 SCAR=29.6
Pod documented
575 4 my $self = shift;
576 4 my $cat = shift;
577 4 my $language = shift;
578 4 my $order = shift;
579 4 my $category = Strehler::Meta::Category->explode_name($cat);
580 4 ▶ return (undef, undef) if(! $category->exists());
Branch: 1 branch
BranchTrueFalseTotal
unless $category->exists 0 4 4
581 4 my $category_access = $self->category_accessor($category->row);
582 4 my $ordering_field;
583 4 ▶ if($order eq 'date' && $self->dated())
Branch: 2 branches
BranchTrueFalseTotal
if ($order eq 'date' and $self->dated) { } 2 2 4
elsif ($order eq 'order' and $self->ordered) { } 2 0 2
Condition66%2/3
$order eq "date" and $self->dated
!ll&&!rl&&r
202
MC/DC50%1/2
$order eq "date" and $self->dated
$order eq "date" $self->dated
Truth table66%2/3
A and B
A= $order eq "date"B= $self->dated
ABresult
0X0
100
111
584 {
585 2 $ordering_field = 'publish_date';
586 }
587 ▶ elsif($order eq 'order' && $self->ordered())
Condition33%1/3
$order eq "order" and $self->ordered
!ll&&!rl&&r
002
MC/DC0%0/2
$order eq "order" and $self->ordered
$order eq "order" $self->ordered
Truth table33%1/3
A and B
A= $order eq "order"B= $self->ordered
ABresult
0X0
100
111
588 {
589 2 $ordering_field = 'display_order';
590 }
591 else
592 {
593 0 carp "Bad order configuration on dashboard for $cat.";
594 0 $ordering_field = 'me.id';
595 }
596 4 my @chapters = $category->row->$category_access->search(undef, { order_by => { -desc => $ordering_field } });
597 4 my $pub = undef;
598 4 my $unpub = undef;
599 4 foreach my $c (@chapters)
600 {
601 7 my $el = $self->new($c->id);
602 7 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 4 3 7
603 {
604 4 ▶ if(! $self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->publishable) 0 4 4
605 {
606 0 return ($el, undef);
607 }
608 4 ▶ if($el->get_attr('published') && $el->get_attr('published') == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($el->get_attr('published') and $el->get_attr('published') == 1) { } 2 2 4
Condition66%2/3
$el->get_attr("published") and $el->get_attr("published") == 1
!ll&&!rl&&r
202
MC/DC50%1/2
$el->get_attr("published") and $el->get_attr("published") == 1
$el->get_attr("published") $el->get_attr("published") == 1
Truth table66%2/3
A and B
A= $el->get_attr("published")B= $el->get_attr("published") == 1
ABresult
0X0
100
111
609 {
610 2 ▶ if(! $pub)
Branch: 1 branch
BranchTrueFalseTotal
unless ($pub) 2 0 2
611 {
612 2 $pub = $el;
613 2 return ($pub, $unpub);
614 }
615 }
616 else
617 {
618 2 ▶ if(! $unpub)
Branch: 1 branch
BranchTrueFalseTotal
unless ($unpub) 2 0 2
619 {
620 2 $unpub = $el;
621 2 ▶ if($pub && $unpub)
Branch: 1 branch
BranchTrueFalseTotal
if ($pub and $unpub) 0 2 2
Condition33%1/3
$pub and $unpub
!ll&&!rl&&r
200
MC/DC0%0/2
$pub and $unpub
$pub $unpub
Truth table33%1/3
A and B
A= $pubB= $unpub
ABresult
0X0
100
111
622 {
623 0 return ($pub, $unpub);
624 }
625 }
626 }
627 }
628 }
629 2 return ($pub, $unpub);
630 }
631  
632  
633 sub get_first_by_order
634 0 ▶{
Subroutine get_first_by_order: not called CC=6 SCAR=37.4
Pod documented
635 0 my $self = shift;
636 0 my $cat = shift;
637 0 my $language = shift;
638 0 my $category = Strehler::Meta::Category->explode_name($cat);
639 0 ▶ return undef if(! $category->exists());
Branch: 1 branch
BranchTrueFalseTotal
unless $category->exists 0 0 0
640 0 my $category_access = $self->category_accessor($category->row);
641 0 my $criteria = {};
642 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
643 {
644 0 $criteria = { published => 1 };
645 }
646 0 my @chapters = $category->row->$category_access->search( $criteria, { order_by => { -asc => 'display_order' } });
647 0 ▶ if($chapters[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($chapters[0]) 0 0 0
648 {
649 0 for(@chapters)
650 {
651 0 my $el = $self->new($_->id);
652 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
653 {
654 0 return $el;
655 }
656 }
657 }
658 0 return undef;
659 }
660 sub get_first_by_date
661 0 ▶{
Subroutine get_first_by_date: not called CC=6 SCAR=37.4
Pod documented
662 0 my $self = shift;
663 0 my $cat = shift;
664 0 my $language = shift;
665 0 my $category = Strehler::Meta::Category->explode_name($cat);
666 0 ▶ return undef if(! $category->exists());
Branch: 1 branch
BranchTrueFalseTotal
unless $category->exists 0 0 0
667 0 my $category_access = $self->category_accessor($category->row);
668 0 my $criteria = {};
669 0 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 0 0 0
670 {
671 0 $criteria = { published => 1 };
672 }
673 0 my @chapters = $category->row->$category_access->search( $criteria, { order_by => { -asc => 'publish_date' } });
674 0 ▶ if($chapters[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($chapters[0]) 0 0 0
675 {
676 0 for(@chapters)
677 {
678 0 my $el = $self->new($_->id);
679 0 ▶ if($el->has_language($language))
Branch: 1 branch
BranchTrueFalseTotal
if ($el->has_language($language)) 0 0 0
680 {
681 0 return $el;
682 }
683 }
684 }
685 0 return undef;
686 }
687  
688 sub get_list
689 33 ▶{
Subroutine get_list: called CC=36 SCAR=37.0
Pod documented
690 33 my $self = shift;
691 33 my $params = shift;
692 33 my %args;
693 33 ▶ if($params)
Branch: 1 branch
BranchTrueFalseTotal
if ($params) { } 30 3 33
694 {
695 30 %args = %{ $params };
696 }
697 else
698 {
699 3 %args = ();
700 }
701  
702 33 ▶ $args{'order'} ||= 'desc';
Condition100%2/2
$args{"order"} ||= "desc"
l!l
726
MC/DC100%1/1
$args{"order"} ||= "desc"
$args{"order"}
Truth table100%2/2
A
A= $args{"order"}
Aresult
11
00
703 33 ▶ $args{'order_by'} ||= 'me.id';
Condition100%2/2
$args{"order_by"} ||= "me.id"
l!l
330
MC/DC100%1/1
$args{"order_by"} ||= "me.id"
$args{"order_by"}
Truth table100%2/2
A
A= $args{"order_by"}
Aresult
11
00
704 33 ▶ $args{'order_by'} = 'me.id' if $args{'order_by'} eq 'id';
Branch: 1 branch
BranchTrueFalseTotal
if $args{"order_by"} eq "id" 0 33 33
705 33 ▶ $args{'entries_per_page'} ||= 20;
Condition100%2/2
$args{"entries_per_page"} ||= 20
l!l
249
MC/DC100%1/1
$args{"entries_per_page"} ||= 20
$args{"entries_per_page"}
Truth table100%2/2
A
A= $args{"entries_per_page"}
Aresult
11
00
706 33 ▶ $args{'page'} ||= 1;
Condition100%2/2
$args{"page"} ||= 1
l!l
627
MC/DC100%1/1
$args{"page"} ||= 1
$args{"page"}
Truth table100%2/2
A
A= $args{"page"}
Aresult
11
00
707 33 ▶ $args{'join'} ||= [];
Condition50%1/2
$args{"join"} ||= []
l!l
033
MC/DC0%0/1
$args{"join"} ||= []
$args{"join"}
Truth table50%1/2
A
A= $args{"join"}
Aresult
11
00
708 33 ▶ $args{'join'} = [ $args{'join'} ] if(! ref($args{'join'}));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"join"} 0 33 33
709
710  
711 33 my $forced_language = 0;
712 33 my @languages_list = undef;
713 33 ▶ if($args{'language'})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'language'}) { } 10 23 33
714 {
715 #Languages arrive here as an array of strings
716 10 $forced_language = 1;
717 10 ▶ if($self->multilang_children())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multilang_children) 9 1 10
718 {
719 9 push @{$args{'join'}}, $self->multilang_children();
720 }
721 }
722 else
723 {
724 23 $args{'language'} = config->{Strehler}->{default_language};
725 }
726 33 my $no_paging = 0;
727 33 my $default_page = 1;
728 33 ▶ my $search_criteria = $args{'search'} || undef;
Condition50%1/2
$args{'search'} || undef
l!l
033
MC/DC0%0/1
$args{'search'} || undef
$args{'search'}
Truth table50%1/2
A
A= $args{'search'}
Aresult
11
00
729 33 ▶ if($forced_language)
Branch: 1 branch
BranchTrueFalseTotal
if ($forced_language) 10 23 33
730 {
731 10 ▶ if($self->multilang_children())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->multilang_children) 9 1 10
732 {
733 9 $search_criteria->{$self->multilang_children() . '.language'} = { -in => $args{'language'} };
734 }
735 }
736 33 ▶ if($args{'order_by'} =~ /^(.*?)\.(.*?)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"order_by"} =~ /^(.*?)\.(.*?)$/) 32 1 33
737 {
738 32 my $order_join = $1;
739 32 ▶ push @{$args{'join'}}, $order_join if $order_join ne 'me';
Branch: 1 branch
BranchTrueFalseTotal
if $order_join ne "me" 2 30 32
740 }
741 33 my %seen = ();
742 33 my @joins = grep { ! $seen{ $_ }++ } @{$args{'join'}};
743 33 $args{'join'} = \@joins;
744 33 ▶ if($args{'entries_per_page'} == -1)
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"entries_per_page"} == -1) 18 15 33
745 {
746 18 $args{'entries_per_page'} = undef;
747 18 $default_page = undef;
748 18 $no_paging = 1;
749 }
750  
751 33 ▶ if($self->publishable())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable) 14 19 33
752 {
753 14 ▶ if(exists $args{'published'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"published"}) 9 5 14
754 {
755 9 ▶ if($args{'published'} == 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'published'} == 1) { } 7 2 9
elsif ($args{'published'} == 0) { } 2 0 2
756 {
757 7 $search_criteria->{'published'} = $args{'published'};
758 }
759 elsif($args{'published'} == 0)
760 {
761 2 $search_criteria->{'published'} = [ undef, 0 ];
762 }
763 }
764 }
765 33 ▶ if(exists $args{'tag'} && $args{'tag'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"tag"} and $args{"tag"}) 0 33 33
Condition33%1/3
exists $args{"tag"} and $args{"tag"}
!ll&&!rl&&r
3300
MC/DC0%0/2
exists $args{"tag"} and $args{"tag"}
exists $args{"tag"} $args{"tag"}
Truth table33%1/3
A and B
A= exists $args{"tag"}B= $args{"tag"}
ABresult
0X0
100
111
766 {
767 0 my $ids = $self->get_schema()->resultset('Tag')->search({tag => $args{'tag'}, item_type => $self->item_type()})->get_column('item_id');
768 0 $search_criteria->{'me.id'} = { -in => $ids->as_query };
769 }
770 33 my $search_rules = { order_by => { '-' . $args{'order'} => $args{'order_by'} } , page => $default_page, rows => $args{'entries_per_page'}, join => $args{'join'}, distinct => 1 };
771  
772 33 my $rs;
773 33 ▶ if(exists $args{'category_id'} && $args{'category_id'})
Branch: 3 branches
BranchTrueFalseTotal
if (exists $args{'category_id'} and $args{'category_id'}) { } 0 33 33
elsif (exists $args{'category'} and $args{'category'}) { } 4 29 33
elsif (exists $args{'ancestor'} and $args{'ancestor'}) { } 1 28 29
Condition66%2/3
exists $args{"category_id"} and $args{"category_id"}
!ll&&!rl&&r
21120
MC/DC0%0/2
exists $args{"category_id"} and $args{"category_id"}
exists $args{"category_id"} $args{"category_id"}
Truth table66%2/3
A and B
A= exists $args{"category_id"}B= $args{"category_id"}
ABresult
0X0
100
111
774 {
775 0 my $category = $self->get_schema()->resultset('Category')->find( { id => $args{'category_id'} } );
776 0 ▶ if(! $category)
Branch: 1 branch
BranchTrueFalseTotal
unless ($category) 0 0 0
777 {
778 0 return {'to_view' => [], 'last_page' => 1 };
779 }
780 0 my $category_access = $self->category_accessor($category);
781 0 $rs = $category->$category_access->search($search_criteria, $search_rules);
782 }
783 ▶ elsif(exists $args{'category'} && $args{'category'})
Condition100%3/3
exists $args{"category"} and $args{"category"}
!ll&&!rl&&r
2364
MC/DC100%2/2
exists $args{"category"} and $args{"category"}
exists $args{"category"} $args{"category"}
Truth table100%3/3
A and B
A= exists $args{"category"}B= $args{"category"}
ABresult
0X0
100
111
784 {
785 4 my $category;
786 4 my $category_obj = Strehler::Meta::Category->explode_name($args{'category'});
787 4 ▶ if(! $category_obj->exists())
Branch: 1 branch
BranchTrueFalseTotal
if (not $category_obj->exists) { } 0 4 4
788 {
789 0 return {'to_view' => [], 'last_page' => 1 };
790 }
791 else
792 {
793 4 $category = $category_obj->row;
794 }
795 4 my $category_access = $self->category_accessor($category);
796 4 $rs = $category->$category_access->search($search_criteria, $search_rules);
797 }
798 ▶ elsif(exists $args{'ancestor'} && $args{'ancestor'})
Condition100%3/3
exists $args{"ancestor"} and $args{"ancestor"}
!ll&&!rl&&r
17111
MC/DC100%2/2
exists $args{"ancestor"} and $args{"ancestor"}
exists $args{"ancestor"} $args{"ancestor"}
Truth table100%3/3
A and B
A= exists $args{"ancestor"}B= $args{"ancestor"}
ABresult
0X0
100
111
799 {
800 1 my $category_obj = Strehler::Meta::Category->new($args{'ancestor'});
801 1 my @category_ids;
802 1 push @category_ids, $args{'ancestor'};
803 1 my @subcategories = $category_obj->subcategories(1);
804 1 for(@subcategories)
805 {
806 0 push @category_ids, $_->get_attr('id');
807 }
808 1 $search_criteria->{'category'} = { -in => \@category_ids };
809 1 $rs = $self->get_schema()->resultset($self->ORMObj())->search($search_criteria, $search_rules);
810 }
811 else
812 {
813 28 $rs = $self->get_schema()->resultset($self->ORMObj())->search($search_criteria, $search_rules);
814 }
815
816 33 my $elements;
817 my $last_page;
818 33 ▶ if($no_paging)
Branch: 1 branch
BranchTrueFalseTotal
if ($no_paging) { } 18 15 33
819 {
820 18 $elements = $rs;
821 18 $last_page = 1;
822 }
823 else
824 {
825 15 my $pager = $rs->pager();
826 15 $elements = $rs->page($args{'page'});
827 15 $last_page = $pager->last_page();
828 }
829 33 my @to_view;
830 33 for($elements->all())
831 {
832 29 my $img = $self->new($_->id);
833 29 my %el;
834 29 ▶ if(exists $args{'json'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'json'}) { } 9 20 29
835 {
836 9 %el = $img->get_json_data($args{'language'});
837 }
838 else
839 {
840 20 ▶ if(exists $args{'ext'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'ext'}) { } 0 20 20
841 {
842 0 %el = $img->get_ext_data($args{'language'});
843 }
844 else
845 {
846 20 %el = $img->get_basic_data();
847 }
848 }
849 29 push @to_view, \%el;
850 }
851 33 return {'to_view' => \@to_view, 'last_page' => $last_page};
852 }
853  
854 sub has_tag
855 0 ▶{
Subroutine has_tag: not called CC=2 SCAR=17.9
Pod undocumented
856 0 my $self = shift;
857 0 my $tag = shift;
858 0 ▶ return 0 if(! $self->categorized());
Branch: 1 branch
BranchTrueFalseTotal
unless $self->categorized 0 0 0
859 0 return Strehler::Meta::Tag->exists_tag($self->get_attr('id'), $self->item_type(), $tag);
860 }
861  
862 sub search_box
863 0 ▶{
Subroutine search_box: not called CC=1 SCAR=6.9
Pod undocumented
864 0 my $self = shift;
865 0 my $string = shift;
866 0 my $parameters = shift;
867 0 $parameters->{'search'} = { $self->default_field() => { 'like', "%$string%" } };
868 0 return $self->get_list($parameters);
869 }
870  
871 sub make_select
872 14 ▶{
Subroutine make_select: called CC=2 SCAR=7.1
Pod undocumented
873 14 my $self = shift;
874 14 my $list = $self->get_list( { entries_per_page => -1 } );
875 14 my @category_values_for_select;
876 14 push @category_values_for_select, { value => undef, label => "-- select --" };
877 14 my @elements = @{$list->{to_view}};
878 0 @elements = sort { lc($a->{'title'}) cmp lc($b->{'title'}) } @elements;
879 14 for(@elements)
880 {
881 0 push @category_values_for_select, { value => $_->{'id'}, label => $_->{'title'} }
882 }
883 14 return \@category_values_for_select;
884 }
885  
886 sub get_form_data
887 0 ▶{
Subroutine get_form_data: not called CC=17 SCAR=57.2
Pod undocumented
888 0 my $self = shift;
889 0 my $el_row = $self->row;
890 0 my %columns = $el_row->get_columns;
891 0 my $data = \%columns;
892 0 foreach my $attribute (keys %columns)
893 {
894 0 ▶ if($el_row->result_source->column_info($attribute)->{'data_type'} eq 'timestamp' || $el_row->result_source->column_info($attribute)->{'data_type'} eq 'date' || $el_row->result_source->column_info($attribute)->{'data_type'} eq 'datetime')
Branch: 1 branch
BranchTrueFalseTotal
if ($el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "date" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "datetime") 0 0 0
Condition0%0/6
$el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "date" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
l!l&&r!l&&!r
000
$el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "date"
l!l&&r!l&&!r
000
MC/DC0%0/3
$el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "date" or $el_row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
$el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp" $el_row->result_source->column_info($attribute)->{"data_type"} eq "date" $el_row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
Truth table0%0/4
A or B or C
A= $el_row->result_source->column_info($attribute)->{"data_type"} eq "timestamp"B= $el_row->result_source->column_info($attribute)->{"data_type"} eq "date"C= $el_row->result_source->column_info($attribute)->{"data_type"} eq "datetime"
ABCresult
1XX1
01X1
0011
0000
895 {
896 0 $data->{$attribute} = $el_row->$attribute;
897 }
898 }
899 0 ▶ if($self->categorized()) #Is the element categorized?
Branch: 1 branch
BranchTrueFalseTotal
if ($self->categorized) 0 0 0
900 {
901 0 ▶ if($el_row->category)
Branch: 1 branch
BranchTrueFalseTotal
if ($el_row->category) { } 0 0 0
902 {
903 0 $data->{'category'} = $el_row->category->id;
904 }
905 else
906 {
907 0 $data->{'category'} = undef;
908 }
909 }
910 0 $data->{'tags'} = $self->get_tags();
911 0 my $children = $self->row->can($self->multilang_children());
912 0 ▶ if($children)
Branch: 1 branch
BranchTrueFalseTotal
if ($children) 0 0 0
913 {
914 0 my @multilang_rows = $self->row->$children;
915 0 foreach my $ml (@multilang_rows)
916 {
917 0 my %ml_columns = $ml->get_columns;
918 0 foreach my $k (keys %ml_columns)
919 {
920 0 ▶ if($k ne 'id' && $k ne $self->item_type() && $k ne 'language')
Branch: 1 branch
BranchTrueFalseTotal
if ($k ne "id" and $k ne $self->item_type and $k ne "language") 0 0 0
Condition0%0/6
$k ne "id" and $k ne $self->item_type and $k ne "language"
!ll&&!rl&&r
000
$k ne "id" and $k ne $self->item_type
!ll&&!rl&&r
000
MC/DC0%0/3
$k ne "id" and $k ne $self->item_type and $k ne "language"
$k ne "id" $k ne $self->item_type $k ne "language"
Truth table0%0/4
A and B and C
A= $k ne "id"B= $k ne $self->item_typeC= $k ne "language"
ABCresult
0XX0
10X0
1100
1111
921 {
922 0 foreach my $attribute (keys %columns)
923 {
924 0 my $data_to_save;
925 0 ▶ if($ml->result_source->column_info($k)->{'data_type'} eq 'timestamp' || $ml->result_source->column_info($k)->{'data_type'} eq 'date' || $ml->result_source->column_info($k)->{'data_type'} eq 'datetime')
Branch: 1 branch
BranchTrueFalseTotal
if ($ml->result_source->column_info($k)->{'data_type'} eq 'timestamp' or $ml->result_source->column_info($k)->{'data_type'} eq 'date' or $ml->result_source->column_info($k)->{'data_type'} eq 'datetime') { } 0 0 0
Condition0%0/6
$ml->result_source->column_info($k)->{"data_type"} eq "timestamp" or $ml->result_source->column_info($k)->{"data_type"} eq "date" or $ml->result_source->column_info($k)->{"data_type"} eq "datetime"
l!l&&r!l&&!r
000
$ml->result_source->column_info($k)->{"data_type"} eq "timestamp" or $ml->result_source->column_info($k)->{"data_type"} eq "date"
l!l&&r!l&&!r
000
MC/DC0%0/3
$ml->result_source->column_info($k)->{"data_type"} eq "timestamp" or $ml->result_source->column_info($k)->{"data_type"} eq "date" or $ml->result_source->column_info($k)->{"data_type"} eq "datetime"
$ml->result_source->column_info($k)->{"data_type"} eq "timestamp" $ml->result_source->column_info($k)->{"data_type"} eq "date" $ml->result_source->column_info($k)->{"data_type"} eq "datetime"
Truth table0%0/4
A or B or C
A= $ml->result_source->column_info($k)->{"data_type"} eq "timestamp"B= $ml->result_source->column_info($k)->{"data_type"} eq "date"C= $ml->result_source->column_info($k)->{"data_type"} eq "datetime"
ABCresult
1XX1
01X1
0011
0000
926 {
927 0 $data_to_save = $ml->$attribute;
928 }
929 else
930 {
931 0 $data_to_save = $ml_columns{$k};
932 }
933 0 $data->{$k . '_' . $ml_columns{'language'}} = $data_to_save;
934 }
935 }
936 }
937 }
938 }
939 0 return $data;
940 }
941  
942 sub form_modifications
943 0 ▶{
Subroutine form_modifications: not called CC=1 SCAR=6.9
Pod undocumented
944 0 my $self = shift;
945 0 my $form = shift;
946 0 return $form;
947 }
948  
949 sub save_form
950 14 ▶{
Subroutine save_form: called CC=30 SCAR=38.7
Pod undocumented
951 14 my $self = shift;
952 14 my $id = shift;
953 14 my $form = shift;
954
955 14 my $el_row;
956 my $el_data;
957 14 my %standby_accessors;
958 14 foreach my $column ($self->get_schema()->resultset($self->ORMObj())->result_source->columns)
959 {
960 85 ▶ if($column ne 'category' && $column ne 'id' && $column ne 'published')
Branch: 2 branches
BranchTrueFalseTotal
if ($column ne 'category' and $column ne 'id' and $column ne 'published') { } 43 42 85
elsif ($column eq 'category') { } 14 28 42
Condition100%6/6
$column ne "category" and $column ne "id" and $column ne "published"
!ll&&!rl&&r
281443
$column ne "category" and $column ne "id"
!ll&&!rl&&r
141457
MC/DC100%3/3
$column ne "category" and $column ne "id" and $column ne "published"
$column ne "category" $column ne "id" $column ne "published"
Truth table100%4/4
A and B and C
A= $column ne "category"B= $column ne "id"C= $column ne "published"
ABCresult
0XX0
10X0
1100
1111
961 {
962 43 ▶ if($form->param_value($column))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->param_value($column)) { } 25 18 43
963 {
964 25 ▶ if(ref $form->param_value($column) eq 'DateTime')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $form->param_value($column) eq 'DateTime') { } 11 14 25
965 {
966 11 ▶ if($self->get_schema()->resultset($self->ORMObj())->result_source->column_info($column)->{'data_type'} eq 'date')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_schema->resultset($self->ORMObj)->result_source->column_info($column)->{'data_type'} eq 'date') { } 11 0 11
967 {
968 11 $el_data->{$column} = $form->param_value($column);
969 }
970 else
971 {
972 0 my $ts = $form->param_value($column);
973 0 $ts->set_time_zone(config->{'Strehler'}->{'timezone'});
974 0 $ts->set_time_zone('UTC');
975 0 $el_data->{$column} = $ts;
976 }
977 }
978 else
979 {
980 14 $el_data->{$column} = $form->param_value($column);
981 }
982 }
983 else
984 {
985 18 my $accessor = $self->can('save_' . $column);
986 18 ▶ if($accessor)
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor) 1 17 18
987 {
988 1 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 0 1 1
989 {
990 0 $el_data->{$column} = $self->$accessor($id, $form, undef);
991 }
992 else
993 {
994 1 $standby_accessors{$column} = $accessor;
995 }
996 }
997 }
998 }
999 elsif($column eq 'category')
1000 {
1001 14 ▶ if($form->param_value('category'))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->param_value("category")) 14 0 14
1002 {
1003 14 $el_data->{'category'} = $form->param_value('category');
1004 }
1005 }
1006 }
1007 14 ▶ if($self->publishable() && $self->auto_publish() && ! $id)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->publishable and $self->auto_publish and not $id) 0 14 14
Condition50%3/6
$self->publishable and $self->auto_publish and not $id
!ll&&!rl&&r
1400
$self->publishable and $self->auto_publish
!ll&&!rl&&r
1130
MC/DC0%0/3
$self->publishable and $self->auto_publish and not $id
$self->publishable $self->auto_publish not $id
Truth table50%2/4
A and B and not(C)
A= $self->publishableB= $self->auto_publishC= not $id
ABCresult
0XX0
10X0
1100
1111
1008 {
1009 0 $el_data->{'published'} = 1;
1010 }
1011 14 ▶ if($form->param_value('strehl-action') eq 'submit-publish')
Branch: 1 branch
BranchTrueFalseTotal
if ($form->param_value("strehl-action") eq "submit-publish") 0 14 14
1012 {
1013 0 $el_data->{'published'} = 1;
1014 }
1015 14 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 0 14 14
1016 {
1017 0 $el_row = $self->get_schema()->resultset($self->ORMObj())->find($id);
1018 0 $el_row->update($el_data);
1019 }
1020 else
1021 {
1022 14 $el_row = $self->get_schema()->resultset($self->ORMObj())->create($el_data);
1023 }
1024 14 my $standby_data;
1025 14 foreach(keys %standby_accessors)
1026 {
1027 1 my $accessor = $standby_accessors{$_};
1028 1 $standby_data->{$_} = $self->$accessor($el_row->id, $form, undef);
1029 }
1030 14 $el_row->update($standby_data);
1031 14 my $children = undef;
1032 14 ▶ if($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 0 14 14
1033 {
1034 0 $children = $el_row->can($self->multilang_children());
1035 0 ▶ $el_row->$children->delete_all() if($children);
Branch: 1 branch
BranchTrueFalseTotal
if $children 0 0 0
1036 }
1037 else
1038 {
1039 14 $children = $el_row->can($self->multilang_children());
1040 }
1041 14 ▶ if($children)
Branch: 1 branch
BranchTrueFalseTotal
if ($children) 13 1 14
1042 {
1043 13 my @languages = @{config->{Strehler}->{languages}};
1044 13 foreach my $lang (@languages)
1045 {
1046 26 my $to_write = 0;
1047 26 my $multi_el_data;
1048 26 foreach my $multicolumn ($self->get_schema()->resultset($self->ORMObj())->$children->result_source->columns)
1049 {
1050 156 ▶ if($form->param_value($multicolumn . '_' . $lang))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->param_value($multicolumn . '_' . $lang)) { } 42 114 156
1051 {
1052 42 ▶ if(ref $form->param_value($multicolumn . '_' . $lang) eq 'DateTime')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $form->param_value($multicolumn . '_' . $lang) eq 'DateTime') { } 0 42 42
1053 {
1054 0 ▶ if($self->get_schema()->resultset($self->ORMObj())->$children->result_source->column_info($multicolumn)->{'data_type'} eq 'date')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_schema->resultset($self->ORMObj)->$children->result_source->column_info($multicolumn)->{'data_type'} eq 'date') { } 0 0 0
1055 {
1056 0 $multi_el_data->{$multicolumn} = $form->param_value($multicolumn . '_' . $lang);
1057 }
1058 else
1059 {
1060 0 my $ts = $form->param_value($multicolumn . '_' . $lang);
1061 0 $ts->set_time_zone(config->{'Strehler'}->{'timezone'});
1062 0 $ts->set_time_zone('UTC');
1063 0 $multi_el_data->{$multicolumn} = $ts;
1064 }
1065 }
1066 else
1067 {
1068 42 $multi_el_data->{$multicolumn} = $form->param_value($multicolumn . '_' . $lang);
1069 42 $to_write = 1;
1070 }
1071 }
1072 else
1073 {
1074 114 my $accessor = $self->can('save_' . $multicolumn);
1075 114 ▶ if($accessor)
Branch: 1 branch
BranchTrueFalseTotal
if ($accessor) 26 88 114
1076 {
1077 26 $multi_el_data->{$multicolumn} = $self->$accessor($el_row->id, $form, $lang);
1078 }
1079 114 ▶ $to_write = 1 if $multi_el_data->{$multicolumn};
Branch: 1 branch
BranchTrueFalseTotal
if $multi_el_data->{$multicolumn} 21 93 114
1080 }
1081 }
1082 26 ▶ if($to_write)
Branch: 1 branch
BranchTrueFalseTotal
if ($to_write) 21 5 26
1083 {
1084 21 $multi_el_data->{'language'} = $lang;
1085 21 $el_row->$children->create( $multi_el_data );
1086 }
1087 }
1088 }
1089 14 ▶ if($form->param_value('tags'))
Branch: 1 branch
BranchTrueFalseTotal
if ($form->param_value("tags")) 14 0 14
1090 {
1091 14 Strehler::Meta::Tag->save_tags($form->param_value('tags'), $el_row->id, $self->item_type());
1092 }
1093 14 return $el_row->id;
1094 }
1095  
1096 sub check_role
1097 36 ▶{
Subroutine check_role: called CC=4 SCAR=13.9
Pod documented
1098 36 my $self = shift;
1099 36 my $user_role = shift;
1100 36 ▶ if(! config->{Strehler}->{admin_secured})
Branch: 1 branch
BranchTrueFalseTotal
unless (config()->{"Strehler"}{"admin_secured"}) 29 7 36
1101 {
1102 29 return 1;
1103 }
1104 7 my $role = $self->allowed_role();
1105 7 ▶ if($role)
Branch: 1 branch
BranchTrueFalseTotal
if ($role) { } 6 1 7
1106 {
1107 6 ▶ if($user_role eq $role)
Branch: 1 branch
BranchTrueFalseTotal
if ($user_role eq $role) { } 6 0 6
1108 {
1109 6 return 1;
1110 }
1111 else
1112 {
1113 0 return 0;
1114 }
1115 }
1116 else
1117 {
1118 1 return 1;
1119 }
1120 }
1121  
1122 sub error_message
1123 2 ▶{
Subroutine error_message: called CC=2 SCAR=7.2
Pod documented
1124 2 my $self = shift;
1125 2 my $action = shift;
1126 2 my $code = shift;
1127 2 ▶ if($code == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 0) { } 0 2 2
1128 {
1129 0 return "OK";
1130 }
1131 else
1132 {
1133 2 return "An error has occurred";
1134 }
1135 }
1136  
1137  
1138  
1139 12 1;
« lib/Strehler/Dancer2/Plugin/EX.pm ↑ Summary lib/Strehler/Admin.pm »