$theme_id = intval($_POST['id']); $value = intval($_POST['value']); if ($theme_id > 0 && $value <= 1 && $value >= -1) { $list = theme_GetThemeValidVotingList($EVENT_NODE); // Confirm theme is on the list // if (isset($list[$theme_id]) && $THEME_VOTE_START_DIFF[$list[$theme_id]['page']] <= 0 && $THEME_VOTE_END_DIFF[$list[$theme_id]['page']] > 0) { $response['id'] = theme_AddVote($theme_id, $value, $user_id); $response['idea_id'] = $theme_id; } else { $response['id'] = 0; } } } else { if ($action == "GETVOTES") { $votes = theme_GetMyVotes($user_id); $list = theme_GetThemeValidVotingList($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 == "FVOTE" && IsFinalThemeVotingOpen()) { $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) {
function theme_CalculateScores($node, $page) { $themes = theme_GetThemeValidVotingList($node); $ret = []; foreach ($themes as $key => $value) { if ($value['page'] !== $page) { continue; } $votes = theme_GetVotes($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]]++; } theme_SetVoteScore($key, $score_sum); $ret[$key] = ['score' => $score_sum, 'scores' => $scores, 'count' => $votes_count]; } return $ret; }