Permalink
Browse files

(core) implemented first part of the rating-pool code (per membergrou…

…p pool of points a member can spend for rating posts).
  • Loading branch information...
silvercircle committed Feb 24, 2013
1 parent e956825 commit 79dad0a832024a19e3cc01c7cc11f5144e40fe2b
View
@@ -105,6 +105,8 @@ function GetRatingWidget()
{
global $modSettings, $user_info, $context, $txt;
$pool_avail = Ratings::getPool();
if($user_info['is_guest'])
AjaxErrorMsg($txt['no_like_for_guests']);
@@ -135,16 +137,22 @@ function GetRatingWidget()
continue;
if(Ratings::isAllowed($key, $id_board)) {
$context['result_count']++;
$cost = isset($rating['cost']) ? $rating['cost'] : 0;
$context['ratings'][] = array(
'rtype' => (int)$key,
'label' => $rating['text'],
'unique' => $rating['unique']
'unique' => $rating['unique'],
'cost' => $cost,
'points' => isset($rating['points']) ? $rating['points'] : 0,
'avail' => $user_info['is_admin'] || $cost <= $pool_avail,
);
}
}
}
$context['pool_avail'] = $pool_avail;
$context['content_id'] = $content_id;
$context['json_data'] = htmlspecialchars(json_encode(array('id' => $content_id, 'error_text' => $txt['ratingwidget_error'])));
$context['widget_help_href'] = URL::parse('?action=helpadmin;help=ratingwidget_help');
}
/**
@@ -371,11 +371,11 @@ function AddMembergroup()
'{db_prefix}membergroups',
array(
'id_group' => 'int', 'description' => 'string', 'group_name' => 'string-80', 'min_posts' => 'int',
'stars' => 'string', 'online_color' => 'string', 'group_type' => 'int',
'stars' => 'string', 'online_color' => 'string', 'group_type' => 'int', 'rating_pool' => 'int'
),
array(
$id_group, '', $_POST['group_name'], ($postCountBasedGroup ? (int) $_POST['min_posts'] : '-1'),
'1#star.gif', '', $_POST['group_type'],
'1#star.gif', '', $_POST['group_type'], $_POST['rating_pool']
),
array('id_group')
);
@@ -682,6 +682,7 @@ function EditMembergroup()
$_POST['group_type'] = !isset($_POST['group_type']) || $_POST['group_type'] < 0 || $_POST['group_type'] > 3 || ($_POST['group_type'] == 1 && !allowedTo('admin_forum')) ? 0 : (int) $_POST['group_type'];
$_POST['group_hidden'] = empty($_POST['group_hidden']) || $_POST['min_posts'] != -1 || $_REQUEST['group'] == 3 ? 0 : (int) $_POST['group_hidden'];
$_POST['group_inherit'] = $_REQUEST['group'] > 1 && $_REQUEST['group'] != 3 && (empty($inherit_type) || $inherit_type != 1) ? (int) $_POST['group_inherit'] : -2;
$_POST['rating_pool'] = abs($_POST['rating_pool']);
// !!! Don't set online_color for the Moderators group?
@@ -691,7 +692,7 @@ function EditMembergroup()
SET group_name = {string:group_name}, online_color = {string:online_color},
max_messages = {int:max_messages}, min_posts = {int:min_posts}, stars = {string:stars},
description = {string:group_desc}, group_type = {int:group_type}, hidden = {int:group_hidden},
id_parent = {int:group_inherit}
id_parent = {int:group_inherit}, rating_pool = {int:rating_pool}
WHERE id_group = {int:current_group}',
array(
'max_messages' => $_POST['max_messages'],
@@ -704,6 +705,7 @@ function EditMembergroup()
'online_color' => $_POST['online_color'],
'stars' => $_POST['stars'],
'group_desc' => $_POST['group_desc'],
'rating_pool' => $_POST['rating_pool']
)
);
@@ -939,7 +941,7 @@ function EditMembergroup()
// Fetch the current group information.
$request = smf_db_query( '
SELECT group_name, description, min_posts, online_color, max_messages, stars, group_type, hidden, id_parent
SELECT group_name, description, min_posts, online_color, max_messages, stars, group_type, hidden, id_parent, rating_pool
FROM {db_prefix}membergroups
WHERE id_group = {int:current_group}
LIMIT 1',
@@ -971,6 +973,7 @@ function EditMembergroup()
'allow_post_group' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
'allow_delete' => $_REQUEST['group'] == 2 || $_REQUEST['group'] > 4,
'allow_protected' => allowedTo('admin_forum'),
'rating_pool' => $row['rating_pool']
);
// Get any moderators for this group
@@ -489,6 +489,7 @@ function ModifyRatingSettings()
'label' => $rating['label'],
'localized' => isset($rating['localized']) ? $rating['localized'] : '',
'points' => isset($rating['points']) ? $rating['points'] : 0,
'cost' => isset($rating['cost']) ? $rating['cost'] : 0,
'groups' => isset($rating['groups']) && !empty($rating['groups']) ? implode(',', $rating['groups']) : '',
'boards' => isset($rating['boards']) && !empty($rating['boards']) ? implode(',', $rating['boards']) : '',
'boards_denied' => isset($rating['boards_denied']) && !empty($rating['boards_denied']) ? implode(',', $rating['boards_denied']) : '',
@@ -503,6 +504,7 @@ function ModifyRatingSettings()
'format' => '',
'label' => '',
'points' => '',
'cost' => '',
'groups' => '',
'boards' => '',
'boards_denied' => '',
@@ -530,6 +532,7 @@ function ModifyRatingSettings()
'boards' => isset($_REQUEST['rating_boards_' . $i]) && !empty($_REQUEST['rating_boards_' . $i]) ? explode(',', normalizeCommaDelimitedList($_REQUEST['rating_boards_' . $i])) : array(),
'boards_denied' => isset($_REQUEST['rating_boards_denied_' . $i]) && !empty($_REQUEST['rating_boards_denied_' . $i]) ? explode(',', normalizeCommaDelimitedList($_REQUEST['rating_boards_denied_' . $i])) : array(),
'points' => isset($_REQUEST['rating_points_' . $i]) && !empty($_REQUEST['rating_points_' . $i]) ? $_REQUEST['rating_points_' . $i] : 0,
'cost' => isset($_POST['rating_cost_' . $i]) && !empty($_POST['rating_cost_' . $i]) ? $_POST['rating_cost_' . $i] : 0,
'unique' => isset($_REQUEST['rating_unique_' . $i]) && $_REQUEST['rating_unique_' . $i] ? true : false,
);
}
@@ -10,17 +10,23 @@
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.0pre
*
* class Ratings contains all the core functionality for the content
* rating system.
*/
if (!defined('EOSA'))
die('No access');
Ratings::init();
class Ratings {
protected static $perm_can_see, $perm_can_give;
protected static $rate_bar = '';
protected static $is_valid;
protected static $show_repair_link;
protected static $perm_can_see, $perm_can_give;
protected static $rate_bar = '';
protected static $is_valid;
protected static $show_repair_link;
const REFRESH = 1;
const UPDATE = 2;
public static function init()
{
@@ -377,4 +383,67 @@ public static function removeByPosts($mid, $ctype = 1)
DELETE FROM {db_prefix}like_cache WHERE id_msg IN ({array_int:id_msg}) AND ctype = {int:ctype}',
array('id_msg' => $_mid, 'ctype' => $ctype));
}
/**
* @param $do_db boolean. if true, update the database.
*
* initialize or refresh a member's rating point pool
*/
public static function refreshPool($do_db = true)
{
global $user_info, $context;
$pool_avail = 0;
$request = smf_db_query('SELECT MAX(rating_pool) AS pool FROM {db_prefix}membergroups AS g WHERE g.id_group IN({array_int:groups})',
array('groups' => $user_info['groups']));
if(smf_db_affected_rows() > 0) {
$row = mysql_fetch_assoc($request);
$pool_avail = $row['pool'];
}
$user_info['meta']['rating_pool']['points'] = $pool_avail;
$user_info['meta']['rating_pool']['refresh'] = $context['time_now'];
if($do_db)
updateMemberData($user_info['id'], array('meta' => @serialize($user_info['meta'])));
}
/**
* @return int the number of available rating points in the member's pool
*
* get the member's rating pool points. If the pool has not been initialized yet, do it.
*/
public static function getPool()
{
global $user_info, $context;
if(!isset($user_info['meta']['rating_pool']['refresh']) || $context['time_now'] - $user_info['meta']['rating_pool']['refresh'] > 86400)
self::refreshPool();
return $user_info['meta']['rating_pool']['points'];
}
/**
* @param $points int points to subtract from the pool
* @param int $mode mode. defaults to update, can also be a bitwise OR of UPDATE | REFRESH
*
* update the member's pool of available rating points.
*/
public static function updatePool($points, $mode = Ratings::UPDATE)
{
global $user_info;
if($mode & Ratings::REFRESH)
self::refreshPool($mode & Ratings::UPDATE ? false : true); // avoid db update if we also do a update afterwards
if($mode & Ratings::UPDATE) {
if($points <= $user_info['meta']['rating_pool']['points'])
$user_info['meta']['rating_pool']['points'] -= $points;
else
$user_info['meta']['rating_pool']['points'] = 0;
updateMemberData($user_info['id'], array('meta' => @serialize($user_info['meta'])));
}
}
}
View
@@ -704,8 +704,8 @@ function constructPageIndex($base_url, &$start, $max_value, $num_per_page, $flex
$data_url = $base_url . ';start=[[PAGE]]';
$prefix = sprintf('<span data-perpage="'.$num_per_page.'" data-urltemplate="'.$data_url.'" class="prefix'.(isset($need_direct_input) ? ' drop" title="Click to enter page number"' : '"').'>'.$txt['page_x_of_n'].'</span>', $start / $num_per_page + 1, ($max_value - 1) / $num_per_page + 1);
$first = $start / $num_per_page > 1 ? sprintf($base_link, 0, $txt['page_first']) : '';
$prev = $start > 0 ? sprintf($base_link, $start - $num_per_page, '&lt;') : '';
$next = $start < $max_value - $num_per_page ? sprintf($base_link, $start + $num_per_page, '&gt;') : '';
$prev = $start > 0 ? sprintf($base_link, $start - $num_per_page, '&larr;') : '';
$next = $start < $max_value - $num_per_page ? sprintf($base_link, $start + $num_per_page, '&rarr;') : '';
$last = $start <= $max_value - 2 * $num_per_page ? sprintf($base_link, $tmpMaxPages, $txt['page_last']) : '';
if(isset($need_direct_input))
$context['need_pager_script_fragment'] = true;
@@ -39,6 +39,12 @@ function template_new_group()
</dt>
<dd>
<input type="text" name="group_name" id="group_name_input" size="30" class="input_text" />
</dd>
<dt>
<label for="group_rating_pool_input"><strong>', $txt['membergroups_group_rating_pool'], ':</strong></label>
</dt>
<dd>
<input type="text" name="rating_pool" id="group_rating_pool_input" size="10" class="input_text" value="0" />
</dd>';
if ($context['undefined_group'])
{
@@ -295,7 +301,14 @@ function template_edit_group()
</dt>
<dd>
<input type="text" name="max_messages" id="max_messages_input" value="', $context['group']['id'] == 1 ? 0 : $context['group']['max_messages'], '" size="6"', $context['group']['id'] == 1 ? ' disabled="disabled"' : '', ' class="input_text" />
</dd>
<dt>
<label for="group_rating_pool_input"><strong>', $txt['membergroups_group_rating_pool'], ':</strong></label>
</dt>
<dd>
<input type="text" name="rating_pool" id="group_rating_pool_input" size="10" class="input_text" value="',$context['group']['rating_pool'],'" />
</dd>';
if (!empty($context['boards']))
{
echo '
@@ -9,7 +9,7 @@ function template_manage_ratings()
</div>
<div class="blue_container mediumpadding cleantop">',
$txt['ratings_help_intro'], '
<div id="rhelp" style="display:none;">',
<div id="rhelp" class="smalltext" style="display:none;">',
$txt['ratings_help'],'
</div>
<form method="post" accept-charset="UTF-8" action="',$context['post_url'],'">
@@ -76,8 +76,9 @@ function template_manage_ratings()
<span style="color:green;">&bull;</span><input style=margin-bottom:4px;" type="text" size="15" name="rating_boards_', $id, '" value="', $class['boards'], '" /><br>
<span style="color:red;">&bull;</span><input type="text" size="15" name="rating_boards_denied_', $id, '" value="', $class['boards_denied'], '" />
</td>
<td>
<input type="text" size="5" name="rating_points_', $id, '" value="', $class['points'], '" />
<td class="nowrap">
<input type="text" size="5" name="rating_points_', $id, '" value="', $class['points'], '" /><br>
<input type="text" size="5" name="rating_cost_', $id, '" value="', $class['cost'], '" />
</td>
<td>
<input type="checkbox" ',($class['unique'] ? 'checked="checked"' : ''),' name="rating_unique_', $id, '" value="1" />
@@ -775,10 +775,10 @@ li.boardrow {
background: #eaecf2;
}
.topicrow.sticky {
background: #e0e0ea;
/*background: #e0e0ea;*/
}
.topicrow.locked {
background: #eae0e0;
/*background: #eae0e0;*/
}
ol.commonlist.notifications {
box-shadow: none !important;
@@ -2343,9 +2343,9 @@ div.spoiler.head {
a.navPages, .pagelinks span.current, .pagelinks span.prefix {
font-size: 11px;
border: 1px solid #ddd;
border: 1px solid #9ebfdd;
cursor: pointer;
background:#f2f2f2;
background: #e5f2f0;
color: #777;
font-family:Tahoma,sans-serif;
font-style: normal !important;
@@ -2359,7 +2359,7 @@ a.navPages:hover {
background-color:#fff;
}
.pagelinks span.prefix.drop {
background: #f2f2f2 url(../images/theme/sprite.png) 0 4px no-repeat;
background: #e5f2f0 url(../images/theme/sprite.png) 0 4px no-repeat;
}
.pagelinks span.current {
background: #8f8f8f url(../images/clipsrc.png) 0 -63px repeat-x;
@@ -2456,6 +2456,21 @@ span.ratings .number {
color:white;
cursor:pointer;
}
div.ratings.cost {
color:blue;
width:20px;
text-align: right;
}
div.ratings.points.positive {
color:green;
width:30px;
text-align: right;
}
div.ratings.points.negative {
color:red;
width:30px;
text-align: right;
}
div#ajaxbusy {
border: 2px solid white;
border-top: 0;
@@ -723,7 +723,7 @@ function showSimpleSEFHelp()
$txt['rating_class_localized'] = 'Localized';
$txt['rating_class_desc'] = 'Description';
$txt['rating_class_format'] = 'Formatting';
$txt['rating_class_points'] = 'Points';
$txt['rating_class_points'] = 'Points/Cost';
$txt['rating_class_groups_allowed'] = 'Member groups';
$txt['rating_class_boards_allowed'] = 'Boards';
$txt['rating_class_unique'] = 'U';
@@ -739,7 +739,7 @@ function showSimpleSEFHelp()
<li>Format can contain basic HTML tags like SPAN, DIV and style or class attributes. Format <b>MUST</b> contain a %s placeholder where the label should go.</li>
<li>Groups is a comma-delimited list of member group ids which are allowed (top field) and/or groups that should be disallowed (bottom field) to use this rating. Leave it empty to allow all members to use this rating.</li>
<li>Boards is a comma-delimited list of board ids where the rating should be available or blocked. Leave it empty to allow this rating in all boards. <b>Note: A denied board ID will override the allowed ones</b>.</li>
<li>Points is a positive or negative number that specifies the number of reputation points a member will receive for this rating. When left empty, the rating is considered a neutral one and no points will be granted. <b>NOTE: THIS IS CURRENTLY UNIMPLEMENTED.</b></li>
<li>The points/cost colum holds two values. The first (upper) one is a positive or negative number that specifies the number of reputation points a member will receive for this rating. When left empty, the rating is considered a neutral one and no points will be granted.<br><br>The second (lower) value is a positive integer that specifies how many points are subtracted from the rating member\'s rating pool when using this rating. A member cannot spend more than points on ratings than the pool allows for a given period of time. <br><strong>NOTE: THIS IS CURRENTLY UNIMPLEMENTED.</strong></li>
</ul>
';
$txt['sphinx_test_passed'] = 'All tests successfully passed. It appears your sphinx search daemon is running and can accept connections and search queries.';
@@ -621,3 +621,6 @@
Typically, you may want to grant link permissions to all your members except new and possibly banned ones. Also note that there are 2 permissions to control this. One general that controls how links from a member\'s signature are handled and one board permission that works like any other per board permission.';
$helptxt['use_rating_widget'] = 'If enabled, direct links to rate a post will be replaced by a single "Rate It" link which will open a widget';
$helptxt['groupColorsFromTheme'] = 'When enabled, the inline colors you have defined for each member group will not be used. Instead, you can define them in your theme\'s style sheet';
$helptxt['ratingwidget_help'] = 'To rate a post select the rating and click the <strong>Submit</strong> button.<br><br>
Stricken ratings are unavailable, because you either do not have permission to use them or you do not have enough rating points left. You can see the cost (in rating points) for each rating in the rightmost column.<br><br>
The second column from the left shows the influence the rating will have on the reputation of the post\'s author. Green numbers have a positive influence while red numbers will give negative reputation.';
@@ -12,6 +12,7 @@
$txt['membergroups_post'] = 'Post count based groups';
$txt['membergroups_group_name'] = 'Membergroup name';
$txt['membergroups_group_rating_pool'] = 'Rating pool points per day';
$txt['membergroups_new_board'] = 'Visible Boards';
$txt['membergroups_new_board_desc'] = 'Boards the membergroup can see';
$txt['membergroups_new_board_post_groups'] = '<em>Note: normally, post groups don\'t need access because the group the member is in will give them access.</em>';
@@ -219,8 +219,8 @@ function reqWin(desktopURL, alternateWidth, alternateHeight, noScrollbars)
{
var el = $('<div id="helpoverlay" class="jqmWindow jsconfirm" style="width:500px;"><div class="jqmWindow_container">\
<div class="jsconfirm glass title">Help</div> <div class="jsconfirm content" id="help_content"></div>\
<div class="smallpadding centertext">\
<div class="jsconfirm glass title">Help</div> <div class="jsconfirm" id="help_content"></div>\
<div class="smallpadding centertext ">\
<span class="button default centered" id="helpclose">Close</span>\
</div></div>\
</div>');
Oops, something went wrong.

0 comments on commit 79dad0a

Please sign in to comment.