Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 245 lines (194 sloc) 6.149 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
<?php
/**
* Our form-related code.
*
* @author Douglas Muth <http://www.dmuth.org/>
*/


/**
* Our form callback.
*
* @param array $form_data Form data
*
* @param array $data Our array of data that we passed in
*
* @return array An array of form elements for the form generator.
*/
function fivestarstats_form($form_data, $data) {

$retval = array();

$retval["total_votes"] = fivestarstats_form_total_votes($data["total"]);
$retval["ips"] = fivestarstats_form_ips($data["ips"]);
$retval["users"] = fivestarstats_form_users($data["users"]);

return($retval);

} // End of fivestarstats_form()


/**
* Create form elements for the total vote data.
*
* @param array $data Our array of data that we passed in
*
* @return array An array of form elements for the form generator.
*/
function fivestarstats_form_total_votes($data) {

$retval = array(
"#type" => "fieldset",
"#title" => t("Total Votes"),
);

$retval["content"] = array(
"#type" => "item",
"#value" => t("%num_votes votes from %num_ips unique IPs "
. "with average of %num_stars stars per vote.",
array("%num_votes" => number_format($data["num_votes"]),
"%num_ips" => $data["num_ips"],
"%num_stars" => $data["average_stars"])
)
);

return($retval);

} // End of fivestarstats_form_total_values()


/**
* Create form elements for top IP addresses.
*
* @return array Array of form elements.
*/
function fivestarstats_form_ips($data) {

$retval = array(
"#type" => "fieldset",
"#title" => t("IP Activity"),
"#description" => "",
);

$content = array();

//
// Top voters
//
$header = array(t("IP"), t("# Votes Cast"));

$rows = array();
foreach ($data["top_voters"] as $key => $value) {
$link = l($value . t(" votes"),
"admin/settings/fivestarstats/ip/" . $key);
$row = array($key,
array("data" => $link, "align" => "right"),
);
$rows[] = $row;
}

$content["top voters"] = "<h2>" . t("Top Voters") . "</h2>";
$content["top voters"] .= theme("table", $header, $rows);


//
// Top 1-star voters
//
$rows = array();
foreach ($data["top_1_star_voters"] as $key => $value) {
$link = l($value . t(" votes"),
"admin/settings/fivestarstats/ip/" . $key);
$row = array($key,
array("data" => $link, "align" => "right"),
);
$rows[] = $row;
}

$content["top 1-star"] = "<h2>" . t("Top 1-star Voters") . "</h2>";
$content["top 1-star"] .= theme("table", $header, $rows);

//
// Lowest vote average
//
$header = array(t("IP"), t("# Votes Cast"), t("Average Vote"));
$rows = array();
foreach ($data["lowest_vote_average"] as $key => $value) {
$link = l($value["cnt"] . t(" votes"),
"admin/settings/fivestarstats/ip/" . $key);
$row = array($key,
array("data" => $link, "align" => "right"),
array("data" => sprintf("%.2f", $value["avg"]) . t(" stars"), "align" => "right"),
);
$rows[] = $row;
}

$content["lowest"] = "<h2>" . t("Lowest Vote Average") . "</h2>";
$content["lowest"] .= theme("table", $header, $rows);

$header = array();
$rows = array();
$rows[] = array($content["top voters"], $content["top 1-star"], $content["lowest"]);
$retval["#description"] = theme("table", $header, $rows);

return($retval);

} // End of fivestarstats_form_ips()


/**
* Create form elements with user info.
*/
function fivestarstats_form_users($data) {

$retval = array();

$retval = array(
"#type" => "fieldset",
"#title" => t("User Activity (votes received)"),
"#description" => "",
);

$content = array();

//
// Top-rated users
//
$header = array(t("Username"), t("# of times voted on"), t("Average Vote"));
$rows = array();
foreach ($data["top_rated"] as $key => $value) {
$link = l($value["num_votes"] . t(" votes"),
"admin/settings/fivestarstats/uid/" . $value["uid"]);
$row = array($value["name"],
array("data" => $link, "align" => "right"),
array("data" => sprintf("%.2f", $value["average"]) . t(" stars"),
"align" => "right"),
);
$rows[] = $row;
}

$content["top rated"] .= "<h2>" . t("Top-rated Users") . "</h2>";
$content["top rated"] .= theme("table", $header, $rows);

//
// Bottom-rated users
//
$rows = array();
foreach ($data["bottom_rated"] as $key => $value) {
$link = l($value["num_votes"] . t(" votes"),
"admin/settings/fivestarstats/uid/" . $value["uid"]);
$row = array($value["name"],
array("data" => $link, "align" => "right"),
array("data" => sprintf("%.2f", $value["average"]) . t(" stars"),
"align" => "right"),
);
$rows[] = $row;

}

$content["bottom rated"] .= "<h2>" . t("Bottom-rated Users") . "</h2>";
$content["bottom rated"] .= theme("table", $header, $rows);

//
// Most 1-star votes received.
//
$header = array(t("Username"), t("# of 1-star votes received"));

$rows = array();
foreach ($data["most_1_star_votes"] as $key => $value) {
$link = l($value["cnt"] . t(" votes"),
"admin/settings/fivestarstats/uid/" . $value["uid"]);
$row = array($value["name"],
array("data" => $link, "align" => "right"),
);
$rows[] = $row;
}


$content["1-star"] .= "<h2>" . t("Most 1-star votes received") . "</h2>";
$content["1-star"] .= theme("table", $header, $rows);

//
// Top Posters
//
$header = array(t("Username"), t("# posts"), t("# votes received"),
t("average rating"));
$rows = array();
foreach ($data["top_posters"] as $key => $value) {
$link = l($value["num_votes"] . t(" votes"),
"admin/settings/fivestarstats/uid/" . $value["uid"]);
$row = array($value["name"],
array("data" => $value["num_posts"] . t(" posts"),
"align" => "right"),
array("data" => $link, "align" => "right"),
array("data" => sprintf("%.2f stars", $value["average"]),
"align" => "right"),
);
$rows[] = $row;
}


$content["top posts"] .= "<h2>" . t("Top posts by # posts/comments") . "</h2>";
$content["top posts"] .= theme("table", $header, $rows);

$header = array();
$rows = array();
$rows[] = array($content["top rated"], $content["top posts"]);
$rows[] = array($content["1-star"], $content["bottom rated"]);

$retval["#description"] = theme("table", $header, $rows);

return($retval);

} // End of fivestarstats_form_users()


Something went wrong with that request. Please try again.