Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mymod_get_votes($type, $cid, $tag = 'vote', $uid = NULL) {
- global $user;
- $percent_threshold = variable_get('mymod_percent', 50);
- $number_threshold = variable_get('mymod_number', 5);
- $unpublished = 0;
- $criteria = array(
- 'entity_type' => $type,
- 'entity_id' => $cid,
- 'value_type' => 'points',//new addition - links to view. specifies that it is in points now, rather than percent.
- 'tag' => $tag,
- );
- $votes = array(
- 'average' => array(),
- 'count' => array(),
- 'user' => array(),
- );
- /** $vount = array(
- 'val' => array()
- );
- */
- $results = votingapi_select_results($criteria);
- // wizonesolutions START ----------------
- foreach ($results as $result) {
- $content_id = $result['content_id'];
- if ($result['function'] == 'sum') { // Add as many of these as you need for however many functions you are using
- $values[$content_id]['sum'] = $result['value'];
- }
- elseif ($result['function'] = 'count') {
- $values[$content_id]['count'] = $result['value'];
- }
- // Add more elseifs if using other functions
- $values[$content_id]['result'] = $result; // Save the original value of $result for our
- }
- foreach ($results as $result) {
- if ($result['function'] == 'average') {
- $votes['average'] = $result;
- }
- if ($result['function'] == 'points') {
- $votes['count'] = $result;
- }
- }
- //dsm(print_r($vount['val']));
- // dsm(print_r($percent_threshold));
- foreach ($values as $value){ // changed this too
- $val_x = $value['sum'];
- dsm(print_r('And the sum for node '));
- dsm(print_r($value['result']['content_id']));
- dsm(print_r(' is:'));
- dsm(print_r($value['sum']));
- dsm(print_r('; '));
- dsm(print_r(' percentage '));
- dsm(print_r (round($percentout)));
- //dsm(print_r($val_x));
- $vount = $value['count'];
- dsm(print_r('Hello friend! The count for node '));
- dsm(print_r($value['result']['content_id']));
- dsm(print_r(' is:'));
- dsm(print_r($value['count']));
- dsm(print_r('; '));
- }
- // wizonesolutions END ------------------
- if ($val_x<0){
- $poscount = ($vount+$val_x)/2;//note that we add here because it is a negative value, so adding is actually subtracting. Get the count, subtract the negative value, divide by two. You're now left with only the positive votes.
- $percentout = ($poscount/$vount)*100; //now just use the positive votes like a normal percentage sum.
- }
- elseif($val_x>0){
- $percentout = $val_x/$vount*100;
- }
- else{
- $percentout = 50;
- }
- } //foreach end
- } // main function end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement