Skip to content

Instantly share code, notes, and snippets.

@dmclark
Created May 24, 2011 20:31
Show Gist options
  • Save dmclark/989600 to your computer and use it in GitHub Desktop.
Save dmclark/989600 to your computer and use it in GitHub Desktop.
public function configure()
{
parent::configure();
$this->test = $this->getOption('test');
$this->setWidget('administered_on', new sfWidgetFormInputHidden());
$questions = is_object($this->test) ? $this->test->getQuestionswithAnswers() : array();
$this->setWidget('client_id', new sfWidgetFormInputHidden());
$this->setWidget('instrument_id', new sfWidgetFormInputHidden());
foreach($questions as $question)
{
$type = $question->type;
if ($type != 'heading') {
if ($type == 'sfWidgetFormSelect' ||$type == 'sfWidgetFormSelectRadio') {
$choices = !is_null($question->choice_array) ? explode(', ', $question->choice_array) : Doctrine_Core::getTable('Test')->getChoices($question->choice);
$w = new $type(array('label' => $question, 'choices' => $choices,'default' => $question->getResponse() ));
} elseif ($type == 'sfWidgetFormSelectCheckbox') {
$choices = !is_null($question->choice_array) ? explode(', ', $question->choice_array) : Doctrine_Core::getTable('Test')->getChoices($question->choice);
$w = new $type(array('label' => 'none', 'choices' => $choices ));
}else {
$w = new $type(array('label' => $question, 'default' => $question->response ));
}
$num = $question->getId();
$v = new sfValidatorDoctrineChoice(array('model' => 'Answer', 'required' => true));
$this->setWidget('question_'.$num, $w);
$this->setValidator('question_'.$num, $v);
if ($type == 'sfWidgetFormSelectCheckbox') {
$this->widgetSchema->setDefault('question_'.$num, $question->getResponse());
}
} else {
$w = new sfWidgetFormDiv(array('label' => $question, 'default' => $question->response ));
$this->setWidget('element_'.$question->getId(), $w);
}
}
$this->widgetSchema->setNameFormat('test[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
unset( $this['created_at'],
$this['updated_at'],
$this['slots_list'],
$this['staff_id']
);
$this->disableLocalCSRFProtection();
$decorator = new sfWidgetFormSchemaFormatterTable($this->getWidgetSchema());
$this->widgetSchema->addFormFormatter('custom', $decorator);
$this->widgetSchema->setFormFormatterName('table');
$this->validatorSchema->setOption('allow_extra_fields', true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment