| 1 | package Strehler::Element::Article; | ||||||||||
| 2 | 12 | $Strehler::Element::Article::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 | 12 | with 'Strehler::Element::Role::Slugged'; | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 12 | my $module_file_path = __FILE__; | |||||||||
| 14 | 12 | my $root_path = abs_path($module_file_path); | |||||||||
| 15 | 12 | $root_path =~ s/Article\.pm//; | |||||||||
| 16 | 12 | my $form_path = $root_path . "../forms"; | |||||||||
| 17 | 12 | my $views_path = $root_path . "../views"; | |||||||||
| 18 | |||||||||||
| 19 | #Standard element implementation | ||||||||||
| 20 | |||||||||||
| 21 | sub metaclass_data | ||||||||||
| 22 | 672 | ▶ | { | ||||||||
|
Subroutine
metaclass_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | 672 | my $self = shift; | |||||||||
| 24 | 672 | my $param = shift; | |||||||||
| 25 | 672 | my %element_conf = ( item_type => 'article', | |||||||||
| 26 | ORMObj => 'Article', | ||||||||||
| 27 | category_accessor => 'articles', | ||||||||||
| 28 | multilang_children => 'contents' ); | ||||||||||
| 29 | 672 | return $element_conf{$param}; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | #Standard configuration overrides | ||||||||||
| 34 | |||||||||||
| 35 | sub label | ||||||||||
| 36 | 5 | ▶ | { | ||||||||
|
Subroutine
label: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 5 | my $self = shift; | |||||||||
| 38 | 5 | return $self->_property('label', 'Articles'); | |||||||||
| 39 | } | ||||||||||
| 40 | sub categorized | ||||||||||
| 41 | 42 | ▶ | { | ||||||||
|
Subroutine
categorized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 42 | 42 | my $self = shift; | |||||||||
| 43 | 42 | return $self->_property('categorized', 1); | |||||||||
| 44 | } | ||||||||||
| 45 | sub ordered | ||||||||||
| 46 | 6 | ▶ | { | ||||||||
|
Subroutine
ordered: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | 6 | my $self = shift; | |||||||||
| 48 | 6 | return $self->_property('ordered', 1); | |||||||||
| 49 | } | ||||||||||
| 50 | sub dated | ||||||||||
| 51 | 6 | ▶ | { | ||||||||
|
Subroutine
dated: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 52 | 6 | my $self = shift; | |||||||||
| 53 | 6 | return $self->_property('dated', 1); | |||||||||
| 54 | } | ||||||||||
| 55 | sub publishable | ||||||||||
| 56 | 51 | ▶ | { | ||||||||
|
Subroutine
publishable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 57 | 51 | my $self = shift; | |||||||||
| 58 | 51 | return $self->_property('publishable', 1); | |||||||||
| 59 | } | ||||||||||
| 60 | sub class | ||||||||||
| 61 | 4 | ▶ | { | ||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 62 | 4 | return __PACKAGE__; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub form | ||||||||||
| 66 | 18 | ▶ | { | ||||||||
|
Subroutine
form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 67 | 18 | return $form_path . '/admin/article.yml'; | |||||||||
| 68 | } | ||||||||||
| 69 | sub multilang_form | ||||||||||
| 70 | 18 | ▶ | { | ||||||||
|
Subroutine
multilang_form: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 71 | 18 | return $form_path . '/admin/article_multilang.yml'; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | sub add_main_column_span | ||||||||||
| 75 | 4 | ▶ | { | ||||||||
|
Subroutine
add_main_column_span: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 76 | 4 | my $self = shift; | |||||||||
| 77 | 4 | return $self->_property('add_main_column_span', 9); | |||||||||
| 78 | } | ||||||||||
| 79 | sub custom_snippet_add_position | ||||||||||
| 80 | 4 | ▶ | { | ||||||||
|
Subroutine
custom_snippet_add_position: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 81 | 4 | my $self = shift; | |||||||||
| 82 | 4 | return $self->_property('custom_snippet_position', 'right'); | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | #Main title redefined to fetch title from multilang attributes | ||||||||||
| 88 | |||||||||||
| 89 | sub main_title | ||||||||||
| 90 | 31 | ▶ | { | ||||||||
|
Subroutine
main_title: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||
| 91 | 31 | my $self = shift; | |||||||||
| 92 | 31 | my @contents = $self->row->contents->search({ language => config->{Strehler}->{default_language} }); | |||||||||
| 93 | 31 | ▶ | if($contents[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | { | ||||||||||
| 95 | 31 | return $contents[0]->title; | |||||||||
| 96 | } | ||||||||||
| 97 | else | ||||||||||
| 98 | { | ||||||||||
| 99 | #Should not be possible | ||||||||||
| 100 | 0 | return "*** no title ***"; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | sub fields_list | ||||||||||
| 106 | 3 | ▶ | { | ||||||||
|
Subroutine
fields_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 107 | 3 | my $self = shift; | |||||||||
| 108 | 3 | my @fields = ( { 'id' => 'id', | |||||||||
| 109 | 'label' => 'ID', | ||||||||||
| 110 | 'ordinable' => 1 }, | ||||||||||
| 111 | { 'id' => 'contents.title', | ||||||||||
| 112 | 'label' => 'Title', | ||||||||||
| 113 | 'ordinable' => 1 }, | ||||||||||
| 114 | { 'id' => 'category', | ||||||||||
| 115 | 'label' => 'Category', | ||||||||||
| 116 | 'ordinable' => 0 }, | ||||||||||
| 117 | { 'id' => 'display_order', | ||||||||||
| 118 | 'label' => 'Order', | ||||||||||
| 119 | 'ordinable' => 1 }, | ||||||||||
| 120 | { 'id' => 'publish_date', | ||||||||||
| 121 | 'label' => 'Date', | ||||||||||
| 122 | 'ordinable' => 1 }, | ||||||||||
| 123 | { 'id' => 'published', | ||||||||||
| 124 | 'label' => 'Status', | ||||||||||
| 125 | 'ordinable' => 1 } | ||||||||||
| 126 | ); | ||||||||||
| 127 | 3 | return \@fields; | |||||||||
| 128 | } | ||||||||||
| 129 | sub search_box | ||||||||||
| 130 | 0 | ▶ | { | ||||||||
|
Subroutine
search_box: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 131 | 0 | my $self = shift; | |||||||||
| 132 | 0 | my $string = shift; | |||||||||
| 133 | 0 | my $parameters = shift; | |||||||||
| 134 | 0 | $parameters->{'search'} = { -or => [ 'contents.title' => { 'like', "%$string%" }, | |||||||||
| 135 | 'contents.text' => { 'like', "%$string%" } ] | ||||||||||
| 136 | }; | ||||||||||
| 137 | 0 | $parameters->{'join'} = 'contents'; | |||||||||
| 138 | 0 | return $self->get_list($parameters); | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | |||||||||||
| 142 | #Ad hoc accessors and hooks | ||||||||||
| 143 | sub image | ||||||||||
| 144 | 31 | ▶ | { | ||||||||
|
Subroutine
image: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||
| 145 | 31 | my $self = shift; | |||||||||
| 146 | 31 | my $image = Strehler::Element::Image->new($self->row->image); | |||||||||
| 147 | 31 | ▶ | if($image->exists()) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | { | ||||||||||
| 149 | 0 | return $image->get_attr('image'); | |||||||||
| 150 | } | ||||||||||
| 151 | else | ||||||||||
| 152 | { | ||||||||||
| 153 | 31 | return undef; | |||||||||
| 154 | } | ||||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | sub custom_add_snippet | ||||||||||
| 158 | 1 | ▶ | { | ||||||||
|
Subroutine
custom_add_snippet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 159 | 1 | return '<div class="thumbnail"><img id="image_preview" src="/strehler/images/no-image.png" /></div>'; | |||||||||
| 160 | } | ||||||||||
| 161 | sub entity_js | ||||||||||
| 162 | 4 | ▶ | { | ||||||||
|
Subroutine
entity_js: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 163 | 4 | my $self = shift; | |||||||||
| 164 | 4 | return $self->_property('entity_js', '/strehler/js/article.js'); | |||||||||
| 165 | } | ||||||||||
| 166 | sub install | ||||||||||
| 167 | 0 | ▶ | { | ||||||||
|
Subroutine
install: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 168 | 0 | return "Standard entity. No installation is needed."; | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | |||||||||||
| 172 | =encoding utf8 | ||||||||||
| 173 | |||||||||||
| 174 | =head1 NAME | ||||||||||
| 175 | |||||||||||
| 176 | Strehler::Element::Article - Strehler Entity for articles | ||||||||||
| 177 | |||||||||||
| 178 | =head1 DESCRIPTION | ||||||||||
| 179 | |||||||||||
| 180 | Base Strehler content, it's used to create general articles, multilanguage. | ||||||||||
| 181 | |||||||||||
| 182 | Its main title is the title in the language configured as default. | ||||||||||
| 183 | |||||||||||
| 184 | =head1 FEATURES | ||||||||||
| 185 | |||||||||||
| 186 | It implements L<Strehler::Element::Role::Slugged> so you can use slugs to refer to articles | ||||||||||
| 187 | |||||||||||
| 188 | |||||||||||
| 189 | =cut | ||||||||||
| 190 | |||||||||||
| 191 | 12 | 1; | |||||||||
| 192 | |||||||||||
| 193 | |||||||||||
| 194 | |||||||||||
| 195 | |||||||||||
| 196 | |||||||||||
| 197 | |||||||||||
| 198 | |||||||||||