$theme_id = intval($_POST['id']); $value = intval($_POST['value']); if ($theme_id > 0 && $value <= 1 && $value >= -1) { $list = theme_GetFinalThemeValidVotingList($EVENT_NODE); // Confirm theme is on the list // if (isset($list[$theme_id]) && $FINAL_VOTE_START_DIFF <= 0 && $FINAL_VOTE_END_DIFF > 0) { $response['id'] = theme_AddFinalVote($theme_id, $value, $user_id); $response['idea_id'] = $theme_id; } else { $response['id'] = 0; } } } else { if ($action == "GETFVOTES") { $votes = theme_GetMyFinalVotes($user_id); $list = theme_GetFinalThemeValidVotingList($EVENT_NODE); $response['id'] = $user_id; $response['votes'] = []; foreach ($votes as $vote) { if (isset($list[$vote['node']])) { $response['votes'][] = ['id' => $vote['node'], 'idea' => $list[$vote['node']], 'value' => $vote['value']]; } } } else { if ($action == "SETPARENT" && $ADMIN) { $parent = intval($_POST['parent']); $children = []; foreach ($_POST['children'] as $child) { if (intval($child) !== $parent) { $children[] = intval($child); }
function theme_GetFinalScores($node) { $themes = theme_GetFinalThemeValidVotingList($node); $ret = []; foreach ($themes as $key => $value) { $votes = theme_GetFinalVotes($key); $score_sum = 0; $scores = [-1 => 0, 0 => 0, 1 => 0]; $votes_count = count($votes); for ($idx = 0; $idx < $votes_count; $idx++) { $score_sum += intval($votes[$idx]); $scores[$votes[$idx]]++; } $ret[$key] = ['id' => $key, 'theme' => $themes[$key]['theme'], 'score' => $score_sum, 'scores' => $scores, 'count' => $votes_count]; } usort($ret, function ($a, $b) { if ($a['score'] == $b['score']) { return 0; } return $a['score'] > $b['score'] ? -1 : 1; }); return $ret; }