<?php
/**
 * class result
 *
 * Description for class result
 *
 * @author:
*/
use form\slideResult_form;

class result extends slideResult_form {
	public function valid($sendData) {
		$sendData = $this->prepareOptions($sendData);
		if(count($sendData) == 0 || count($sendData) > $this->config["quantity"]) {
			return false;
		}

		return true;
	}

	public function save($presentationId, $slideId, $userId, $sendData, $time) {
		global $__database;

		$sendData = $this->prepareOptions($sendData);
		if(count($sendData) == 0) {
			return false;
		}

		try {
			foreach($sendData as $key => $text) {
				$query = $__database->prepare("INSERT INTO `results` (`result_id`, `presentation_id`, `board_id`, `user_id`, `reply`, `time`) VALUES (UUID(), :presentation_id, :board_id, :user_id, :reply, :time)");
				$query->bindParam(":presentation_id", $presentationId);
				$query->bindParam(":board_id", $slideId);
				$query->bindParam(":user_id", $userId);
				$query->bindParam(":reply", $text);
				$query->bindParam(":time", $time);
				$query->execute();
			}

			return true;
		} catch(PDOException $error) {

		}

		return false;
	}
}
?>