<?
class frmIndexed extends MForm
{
    public $test;
 
    public function __construct()
    {   
		parent::__construct('Persistence Sample - Indexed Attributes');
        $this->setClose($this->manager->getActionURL('persistence','main'));
        $this->eventHandler();
	}

	function createFields()
    {
        $student = $this->manager->getBusiness('persistence','student');
        $query = $student->listAll();
        $answer = array('A'=>'A','B'=>'B','C'=>'C','D'=>'D','E'=>'E');
        $q = MForm::getFormValue('q');
        $fields = array(
            new MLabel('Insert a new test:','blue',true),
            new MSelection('number','','Student',$query->chunkResult(0,4)),
            new MSelection('q[1]',$q[1],'Question 1',$answer),
            new MSelection('q[2]',$q[2],'Question 2',$answer),
            new MSelection('q[3]',$q[3],'Question 3',$answer),
            new MSelection('q[4]',$q[4],'Question 4',$answer),
            new MSelection('q[5]',$q[5],'Question 5',$answer),
        );

        $this->setFields($fields);

        $buttons = array(
            new MButton('btnPost','Send Data')
        );

        $this->setButtons($buttons);

	}
    
    public function getData()
    {
        $data = new FormData();
        $data->number = $this->getFieldValue('number');
        $data->questions = $this->getFormValue('q');
        $data->date = $this->manager->getSysTime();
        return $data;
    }

    public function btnPost_click()
    {
        $data = $this->getData();
        $test = $this->manager->getBusiness('persistence','test');
        $test->setData($data);
        $test->save();
    }

}
?>
