You are here

function advpoll_ranking_process_rows in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_rows()
  2. 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_process_rows()

Remove duplicate rows for a given user in the case of multiple choice (typical of a ranking poll) and display one user's choice as a token delimited list indicating ranking preference.

Parameters

$rows: Several rows of voting data.

Return value

Returns a set of rows with duplicates removed and replaced with a single row displaying user's ranking of choices.

1 call to advpoll_ranking_process_rows()
advpoll_ranking_votes_page in advpoll_ranking/advpoll_ranking.module
Display the overridden votes page.

File

advpoll_ranking/advpoll_ranking.module, line 843

Code

function advpoll_ranking_process_rows($rows) {
  $users = array();
  $sorted = array();
  $votes = array();
  $final = array();

  // Get selections by user and put a single row of data in the sorted list by
  // user.
  foreach ($rows as $row) {
    $user = strip_tags($row['data'][0]);

    // Store choices with index being the value assigned to that choice.
    $votes[$user][$row['data'][3]] = $row['data'][2];
    if (!in_array($user, $users)) {
      $users[] = $user;

      // Remove vote value column since we do not want to display it in the
      // table.
      unset($row['data'][3]);
      $sorted[] = $row;
    }
  }

  // Now match up and rank user selections with the user's unique row.
  foreach ($sorted as $row) {
    $user = strip_tags($row['data'][0]);
    $choices = $votes[$user];
    krsort($choices);
    $choice = implode(' > ', $choices);
    $row['data'][2] = $choice;
    $final[] = $row;
  }
  $rows = $final;
  return $rows;
}