<?php
/**
 * class result_form
 *
 * Description for class result_form
 *
 * @author:
*/
namespace area\presentation\form;

use core\form;

class result_form extends form {
	private $presentation = null;
	private $slide = null;
	private $slideType = null;
	private $resultForm = null;
	public $reply = null;

	public function __construct($presentation, $step, $data = array()) {
		$this->presentation = $presentation;
		
		$this->slide = $this->presentation->slideGetId($step);
		if($this->slide === false) {
			exit;
		}
		
		$this->slideType = $this->presentation->typesGet($this->slide["type"]);
		if(empty($this->slideType["show"]["form"])) {
			exit;
		}

		if(empty($this->slideType["show"]["form"])) {
			__debug("Brak formularza");
		}

		require_once $this->slideType["show"]["form"];
		
		$this->resultForm = new \result($this->slide, $this->slide["config"], $this->slide["options"]);

		parent::__construct($data);
	}

	public function init() {
		$this->addElement("reply", array("required"));
		$this->addElement("time", array("required"));
	}

	public function valid($userId) {
		if($this->resultForm->valid($this->reply)) {
			return $this->save($userId);
		}

		return false;
	}

	protected function save($userId) {
		return $this->resultForm->save($this->presentation->presentationId, $this->slide["board_id"], $userId, $this->reply, $this->time);
	}
}
?>