| 1 | package Strehler::Element::Image; | ||||||||||||||||||||||||||||
| 2 | 12 | $Strehler::Element::Image::VERSION = '1.6.8'; | |||||||||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use Cwd 'abs_path'; | ||||||||||||||||||||||||||
|
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 | |||||||||||||||||||||||||||||
| 9 | 12 | extends 'Strehler::Element'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 12 | my $module_file_path = __FILE__; | |||||||||||||||||||||||||||
| 12 | 12 | my $root_path = abs_path($module_file_path); | |||||||||||||||||||||||||||
| 13 | 12 | $root_path =~ s/Image\.pm//; | |||||||||||||||||||||||||||
| 14 | 12 | my $form_path = $root_path . "../forms"; | |||||||||||||||||||||||||||
| 15 | 12 | my $views_path = $root_path . "../views"; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #Standard element implementation | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub metaclass_data | ||||||||||||||||||||||||||||
| 20 | 181 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
metaclass_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 181 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 181 | my $param = shift; | |||||||||||||||||||||||||||
| 23 | 181 | my %element_conf = ( item_type => 'image', | |||||||||||||||||||||||||||
| 24 | ORMObj => 'Image', | ||||||||||||||||||||||||||||
| 25 | category_accessor => 'images', | ||||||||||||||||||||||||||||
| 26 | multilang_children => 'descriptions' ); | ||||||||||||||||||||||||||||
| 27 | 181 | return $element_conf{$param}; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #Standard configuration overrides | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub label | ||||||||||||||||||||||||||||
| 33 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
label: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 6 | return $self->_property('label', 'Images'); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | sub categorized | ||||||||||||||||||||||||||||
| 38 | 42 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
categorized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 42 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 42 | return $self->_property('categorized', 1); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub class | ||||||||||||||||||||||||||||
| 44 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 4 | return __PACKAGE__; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | sub form | ||||||||||||||||||||||||||||
| 48 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 7 | return $form_path . '/admin/image.yml'; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | sub multilang_form | ||||||||||||||||||||||||||||
| 52 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
multilang_form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 7 | return $form_path . '/admin/image_multilang.yml'; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | #Main title redefined to fetch title from multilang attributes | ||||||||||||||||||||||||||||
| 58 | sub main_title | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
main_title: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 1 | my @desc = $self->row->descriptions->search({ language => config->{Strehler}->{default_language } }); | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | if($desc[0]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | 1 | return $desc[0]->title; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 0 | return "*** no title ***"; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | sub fields_list | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
fields_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 74 | 2 | my @fields = ( { 'id' => 'id', | |||||||||||||||||||||||||||
| 75 | 'label' => 'ID', | ||||||||||||||||||||||||||||
| 76 | 'ordinable' => 1 }, | ||||||||||||||||||||||||||||
| 77 | { 'id' => 'descriptions.title', | ||||||||||||||||||||||||||||
| 78 | 'label' => 'Title', | ||||||||||||||||||||||||||||
| 79 | 'ordinable' => 1 }, | ||||||||||||||||||||||||||||
| 80 | { 'id' => 'category', | ||||||||||||||||||||||||||||
| 81 | 'label' => 'Category', | ||||||||||||||||||||||||||||
| 82 | 'ordinable' => 0 }, | ||||||||||||||||||||||||||||
| 83 | { 'id' => 'Preview', | ||||||||||||||||||||||||||||
| 84 | 'label' => 'Preview', | ||||||||||||||||||||||||||||
| 85 | 'ordinable' => 0 } | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | 2 | return \@fields; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | #Save form redefined to manage image upload | ||||||||||||||||||||||||||||
| 92 | sub save_form | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
save_form: called CC=8 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 1 | my $id = shift; | |||||||||||||||||||||||||||
| 96 | 1 | my $form = shift; | |||||||||||||||||||||||||||
| 97 | 1 | my $uploads = shift; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | my $img = $uploads->{'photo'}; | |||||||||||||||||||||||||||
| 100 | 1 | my $ref; | |||||||||||||||||||||||||||
| 101 | my $path; | ||||||||||||||||||||||||||||
| 102 | 1 | my $public; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if($img) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 1 | $public = Strehler::Helpers::public_directory(); | |||||||||||||||||||||||||||
| 107 | 1 | $ref = '/upload/' . $img->filename; | |||||||||||||||||||||||||||
| 108 | 1 | $path = $public . $ref; | |||||||||||||||||||||||||||
| 109 | 1 | $img->copy_to($path); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | my $category; | |||||||||||||||||||||||||||
| 113 | 1 | ▶ | if($form->param_value('category')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 1 | $category = $form->param_value('category'); | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | my $img_row; | |||||||||||||||||||||||||||
| 119 | 1 | ▶ | if($id) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 0 | $img_row = $self->get_schema()->resultset('Image')->find($id); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if($img) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 0 | $img_row->update({ image => $ref, category => $category }); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | else | ||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 0 | $img_row->update({ category => $category }); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | $img_row->descriptions->delete_all(); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | else | ||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 1 | $img_row = $self->get_schema()->resultset('Image')->create({ image => $ref, category => $category }); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 1 | my @languages = @{config->{Strehler}->{languages}}; | |||||||||||||||||||||||||||
| 137 | 1 | for(@languages) | |||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 2 | my $lan = $_; | |||||||||||||||||||||||||||
| 140 | 2 | ▶ | $img_row->descriptions->create( { title => $form->param_value('title_' . $lan), description => $form->param_value('description_' . $lan), language => $lan }) if($form->param_value('title_' . $lan) || $form->param_value('description_' . $lan));; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$form->param_value('title_' . $lan) or $form->param_value('description_' . $lan)
MC/DC0%0/2
$form->param_value('title_' . $lan) or $form->param_value('description_' . $lan)
$form->param_value('title_' . $lan)
$form->param_value('description_' . $lan)
Truth table33%1/3
A or B
A= $form->param_value('title_' . $lan)B= $form->param_value('description_' . $lan)
| |||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | 1 | Strehler::Meta::Tag->save_tags($form->param_value('tags'), $img_row->id, 'image'); | |||||||||||||||||||||||||||
| 143 | 1 | return $img_row->id; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | sub search_box | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
search_box: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | 0 | my $string = shift; | |||||||||||||||||||||||||||
| 149 | 0 | my $parameters = shift; | |||||||||||||||||||||||||||
| 150 | 0 | $parameters->{'search'} = { 'descriptions.title' => { 'like', "%$string%" } }; | |||||||||||||||||||||||||||
| 151 | 0 | $parameters->{'join'} = 'descriptions'; | |||||||||||||||||||||||||||
| 152 | 0 | return $self->get_list($parameters); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub custom_add_snippet | ||||||||||||||||||||||||||||
| 156 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
custom_add_snippet: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 2 | ▶ | if(ref($self)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | 1 | return "<p>Image:</p>" . | |||||||||||||||||||||||||||
| 161 | '<img class="span2" src=' . $self->get_attr('image') . " />"; | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | else | ||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 1 | return undef; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | sub custom_list_template | ||||||||||||||||||||||||||||
| 170 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
custom_list_template: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 171 | 6 | return $views_path . "/admin/entities/image_list_block.tt"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | sub install | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 176 | 0 | return "Standard entity. No installation is needed."; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =encoding utf8 | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head1 NAME | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | Strehler::Element::Image - Strehler Entity for images | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | Base Strehler content, it's used to create images, multilanguage. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Its main title is the title in the language configured as default. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | It has all the features of base Strehler::Element plus the capability to upload images. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 12 | 1; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||