root/branches/release-26/lib/MT/ObjectScore.pm @ 1174

Revision 1174, 2.4 kB (checked in by bchoate, 23 months ago)

Updated copyright year for source.

  • Property svn:keywords set to Author Date Id Revision
Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::ObjectScore;
8
9use strict;
10use base qw( MT::Object );
11
12__PACKAGE__->install_properties({
13    column_defs => {
14        'id'           => 'integer not null auto_increment',
15        'namespace'    => 'string(255) not null',
16        'object_id'    => 'integer',
17        'author_id'    => 'integer',
18        'score'        => 'float',
19        'object_ds'    => 'string(50) not null',
20        'ip'           => 'string(16)',
21    },
22    indexes => {
23        namespace => 1,
24        object_id => 1,
25        author_id => 1,
26        ip        => 1,
27    },
28    defaults => {
29        object_id => 0,
30        author_id => 0,
31    },
32    audit => 1,
33    datasource  => 'objectscore',
34    primary_key => 'id',
35});
36
37sub class_label {
38    MT->translate("Object Score");
39}
40
41sub class_label_plural {
42    MT->translate("Object Scores");
43}
44
45sub scored_by {
46    my $class = shift;
47    my ($namespace, $user) = @_;
48    MT::ObjectScore->load_iter({
49        author_id => $user->id,
50        defined($namespace) ? (namespace => $namespace) : (),
51    });
52}
53
541;
55__END__
56
57=head1 NAME
58
59MT::Scorable - An interface for any MT::Object that wishes to be rated.
60
61=head1 SYNOPSIS
62
63    use MT::Entry;
64    my $entry = MT::Entry->load($id);
65    $entry->set_score('key', $app->user, 100, $overwrite);
66
67=head1 METHODS
68
69=head2 get_score($namespace, $user)
70
71Return the score of the object, scored by the user specified.
72This is not for total score of an object.  This is to get a score
73specified by a user to an object.
74
75=head2 set_score($namespace, $user, $score, $overwrite)
76
77Set specified score to the object by the user.  If $overwrite argument
78is false and the user has already scored the object before, error results.
79
80=head2 score_for($namespace)
81
82Return the total score of the object.
83
84=head2 vote_for($namespace)
85
86Return how many users scored to the object.
87
88=head2 score_high($namespace)
89
90Return the highest score to the object.
91
92=head2 score_low($namespace)
93
94Return the lowest score to the object.
95
96=head2 score_avg($namespace)
97
98Return the average score of the object.
99
100=head2 rank_for($namespace, $max)
101
102Return the rank of the object based on its score among other objects
103of the same type.  The smaller the number is, the higher the object's rank is.
104
105=head1 AUTHOR & COPYRIGHT
106
107Please see L<MT/AUTHOR & COPYRIGHT>.
108
109=cut
110
Note: See TracBrowser for help on using the browser.