<?php
/**
 * class result_009_WordCloud
 *
 * Description for class result_009_WordCloud
 *
 * @author:
*/
use core\slideResult;

class result_009_WordCloud extends slideResult {
	public function result() {
		global $__database;

		$return = array(
			"users" => 0,
			"results" => array()
			);
		$result = array();

		$query = $__database->prepare("SELECT COUNT(DISTINCT `user_id`) AS `users` FROM `results` WHERE `board_id`=:id");
		$query->bindParam(":id", $this->id);
		$query->execute();
		if($row = $query->fetch()) {
			$return["users"] = $row["users"];
		}
		
		$query = $__database->prepare("SELECT `reply`, COUNT(`result_id`) AS `quantity` FROM `results` WHERE `board_id`=:id GROUP BY `reply`");
		$query->bindParam(":id", $this->id);
		$query->execute();
		while($row = $query->fetch()) {
			$result[] = array("text" => $row["reply"], "weight" => $row["quantity"]);
		}
		
		$return["results"] = $result;

		return $return;
	}
}
?>