MT::Scorable
Movable Type comes with a scoring framework built in. What does that mean? It means that a developer can very easily bootstrap any object, class or package they define to expose methods to allow for plugins to score, both positively and negatively that object.
get_score($plugin_key, $user)
- Return the score of the object, scored by the user specified. This is not for total score of an object. This is to get a score specified by a user to an object.set_score($plugin_key, $user, $score, $overwrite)
- Set specified score to the object by the user. If $overwrite argument is false and the user has already scored the object before, error results.score_for($plugin_key)
- Return the total score of the object.vote_for($plugin_key)
- Return how many users scored to the object.score_high($plugin_key)
- Return the highest score to the object.score_low($plugin_key)
- Return the lowest score to the object.score_avg($plugin_key)
- Return the average score of the object.rank_for($plugin_key, $max)
- Return the rank of the object based on its score among other objects of the same type. The smaller the number is, the higher the object’s rank is.
Inheriting from the MT::Scorable Interface
To make an object scorable, a developer need only state that their package inherits from the MT::Scorable
interface.
package My::Object::Model;
use base qw( MT::Object <strong>MT::Scorable</strong> );
__PACKAGE__->install_properties({
# ...
});
1;
Using the MT::Scorable Interface
Then you get the methods in the MT::Scorable interface on your model objects:
sub score_myobject {
my ($m_id) = @_;
my $m = My::Object::Model->load($m_id);
my $is_awesome = $m->score_avg('percent-rating') > 80 ? 1 : 0;
if ($is_awesome) {
# do something wicked
}
}