summaryrefslogtreecommitdiff
path: root/lib/Bookmarks/M/DB/Links.pm
blob: 510352210b7591b9b960d5ce08bc582e53084cfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package Bookmarks::M::DB::Links; 
use strict;
use MIME::Base64;
use Bookmarks::M::DB::LinksTags;
use List::MoreUtils qw(uniq);
 
for my $col_name (qw(add_date last_access_date)) {
    __PACKAGE__->has_a( $col_name => 'DateTime',
                        inflate => sub { DateTime->from_epoch( epoch => $_[0] ) },
                        deflate => 'epoch',
                    );
}
 
sub set_icon {
    my ($self,$icon)=@_;
    $self->icon(encode_base64($icon||''));
}
sub get_icon {
    my ($self)=@_;
    return decode_base64($self->icon()||'');
}
 
sub search_complex {
    my ($class$query@tags)=@_;
 
    $query =~ s{^ +| +$}{}g;
    $query =~ s{ +}{%}g;
 
    my $iterator = $class->search_like(title => "%$query%", {order_by => 'access_count'});
 
    my @result=();
 
    while (my $link=$iterator->next()) {
        my @link_tags = map {$_->pk} $link->tags();
 
        # se @tags contiene roba non in @link_tags, i risultati sono diversi 
        # notare che @tags=() significa 'tutti' 
        if (scalar uniq(@link_tags,@tags) == scalar @link_tags) {
            push @result,$link;
        }
    }
 
    return @result;
}
 
__PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] );
 
=head1 NAME
 
Bookmarks::M::DB::Links - CDBI Model Component Table Class
 
=head1 SYNOPSIS
 
    Very simple to use
 
=head1 DESCRIPTION
 
Very nice component.
 
=head1 AUTHOR
 
Clever guy
 
=head1 LICENSE
 
This library is free software . You can redistribute it and/or modify it under
the same terms as perl itself.
 
=cut
 
1;