Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
693 views
in Q2A Core by

I would like users to have the possibility to up and downvote questions and to only upvote answers (no downvote on answers). Furthermore I want to limit the total number of votes casted (so down+upvotes cast) per user. I don't want a daily vote limit, but a limit over all time. Users can earn points by adding answers. If they have more points they can cast extra votes. All users start with 10 points, so when they are new to the website they can cast some votes. I 

Per up vote on your answer: 4 points

Voting up a question: -2   points

Voting down a question: -2   points

 

Voting up an answer: -1   points
 
Voting down an answer: -10000  points
Multiply all points: 1×  
Add for all users: + 10  points
 
The problem is that the system does not check if points are negative. Can this be easily solved? 
When the user has used up his 5 votes on questions, would he be able to remove his vote from one question (and earn back his points) and cast it on another question (and spend his points)?
 

 

Q2A version: 1.5.3

2 Answers

+1 vote
by

 

I managed to disable the upvote and downvote buttons on the questions and answers in case after the vote the user will have <0 points. 

I replace in qa-app-format.php  this code

 

if (strpos($voteview, '-uponly-level')) {

$fields['vote_state']='up_only';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
} else {
$fields['vote_state']='enabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_down_popup').'" NAME="'.qa_html('vote_'.$postid.'_-1_'.$elementid).'" '.$onclick;
}

 

with this code:

 

// calculation new points for the case the user clicks on down or upvote button
if ($isquestion){
$newpointsafterdownvote = qa_get_logged_in_points() + ((@$post['uservote']>0) ? -1*qa_opt('points_vote_up_q') : qa_opt('points_vote_down_q'));
$newpointsafterupvote = qa_get_logged_in_points() + ((@$post['uservote']<0) ? -1*qa_opt('points_vote_down_q') : qa_opt('points_vote_up_q'));
 
}else{
$newpointsafterdownvote = qa_get_logged_in_points() + ((@$post['uservote']>0) ? -1*qa_opt('points_vote_up_a') : qa_opt('points_vote_down_a'));
$newpointsafterupvote = qa_get_logged_in_points() + ((@$post['uservote']<0) ? -1*qa_opt('points_vote_down_a') : qa_opt('points_vote_up_a'));
}
if($newpointsafterdownvote<0){
// If after downvote user will have less than 0 points, then hide downvoting button
if($newpointsafterupvote<0){
// If after upvote user will have less than 0 points, then hide upvoting button
$fields['vote_state']='disabled';
$fields['vote_up_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
$fields['vote_down_tags']=$fields['vote_up_tags'];
 
}else{
// only hide downvoting button
$fields['vote_state']='up_only';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
}
}else{
 
+1 vote
by

 

second part of answer (because of 800 character limit error, my text was only 2843 characters).
if($newpointsafterupvote<0){
// only hide upvoting button
if (strpos($voteview, '-uponly-level')) {
$fields['vote_state']='disabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
$fields['vote_up_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
 
} else {
// vote_state 'down_only' does not exist. Therfore use disabled state. 
$fields['vote_state']='disabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
$fields['vote_up_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
}
}else{
// after click on either up or downvote button, points will be >0
if (strpos($voteview, '-uponly-level')) {
$fields['vote_state']='up_only';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
 
} else {
$fields['vote_state']='enabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_down_popup').'" NAME="'.qa_html('vote_'.$postid.'_-1_'.$elementid).'" '.$onclick;
}
}
}

 

}

...