| 1 | package Strehler::Meta::Tag; | ||||||||||||||
| 2 | 12 | $Strehler::Meta::Tag::VERSION = '1.6.8'; | |||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 12 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 12 | ▶ | use Dancer2 0.166001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 12 | ▶ | use Dancer2::Plugin::DBIC; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 12 | ▶ | use Strehler::Meta::Category; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 12 | has row => ( | |||||||||||||
| 10 | is => 'ro', | ||||||||||||||
| 11 | ); | ||||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | sub BUILDARGS { | ||||||||||||
|
Subroutine
BUILDARGS: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 14 | 0 | my ( $class, @args ) = @_; | |||||||||||||
| 15 | 0 | my $tag = undef; | |||||||||||||
| 16 | 0 | ▶ | if($#args == 0) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | { | ||||||||||||||
| 18 | 0 | my $id = shift @args; | |||||||||||||
| 19 | 0 | $tag = $class->get_schema()->resultset('Tag')->find($id); | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | elsif($#args == 1) | ||||||||||||||
| 22 | { | ||||||||||||||
| 23 | 0 | ▶ | if($args[0] eq 'tag') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | { | ||||||||||||||
| 25 | 0 | $tag = $class->get_schema()->resultset('Tag')->find({ tag => $args[1] }); | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | 0 | ▶ | if($args[0] eq 'row') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | { | ||||||||||||||
| 29 | 0 | $tag = $args[1]; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | } | ||||||||||||||
| 32 | 0 | return { row => $tag }; | |||||||||||||
| 33 | }; | ||||||||||||||
| 34 | sub get_schema | ||||||||||||||
| 35 | 86 | ▶ | { | ||||||||||||
|
Subroutine
get_schema: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||
| 36 | 86 | ▶ | if(config->{'Strehler'}->{'schema'}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | { | ||||||||||||||
| 38 | 0 | return schema config->{'Strehler'}->{'schema'}; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | else | ||||||||||||||
| 41 | { | ||||||||||||||
| 42 | 86 | return schema; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | |||||||||||||||
| 47 | sub tags_to_string | ||||||||||||||
| 48 | 0 | ▶ | { | ||||||||||||
|
Subroutine
tags_to_string: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||
| 50 | 0 | my $item = shift; | |||||||||||||
| 51 | 0 | my $item_type = shift; | |||||||||||||
| 52 | 0 | my @tags = $self->get_schema()->resultset('Tag')->search({ item_id => $item, item_type => $item_type }); | |||||||||||||
| 53 | 0 | my $out = ""; | |||||||||||||
| 54 | 0 | for(@tags) | |||||||||||||
| 55 | { | ||||||||||||||
| 56 | 0 | $out .= $_->tag . ","; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | 0 | $out =~ s/,$//; | |||||||||||||
| 59 | 0 | return $out; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | sub save_tags | ||||||||||||||
| 63 | 15 | ▶ | { | ||||||||||||
|
Subroutine
save_tags: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||
| 64 | 15 | my $self = shift; | |||||||||||||
| 65 | 15 | my $string = shift; | |||||||||||||
| 66 | 15 | my $item = shift; | |||||||||||||
| 67 | 15 | my $item_type = shift; | |||||||||||||
| 68 | 15 | ▶ | $string ||= ''; | ||||||||||||
|
Condition50%1/2
$string ||= ""
MC/DC0%0/1
$string ||= ""
$string
Truth table50%1/2
A
A= $string
| |||||||||||||||
| 69 | 15 | $string =~ s/( +)?,( +)?/,/g; | |||||||||||||
| 70 | 15 | my @tags = split(',', $string); | |||||||||||||
| 71 | 15 | $self->get_schema()->resultset('Tag')->search({item_id => $item, item_type => $item_type})->delete_all(); | |||||||||||||
| 72 | 15 | my %already; | |||||||||||||
| 73 | 15 | for(@tags) | |||||||||||||
| 74 | { | ||||||||||||||
| 75 | 15 | ▶ | if(! $already{$_}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | { | ||||||||||||||
| 77 | 15 | $already{$_} = 1; | |||||||||||||
| 78 | 15 | my $new_tag = $self->get_schema()->resultset('Tag')->create({tag => $_, item_id => $item, item_type => $item_type}); | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 15 | return; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | sub get_configured_tags | ||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||
|
Subroutine
get_configured_tags: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||
| 88 | 0 | my $category_name = shift; | |||||||||||||
| 89 | 0 | my $t = shift; | |||||||||||||
| 90 | 0 | my @types = @{$t}; | |||||||||||||
| 91 | 0 | my $out; | |||||||||||||
| 92 | 0 | my $category = Strehler::Meta::Category->explode_name($category_name); | |||||||||||||
| 93 | 0 | foreach my $t (@types) | |||||||||||||
| 94 | { | ||||||||||||||
| 95 | 0 | my @tags = $self->get_schema()->resultset('ConfiguredTag')->search({category_id => $category->get_attr('id'), item_type => $t}); | |||||||||||||
| 96 | 0 | my $string = ''; | |||||||||||||
| 97 | 0 | my $default = ''; | |||||||||||||
| 98 | 0 | for(@tags) | |||||||||||||
| 99 | { | ||||||||||||||
| 100 | 0 | $string .= $_->tag; | |||||||||||||
| 101 | 0 | $string .= ","; | |||||||||||||
| 102 | 0 | ▶ | if($_->default_tag == 1) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | { | ||||||||||||||
| 104 | 0 | $default .= $_->tag; | |||||||||||||
| 105 | 0 | $default .= ","; | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | } | ||||||||||||||
| 108 | 0 | $string =~ s/,$//; | |||||||||||||
| 109 | 0 | $default =~ s/,$//; | |||||||||||||
| 110 | 0 | ▶ | if($string ne '') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | { | ||||||||||||||
| 112 | 0 | $out->{$t} = $string; | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | else | ||||||||||||||
| 115 | { | ||||||||||||||
| 116 | 0 | $out->{$t} = undef; | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | 0 | $out->{'default-' . $t} = $default; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | 0 | return $out; | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | sub get_configured_tags_for_template | ||||||||||||||
| 123 | 0 | ▶ | { | ||||||||||||
|
Subroutine
get_configured_tags_for_template: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||
| 125 | 0 | my $category_name = shift; | |||||||||||||
| 126 | 0 | my $type = shift; | |||||||||||||
| 127 | 0 | my $category = Strehler::Meta::Category->explode_name($category_name); | |||||||||||||
| 128 | 0 | my @tags = $self->get_schema()->resultset('ConfiguredTag')->search({category_id => $category->get_attr('id'), item_type => 'all'}); | |||||||||||||
| 129 | 0 | ▶ | if($#tags > -1) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 130 | { | ||||||||||||||
| 131 | 0 | return @tags; | |||||||||||||
| 132 | } | ||||||||||||||
| 133 | else | ||||||||||||||
| 134 | { | ||||||||||||||
| 135 | 0 | @tags = $self->get_schema()->resultset('ConfiguredTag')->search({category_id => $category->get_attr('id'), item_type => $type}); | |||||||||||||
| 136 | 0 | return @tags; | |||||||||||||
| 137 | } | ||||||||||||||
| 138 | } | ||||||||||||||
| 139 | |||||||||||||||
| 140 | sub save_configured_tags | ||||||||||||||
| 141 | 14 | ▶ | { | ||||||||||||
|
Subroutine
save_configured_tags: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||
| 142 | 14 | my $self = shift; | |||||||||||||
| 143 | 14 | my $string = shift; | |||||||||||||
| 144 | 14 | my $default_tags = shift; | |||||||||||||
| 145 | 14 | my $category = shift; | |||||||||||||
| 146 | 14 | my $type = shift; | |||||||||||||
| 147 | 14 | ▶ | $default_tags ||= ''; | ||||||||||||
|
Condition100%2/2
$default_tags ||= ""
MC/DC100%1/1
$default_tags ||= ""
$default_tags
Truth table100%2/2
A
A= $default_tags
| |||||||||||||||
| 148 | 14 | $string =~ s/( +)?,( +)?/,/g; | |||||||||||||
| 149 | 14 | $default_tags =~ s/( +)?,( +)?/,/g; | |||||||||||||
| 150 | 14 | my @tags = split(',', $string); | |||||||||||||
| 151 | 14 | my @dtags = split(',', $default_tags); | |||||||||||||
| 152 | 14 | my %already; | |||||||||||||
| 153 | 14 | foreach my $t (@tags) | |||||||||||||
| 154 | { | ||||||||||||||
| 155 | 42 | ▶ | if(! $already{$t}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 156 | { | ||||||||||||||
| 157 | 42 | $already{$t} = 1; | |||||||||||||
| 158 | 42 | my $default = 0; | |||||||||||||
| 159 | 42 | ▶ | if (grep {$_ eq $t} @dtags) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 160 | 8 | $default = 1; | |||||||||||||
| 161 | } | ||||||||||||||
| 162 | 42 | $self->get_schema()->resultset('ConfiguredTag')->create({tag => $t, category_id => $category, item_type => $type, default_tag => $default}); | |||||||||||||
| 163 | } | ||||||||||||||
| 164 | } | ||||||||||||||
| 165 | |||||||||||||||
| 166 | 14 | return; | |||||||||||||
| 167 | } | ||||||||||||||
| 168 | |||||||||||||||
| 169 | sub clean_configured_tags | ||||||||||||||
| 170 | 14 | ▶ | { | ||||||||||||
|
Subroutine
clean_configured_tags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 171 | 14 | my $self = shift; | |||||||||||||
| 172 | 14 | my $category = shift; | |||||||||||||
| 173 | 14 | $self->get_schema()->resultset('ConfiguredTag')->search({ category_id => $category })->delete_all(); | |||||||||||||
| 174 | |||||||||||||||
| 175 | 14 | return; | |||||||||||||
| 176 | } | ||||||||||||||
| 177 | sub exists_tag | ||||||||||||||
| 178 | 0 | ▶ | { | ||||||||||||
|
Subroutine
exists_tag: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 179 | 0 | my $self = shift; | |||||||||||||
| 180 | 0 | my $id = shift; | |||||||||||||
| 181 | 0 | my $entity = shift; | |||||||||||||
| 182 | 0 | my $tag = shift; | |||||||||||||
| 183 | 0 | my $many = $self->get_schema()->resultset('Tag')->search({tag => $tag, item_id => $id, item_type => $entity})->count(); | |||||||||||||
| 184 | 0 | return $many > 0; | |||||||||||||
| 185 | } | ||||||||||||||
| 186 | |||||||||||||||
| 187 | =encoding utf8 | ||||||||||||||
| 188 | |||||||||||||||
| 189 | =head1 NAME | ||||||||||||||
| 190 | |||||||||||||||
| 191 | Strehler::Meta::Tag - Strehler Entity for Tags | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =head1 DESCRIPTION | ||||||||||||||
| 194 | |||||||||||||||
| 195 | Tags. Tags can be used to give a classification of contents other than the one given by categories. | ||||||||||||||
| 196 | |||||||||||||||
| 197 | In the forms, tags are alway presented as a list of strings separated with comma or as checkbox, but in the database every link tag-entity is a line on a table. Tag module gives abstraction for this. | ||||||||||||||
| 198 | |||||||||||||||
| 199 | =cut | ||||||||||||||
| 200 | |||||||||||||||
| 201 | |||||||||||||||
| 202 | |||||||||||||||
| 203 | 12 | 1; | |||||||||||||
| 204 | |||||||||||||||
| 205 | |||||||||||||||
| 206 | |||||||||||||||
| 207 | |||||||||||||||
| 208 | |||||||||||||||
| 209 | |||||||||||||||
| 210 | |||||||||||||||