root/branches/release-41/lib/MT/ObjectScore.pm @ 2677

Revision 2677, 2.9 kB (checked in by bchoate, 17 months ago)

Updates to indexes for mt_objectscore.

  • 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        # usually used to remove all scores for a given object
24        ds_obj => {
25            columns => ['object_ds', 'object_id'],
26        },
27        # common requests for scoring
28        ns_user_ds_obj => {
29            columns => ['namespace', 'author_id', 'object_ds', 'object_id'],
30        },
31        # common requests for anonymous scoring (ip-based)
32        ns_ip_ds_obj => {
33            columns => ['namespace', 'ip', 'object_ds', 'object_id'],
34        },
35        # for scored_by method
36        user_ns => {
37            columns => ['author_id', 'namespace'],
38        },
39    },
40    defaults => {
41        object_id => 0,
42        author_id => 0,
43    },
44    audit => 1,
45    datasource  => 'objectscore',
46    primary_key => 'id',
47});
48
49sub class_label {
50    MT->translate("Object Score");
51}
52
53sub class_label_plural {
54    MT->translate("Object Scores");
55}
56
57sub scored_by {
58    my $class = shift;
59    my ($namespace, $user) = @_;
60    MT::ObjectScore->load_iter({
61        author_id => $user->id,
62        defined($namespace) ? (namespace => $namespace) : (),
63    });
64}
65
661;
67__END__
68
69=head1 NAME
70
71MT::Scorable - An interface for any MT::Object that wishes to be rated.
72
73=head1 SYNOPSIS
74
75    use MT::Entry;
76    my $entry = MT::Entry->load($id);
77    $entry->set_score('key', $app->user, 100, $overwrite);
78
79=head1 METHODS
80
81=head2 get_score($namespace, $user)
82
83Return the score of the object, scored by the user specified.
84This is not for total score of an object.  This is to get a score
85specified by a user to an object.
86
87=head2 set_score($namespace, $user, $score, $overwrite)
88
89Set specified score to the object by the user.  If $overwrite argument
90is false and the user has already scored the object before, error results.
91
92=head2 score_for($namespace)
93
94Return the total score of the object.
95
96=head2 vote_for($namespace)
97
98Return how many users scored to the object.
99
100=head2 score_high($namespace)
101
102Return the highest score to the object.
103
104=head2 score_low($namespace)
105
106Return the lowest score to the object.
107
108=head2 score_avg($namespace)
109
110Return the average score of the object.
111
112=head2 rank_for($namespace, $max)
113
114Return the rank of the object based on its score among other objects
115of the same type.  The smaller the number is, the higher the object's rank is.
116
117=head1 AUTHOR & COPYRIGHT
118
119Please see L<MT/AUTHOR & COPYRIGHT>.
120
121=cut
122
Note: See TracBrowser for help on using the browser.