line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::UserMessage; |
2
|
1
|
|
|
1
|
|
1116
|
use Kwiki::Plugin qw(-Base -XXX); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
const class_id => 'user_message'; |
7
|
|
|
|
|
|
|
const class_title => 'Kwiki User Message'; |
8
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::UserMessage::CGI'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
const css_file => 'user_message.css'; |
11
|
|
|
|
|
|
|
const javascript_file => 'user_message.js'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
field cdbi => -init => '$self->hub->cdbi'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
field 'display_msg'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub register { |
18
|
|
|
|
|
|
|
my $registry = shift; |
19
|
|
|
|
|
|
|
$registry->add(action => 'user_message'); |
20
|
|
|
|
|
|
|
$registry->add(toolbar => 'user_message', |
21
|
|
|
|
|
|
|
template => 'user_message_toolbar.html'); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub dbinit { |
25
|
|
|
|
|
|
|
my $dbpath = io->catfile($self->plugin_directory,"data.sqlt"); |
26
|
|
|
|
|
|
|
my $db = $self->hub->cdbi; |
27
|
|
|
|
|
|
|
$db->base('Kwiki::UserMessage::CDBI'); |
28
|
|
|
|
|
|
|
$db->connection("dbi:SQLite:".$dbpath->name); |
29
|
|
|
|
|
|
|
$db->dbinit unless $dbpath->exists; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub user_message { |
33
|
|
|
|
|
|
|
$self->dbinit; |
34
|
|
|
|
|
|
|
my $mode = $self->cgi->run_mode || 'list'; |
35
|
|
|
|
|
|
|
$self->$mode if $self->can($mode); |
36
|
|
|
|
|
|
|
$self->render_screen; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub list {} |
40
|
|
|
|
|
|
|
sub compose {} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub delete { |
43
|
|
|
|
|
|
|
my $id = shift || $self->cgi->id; |
44
|
|
|
|
|
|
|
$self->delete_message($id) if $id; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $obj = $self->cdbi->retrieve($id); |
47
|
|
|
|
|
|
|
$obj->delete if $obj; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub post { |
51
|
|
|
|
|
|
|
my $caller_sub = (caller(1))[3]; |
52
|
|
|
|
|
|
|
if($caller_sub eq 'Kwiki::UserMessage::user_message') { |
53
|
|
|
|
|
|
|
if($self->post($self->users->current->name, |
54
|
|
|
|
|
|
|
$self->cgi->to, |
55
|
|
|
|
|
|
|
$self->cgi->subject, |
56
|
|
|
|
|
|
|
$self->cgi->body)) { |
57
|
|
|
|
|
|
|
$self->display_msg("Message Delivered"); |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
$self->display_msg("Delivery Error"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} else { |
62
|
|
|
|
|
|
|
my ($sender,$receiver,$subject,$body) = @_; |
63
|
|
|
|
|
|
|
my $vars = { |
64
|
|
|
|
|
|
|
id => $self->cdbi->maximum_value_of("id")||0 + 1, |
65
|
|
|
|
|
|
|
sender => $sender, |
66
|
|
|
|
|
|
|
receiver => $receiver, |
67
|
|
|
|
|
|
|
subject => $subject, |
68
|
|
|
|
|
|
|
body => $body, |
69
|
|
|
|
|
|
|
ts => scalar(localtime) |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
$self->cdbi->create($vars); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub message_list { |
76
|
|
|
|
|
|
|
my $user = shift || $self->users->current->name; |
77
|
|
|
|
|
|
|
my $it = $self->cdbi->search( receiver => $user ); |
78
|
|
|
|
|
|
|
my @obj = $self->retrieve_obj_list($it); |
79
|
|
|
|
|
|
|
return \@obj; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_message { |
83
|
|
|
|
|
|
|
my $id = shift; |
84
|
|
|
|
|
|
|
$self->retrieve_obj($self->cdbi->retrieve($id), $self->cdbi->columns()); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub retrieve_obj_list { |
88
|
|
|
|
|
|
|
my $it = shift || return; |
89
|
|
|
|
|
|
|
my $entity = shift || $self->cdbi; |
90
|
|
|
|
|
|
|
my @objs; |
91
|
|
|
|
|
|
|
my @columns = $entity->columns(); |
92
|
|
|
|
|
|
|
while(my $obj = $it->next) { |
93
|
|
|
|
|
|
|
push @objs, $self->retrieve_obj($obj,@columns); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
return @objs; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub retrieve_obj { |
99
|
|
|
|
|
|
|
my ($obj,@columns) = @_; |
100
|
|
|
|
|
|
|
return unless ref($obj); |
101
|
|
|
|
|
|
|
my $var; |
102
|
|
|
|
|
|
|
for(@columns) { |
103
|
|
|
|
|
|
|
$var->{$_} = $self->utf8_decode($obj->$_); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
$var->{time} = $var->{ts}; |
106
|
|
|
|
|
|
|
return $var; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
package Kwiki::UserMessage::CGI; |
110
|
|
|
|
|
|
|
use base 'Kwiki::CGI'; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
cgi 'run_mode'; |
113
|
|
|
|
|
|
|
cgi 'id'; |
114
|
|
|
|
|
|
|
cgi 'to'; |
115
|
|
|
|
|
|
|
cgi 'body'; |
116
|
|
|
|
|
|
|
cgi 'subject'; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
package Kwiki::UserMessage; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__DATA__ |