| 1 | package Nitesi::Navigation; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use Sub::Quote; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Nitesi::Navigation - Navigation class for Nitesi Shop Machine | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | Generic navigation class for L<Nitesi>. | ||
| 16 | |||
| 17 | =head2 NAVIGATION | ||
| 18 | |||
| 19 | A navigation entity has the following attributes: | ||
| 20 | |||
| 21 | =over 4 | ||
| 22 | |||
| 23 | =item code | ||
| 24 | |||
| 25 | Unique identifier for the navigation entity. | ||
| 26 | |||
| 27 | =item uri | ||
| 28 | |||
| 29 | Navigation URI. | ||
| 30 | |||
| 31 | =item name | ||
| 32 | |||
| 33 | Navigation name. | ||
| 34 | |||
| 35 | =item description | ||
| 36 | |||
| 37 | Navigation description. | ||
| 38 | |||
| 39 | =item template | ||
| 40 | |||
| 41 | Template used for this navigation entity. | ||
| 42 | |||
| 43 | =item language | ||
| 44 | |||
| 45 | Language of this navigation entity. | ||
| 46 | |||
| 47 | =item alias | ||
| 48 | |||
| 49 | Original navigation entity for language specific entities. | ||
| 50 | |||
| 51 | =item priority | ||
| 52 | |||
| 53 | The priority is used for sort navigation | ||
| 54 | entities. | ||
| 55 | |||
| 56 | =item inactive | ||
| 57 | |||
| 58 | Inactive Navigations are excluded from search results and | ||
| 59 | category listings. | ||
| 60 | |||
| 61 | =item entered | ||
| 62 | |||
| 63 | Creation date and time for this navigation object. | ||
| 64 | |||
| 65 | =back | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | has code => ( | ||
| 70 | is => 'rw', | ||
| 71 | ); | ||
| 72 | |||
| 73 | has type => ( | ||
| 74 | is => 'rw', | ||
| 75 | lazy => 1, | ||
| 76 | default => quote_sub q{return 'category';}, | ||
| 77 | ); | ||
| 78 | |||
| 79 | has scope => ( | ||
| 80 | is => 'rw', | ||
| 81 | lazy => 1, | ||
| 82 | default => quote_sub q{return '';}, | ||
| 83 | ); | ||
| 84 | |||
| 85 | has name => ( | ||
| 86 | is => 'rw', | ||
| 87 | ); | ||
| 88 | |||
| 89 | has description => ( | ||
| 90 | is => 'rw', | ||
| 91 | ); | ||
| 92 | |||
| 93 | has template => ( | ||
| 94 | is => 'rw', | ||
| 95 | lazy => 1, | ||
| 96 | default => quote_sub q{return '';}, | ||
| 97 | ); | ||
| 98 | |||
| 99 | has language => ( | ||
| 100 | is => 'rw', | ||
| 101 | lazy => 1, | ||
| 102 | default => quote_sub q{return '';}, | ||
| 103 | ); | ||
| 104 | |||
| 105 | has alias => ( | ||
| 106 | is => 'rw', | ||
| 107 | lazy => 1, | ||
| 108 | default => quote_sub q{return 0;}, | ||
| 109 | ); | ||
| 110 | |||
| 111 | has parent => ( | ||
| 112 | is => 'rw', | ||
| 113 | lazy => 1, | ||
| 114 | default => quote_sub q{return 0;}, | ||
| 115 | ); | ||
| 116 | |||
| 117 | has priority => ( | ||
| 118 | is => 'rw', | ||
| 119 | lazy => 1, | ||
| 120 | default => quote_sub q{return 0;}, | ||
| 121 | ); | ||
| 122 | |||
| 123 | has inactive => ( | ||
| 124 | is => 'rw', | ||
| 125 | lazy => 1, | ||
| 126 | default => quote_sub q{return 0;}, | ||
| 127 | ); | ||
| 128 | |||
| 129 | has entered => ( | ||
| 130 | is => 'rw', | ||
| 131 | lazy => 1, | ||
| 132 | ); | ||
| 133 | |||
| 134 | has uri => ( | ||
| 135 | is => 'rw', | ||
| 136 | lazy => 1, | ||
| 137 | builder => '_build_uri', | ||
| 138 | ); | ||
| 139 | |||
| 140 | =head1 METHODS | ||
| 141 | |||
| 142 | =head2 api_attributes | ||
| 143 | |||
| 144 | API attributes for navigation class. | ||
| 145 | |||
| 146 | =cut | ||
| 147 | |||
| 148 | has api_attributes => ( | ||
| 149 | is => 'rw', | ||
| 150 | ); | ||
| 151 | |||
| 152 | =head2 api_info | ||
| 153 | |||
| 154 | API information for navigation class. | ||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub api_info { | ||
| 159 | my $self = shift; | ||
| 160 | |||
| 161 | return {base => __PACKAGE__, | ||
| 162 | table => 'navigation', | ||
| 163 | key => 'code', | ||
| 164 | attributes => $self->api_attributes, | ||
| 165 | assign => {'Nitesi::Product' => { | ||
| 166 | table => 'navigation_products', | ||
| 167 | key => [qw/sku navigation/]} | ||
| 168 | }, | ||
| 169 | }; | ||
| 170 | }; | ||
| 171 | |||
| 172 | sub _build_uri { | ||
| 173 | my $self = shift; | ||
| 174 | |||
| 175 | return $self->clean_uri; | ||
| 176 | } | ||
| 177 | |||
| 178 | =head2 clean_uri | ||
| 179 | |||
| 180 | Retrieve clean URI for this navigation object. | ||
| 181 | |||
| 182 | =cut | ||
| 183 | |||
| 184 | sub clean_uri { | ||
| 185 | my $self = shift; | ||
| 186 | my $name = $self->name; | ||
| 187 | |||
| 188 | $name =~ s/\s/-/g; | ||
| 189 | $name =~ s/[^\w-]//g; | ||
| 190 | $name =~ s/-+/-/g; | ||
| 191 | $name =~ s/-$//; | ||
| 192 | |||
| 193 | return $name; | ||
| 194 | } | ||
| 195 | |||
| 196 | =head2 move | ||
| 197 | |||
| 198 | Move category to a new parent. | ||
| 199 | |||
| 200 | =cut | ||
| 201 | |||
| 202 | sub move { | ||
| 203 | my ($self, $new_parent) = @_; | ||
| 204 | |||
| 205 | $self->parent($new_parent); | ||
| 206 | } | ||
| 207 | |||
| 208 | =head1 AUTHOR | ||
| 209 | |||
| 210 | Stefan Hornburg (Racke), <racke@linuxia.de> | ||
| 211 | |||
| 212 | =head1 LICENSE AND COPYRIGHT | ||
| 213 | |||
| 214 | Copyright 2012-2013 Stefan Hornburg (Racke) <racke@linuxia.de>. | ||
| 215 | |||
| 216 | This program is free software; you can redistribute it and/or modify it | ||
| 217 | under the terms of either: the GNU General Public License as published | ||
| 218 | by the Free Software Foundation; or the Artistic License. | ||
| 219 | |||
| 220 | See http://dev.perl.org/licenses/ for more information. | ||
| 221 | |||
| 222 | =cut | ||
| 223 | |||
| 224 | 1; |