/** * Executes index action * * @param sfRequest $request A request object */ public function execute($request) { sfContext::getInstance()->getConfiguration()->loadHelpers('Url'); $this->answers = QuestionsAnswersTable::getInstance()->findByQuestionId($this->getRequest()->getParameter('id')); $this->question = QuestionsTable::getInstance()->findOneById($this->getRequest()->getParameter('id')); $this->dayNumber = QuestionsOrderTable::getInstance()->findOneByQuestionId($this->getRequest()->getParameter('id')); $this->dayNumber = $this->dayNumber['day_number']; if ($this->answers) { $this->answersCollectionForm = new answersCollectionForm(null, array('answers' => $this->answers)); if ($this->getRequest()->hasParameter('answersCollection')) { $this->answersCollectionForm->bind($this->getRequest()->getParameter('answersCollection')); if ($this->answersCollectionForm->isValid()) { $i = 0; foreach ($this->answersCollectionForm->getValues() as $answer) { if ($this->answers[$i]->id == $answer['id']) { $this->answers[$i]->fromArray($answer); $this->answers[$i]->save(); $i++; } else { $invalidAnswer = QuestionsAnswersTable::getInstance()->findOneById($answer['id']); $invalidAnswer->fromArray($answer); $invalidAnswer->save(); } } } } } }
/** * Executes index action * * @param sfRequest $request A request object */ public function execute($request) { sfContext::getInstance()->getConfiguration()->loadHelpers('Url'); $this->addQuestionForm = new addQuestionForm(); if ($this->getRequest()->hasParameter('nr')) { $this->dayNumber = $this->getRequest()->getParameter('nr'); } if ($this->getRequest()->hasParameter('addQuestion')) { $this->addQuestionForm->bind($this->getRequest()->getParameter('addQuestion')); if ($this->addQuestionForm->isValid()) { $this->question = new Questions(); $this->question->fromArray($this->addQuestionForm->getValues()); $this->question->save(); $questionNumber = QuestionsOrderTable::getInstance()->findByDayNumber($this->dayNumber)->count(); $this->questionOrder = new QuestionsOrder(); $this->questionOrder->fromArray(array('day_number' => $this->dayNumber, 'question_number' => $questionNumber, 'question_id' => $this->question->id)); $this->questionOrder->save(); $this->redirect(url_for2('default', array('module' => 'questions', 'action' => 'answers'), true) . '?id=' . $this->question->id); } } }