Пример #1
0
 /**
  * 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->question = QuestionsTable::getInstance()->findOneById($this->getRequest()->getParameter('questionId'));
     if ($this->question) {
         $this->answer = QuestionsAnswersTable::getInstance()->findOneByQuestionIdAndId($this->question->id, $this->getRequest()->getParameter('answerId'));
     }
     if ($this->answer) {
         $this->deleteAnswerForm = new deleteAnswerForm();
         $this->deleteAnswerForm->setDefaults($this->answer->toArray());
         if ($this->getRequest()->hasParameter('deleteAnswer')) {
             $this->deleteAnswerForm->bind($this->getRequest()->getParameter('deleteAnswer'));
             if ($this->deleteAnswerForm->isValid()) {
                 $this->answer->delete();
                 $this->redirect(url_for2('default', array('module' => 'questions', 'action' => 'answers'), true) . '?id=' . $this->question->id);
             }
         }
     }
 }