HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS. ocPortal 9 is superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Points for forum posts by Group

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#111811 (In Topic #22475)
TQ
Avatar

Honoured member

Hi Folks,

I would like to give points for forum posts made by members of a specific group (whilst all other group members receive no points for posts), is this possible?

The reasoning behind this is that I do not give points on a per-post basis to stop people posting useless rubbish in order to accumulate points to use for downloads but there is a specific group (Technical Advisor) that I always want to give points to, to save me having to read every post and manually award points.

If this can't be done by group, is there a way to do it on a per member basis?

TQ
Back to the top
 
Posted
Rating:
#111813
Avatar

Hi,

You'd need to do it with a code override of sources/points.php.

Try changing this function:

PHP code

/**
 * Get the total points in the specified member's account; some of these will probably have been spent already
 *
 * @param  MEMBER            The member
 * @return integer        The number of points the member has
 */
function total_points($member)
{
    if (!
has_specific_permission($member,'use_points')) return 0;

    global 
$TOTAL_POINTS_CACHE;
    if (
array_key_exists($member,$TOTAL_POINTS_CACHE)) return $TOTAL_POINTS_CACHE[$member];

    
$points_gained_posting=$GLOBALS['FORUM_DRIVER']->get_post_count($member);
    
$_points_gained=point_info($member);
    
$points_gained_given=array_key_exists('points_gained_given',$_points_gained)?$_points_gained['points_gained_given']:0;
    
$points_gained_rating=array_key_exists('points_gained_rating',$_points_gained)?$_points_gained['points_gained_rating']:0;
    
$points_gained_voting=array_key_exists('points_gained_voting',$_points_gained)?$_points_gained['points_gained_voting']:0;
    
$points_gained_cedi=array_key_exists('points_gained_seedy',$_points_gained)?$_points_gained['points_gained_seedy']:0;
    
$points_gained_chat=array_key_exists('points_gained_chat',$_points_gained)?$_points_gained['points_gained_chat']:0;
    
$points_posting=intval(get_option('points_posting'));
    
$points_rating=intval(get_option('points_rating'));
    
$points_voting=intval(get_option('points_voting'));
    
$points_joining=intval(get_option('points_joining'));
    
$points_per_day=intval(get_option('points_per_day',true));
    
$points_chat=intval(get_option('points_chat',true));
    
$points_cedi=intval(get_option('points_cedi',true));
    
$points_gained_auto=$points_per_day*intval(floor(floatval(time()-$GLOBALS['FORUM_DRIVER']->get_member_join_timestamp($member))/floatval(60*60*24)));
    
$points=$points_joining+$points_gained_chat*$points_chat+$points_gained_cedi*$points_cedi+$points_gained_posting*$points_posting+$points_gained_given+$points_gained_rating*$points_rating+$points_gained_voting*$points_voting+$points_gained_auto;

    
$TOTAL_POINTS_CACHE[$member]=$points;

    return 
$points;
}

to:

PHP code


/**
 * Get the total points in the specified member's account; some of these will probably have been spent already
 *
 * @param  MEMBER            The member
 * @return integer        The number of points the member has
 */
function total_points($member)
{
    if (!
has_specific_permission($member,'use_points')) return 0;

    global 
$TOTAL_POINTS_CACHE;
    if (
array_key_exists($member,$TOTAL_POINTS_CACHE)) return $TOTAL_POINTS_CACHE[$member];

    
$points_gained_posting=0;
    if (
in_array(123,$GLOBALS['FORUM_DRIVER']->get_members_groups($member)))
        
$points_gained_posting=$GLOBALS['FORUM_DRIVER']->get_post_count($member);
    
$_points_gained=point_info($member);
    
$points_gained_given=array_key_exists('points_gained_given',$_points_gained)?$_points_gained['points_gained_given']:0;
    
$points_gained_rating=array_key_exists('points_gained_rating',$_points_gained)?$_points_gained['points_gained_rating']:0;
    
$points_gained_voting=array_key_exists('points_gained_voting',$_points_gained)?$_points_gained['points_gained_voting']:0;
    
$points_gained_cedi=array_key_exists('points_gained_seedy',$_points_gained)?$_points_gained['points_gained_seedy']:0;
    
$points_gained_chat=array_key_exists('points_gained_chat',$_points_gained)?$_points_gained['points_gained_chat']:0;
    
$points_posting=intval(get_option('points_posting'));
    
$points_rating=intval(get_option('points_rating'));
    
$points_voting=intval(get_option('points_voting'));
    
$points_joining=intval(get_option('points_joining'));
    
$points_per_day=intval(get_option('points_per_day',true));
    
$points_chat=intval(get_option('points_chat',true));
    
$points_cedi=intval(get_option('points_cedi',true));
    
$points_gained_auto=$points_per_day*intval(floor(floatval(time()-$GLOBALS['FORUM_DRIVER']->get_member_join_timestamp($member))/floatval(60*60*24)));
    
$points=$points_joining+$points_gained_chat*$points_chat+$points_gained_cedi*$points_cedi+$points_gained_posting*$points_posting+$points_gained_given+$points_gained_rating*$points_rating+$points_gained_voting*$points_voting+$points_gained_auto;

    
$TOTAL_POINTS_CACHE[$member]=$points;

    return 
$points;
}


I haven't tested it, and I hard-coded group ID #123.


Last edit: by Chris Graham


Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Support me on Patreon
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#111930
TQ
Avatar

Honoured member

Hi Chris,

I should first apologise for not responding before but, for some reason, I don't recall seeing the email response so I have only just read your reply whilst cruising the forum.

I have now tried you code change but I don't seem to be getting the result I expected. I have amended the group appropriately (#123 to 22), added a test user to the group and then added a few posts by that user. I have also reset the points to award 5 point per post.

The post count/points to the left of 'Current Points' is incrementing with each post but the actual 'Current Points' is not.

Is there anything else I should be doing?

TQ
Back to the top
 
Posted
Rating:
#111935
Avatar

I saw a mistake in my code, a $points_gained_posting= was missing. I edited my post.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Support me on Patreon
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Item has a rating of 5 (Liked by Chris Graham)  
Rating:
#111938
TQ
Avatar

Honoured member

Thank you Chris, that sorted it!

In case anyone else is interested in doing the same thing, it may be worth while changing the following in /POINTS_PROFILE.tpl to avoid members that are not in the group asking why they haven't been allocated posting points:

From:

Code

{+START,IF,{$NEQ,{POINTS_POSTING},0}}{+START,IF,{$HAS_FORUM}}
    <tr>
        <td>&bull; {!COUNT_POSTS}:</td>
        <td class="equation">{POST_COUNT*} &times; {POINTS_POSTING*} {!POINTS_UNIT}</td>
        <td class="answer">= {MULT_POINTS_POSTING*} {!POINTS_UNIT}</td>
    </tr>
{+END}{+END}
To:

Code

{+START,IF,{$IS_IN_GROUP,123}}
    {+START,IF,{$NEQ,{POINTS_POSTING},0}}{+START,IF,{$HAS_FORUM}}
        <tr>
            <td>&bull; {!COUNT_POSTS}:</td>
            <td class="equation">{POST_COUNT*} &times; {POINTS_POSTING*} {!POINTS_UNIT}</td>
            <td class="answer">= {MULT_POINTS_POSTING*} {!POINTS_UNIT}</td>
        </tr>
{+END}{+END}{+END}
(the same hard coded group note applies (#123))

Thank you again Chris, this is going to save me a lot of time in the future.

TQ
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: