proposals.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. function proposals_get_votes($entity) {
  3. $annotations = elgg_get_annotations(array(
  4. 'guid' => $entity->guid,
  5. 'annotation_name' => 'votes',
  6. 'limit' => 0
  7. ));
  8. $votes = array();
  9. foreach(array("yes", "no", "block", "abstain") as $name) {
  10. $votes[$name] = 0;
  11. }
  12. foreach($annotations as $annotation) {
  13. if (!isset($votes[$annotation->value])) {
  14. $votes[$annotation->value] = 0;
  15. }
  16. $votes[$annotation->value] += 1;
  17. }
  18. return $votes;
  19. }
  20. function proposals_get_points_from_votes($votes) {
  21. $points = $votes["yes"] - ($votes["no"] + $votes["block"]);
  22. if ($points > 0) {
  23. $points = "+".$points;
  24. }
  25. return $points;
  26. }
  27. function proposals_get_status_from_votes($votes, $member_count) {
  28. $status = "no_consensus";
  29. $total_votes = array_sum($votes);
  30. if ($votes["block"]) {
  31. $status = "blocked";
  32. } elseif ($total_votes < $member_count/2) {
  33. $status = "new";
  34. } elseif ($votes["no"] >= $member_count / 2) {
  35. $status = "no_consensus";
  36. } elseif (($votes["yes"] > $votes["no"]+($member_count-$total_votes))) {
  37. $status = "consensus";
  38. }
  39. return $status;
  40. }