Skip to content

Commit

Permalink
Added table.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuth committed Feb 12, 2012
1 parent 11757e5 commit 87ba93b
Showing 1 changed file with 81 additions and 6 deletions.
87 changes: 81 additions & 6 deletions recent/main.inc.php
Expand Up @@ -13,18 +13,19 @@
*/
function fivestarstats_recent() {


$votes = fivestarstats_recent_votes();
fivestarstats_debug($votes);
//fivestarstats_debug($votes); // Debugging

$retval = fivestarstats_recent_get_html($votes);
//fivestarstats_debug($retval); // Debugging

/**
TODO:
- Put into a nice table
- add links
- Add paging
*/

return($retval);

} // End of fivestarstats_get_recent_votes()


Expand All @@ -39,9 +40,14 @@ function fivestarstats_recent_votes() {

$num = 5;
$query = "SELECT "
. "votes.*, users.name, "
. "votes.timestamp, "
. "votes.vote_source, "
. "votes.content_type, votes.content_id, "
. "votes.value, "
. "users.uid, users.name, "
. "node.nid, "
. "node.title AS node_title, "
. "comments.cid, "
. "comments.cid, comments.nid AS comments_nid, "
. "comments.subject AS comment_title "
. "FROM votingapi_vote AS votes "
. "JOIN users ON votes.uid = users.uid "
Expand All @@ -59,8 +65,77 @@ function fivestarstats_recent_votes() {
$retval[] = $row;
}

//fivestarstats_debug($retval); // Debugging
return($retval);

} // End of givestarstats_recent_votes()


/**
* Turn our recent votes into HTML.
*
* @param array $data Our recent votes.
*
* @return string HTML
*/
function fivestarstats_recent_get_html($data) {

$retval = "";

$header = array("Date", "Title", "User", "IP", "Rating");
$rows = array();

foreach ($data as $key => $value) {

$value["timestamp"] = format_date(
$value["timestamp"], "custom", "Y-m-d H:i:s a");
$value["rating"] = $value["value"] / 20;

$maxlen = 60;

if (!empty($value["comment_title"])) {
$title = $value["comment_title"];
$title = truncate_utf8($title, $maxlen);
$nid = $value["comments_nid"];
$cid = $value["cid"];
$options = array("fragment" => "comment-" . $cid);
$title = l(t("Comment: ") . $title,
"node/" . $nid, $options);

} else {
$title = $value["node_title"];
$title = truncate_utf8($title, $maxlen);
$nid = $value["nid"];
$title = l($title, "node/" . $nid);

}

if (!empty($value["uid"])) {
$user = l($value["name"], "user/" . $value["uid"]);

} else {
$user = t("Anonymous");

}

$ip = $value["vote_source"];
$ip_string = l($ip, "admin/settings/fivestarstats/ip/" . $ip);

$row = array();
$row[] = array("data" => $value["timestamp"], "align" => "right");
$row[] = $title;
$row[] = $user;
$row[] = $ip_string;
$row[] = $value["rating"] . t(" stars");
$rows[] = $row;

}

$retval .= theme("table", $header, $rows);

return($retval);

} // End of fivestarstats_recent_get_html()



0 comments on commit 87ba93b

Please sign in to comment.