public function testModelQuestionModelSavesModelResponses()
 {
     $this->auth();
     $question = new ModelQuestionModel(array('modelID' => 1, 'questionID' => 7, 'depth' => 'response'));
     $response = $question->createModelResponse('match', 'test');
     $modelResponseID = $response->modelResponseID;
     $question->save();
     $testResponse = new ModelResponseModel(array('modelResponseID' => $modelResponseID));
     $this->assertEquals($modelResponseID, $testResponse->modelResponseID);
 }
Beispiel #2
0
 /**
  * Save action.  Save a model.
  */
 public function saveAction()
 {
     // don't really need this but it should help with query caching efficiency
     $page = new ModelPageModel(array('modelID' => $this->model->modelID, 'pageID' => $this->view->currentPageID, 'depth' => 'response'));
     $responses = $this->_getParam('response');
     foreach ($responses as $questionID => $response) {
         $question = new ModelQuestionModel(array('modelID' => $this->model->modelID, 'questionID' => $questionID, 'depth' => 'response'));
         if ($question->nextModelResponse() !== null) {
             $question->delete();
         }
         if (!$this->isBlank($response)) {
             if ($response['noinclude']) {
                 $question->createModelResponse('no preference', '-');
             } else {
                 if ($response['target']) {
                     $this->setModelResponse($question, $response['target']);
                 }
                 if ($response['remediationInfoMod'] == 1) {
                     $question->createModelResponse('remediation info', -1, $response['remediationInfo']);
                 }
                 if ($response['requireAttachment'] == 1) {
                     $question->createModelResponse('require attachment', -1);
                 }
             }
         }
     }
     $this->flash('notice', 'Model saved successfully');
     $this->_redirector->gotoUrl("/compare/edit/{$this->model->modelID}?page={$page->pageID}");
 }