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); }
/** * 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}"); }
/** * Return HTML for the remediation info box * * @param ModelQuestionModel * @return string */ public function remediationInfo(ModelQuestionModel $modelQuestion) { $class = 'remediationInfo'; if ($modelQuestion->hasRemediationInfo()) { $class .= ' hasContent'; $content = $this->view->h($modelQuestion->remediationInfo()); $style = ''; $mod = 1; } else { $style = 'display: none;'; $content = 'Enter remediation information here'; $mod = 0; } $remediationInfo = $this->view->formTextarea("response[{$modelQuestion->questionID}][remediationInfo]", $content, array('class' => $class, 'style' => $style)); $remediationInfoMod = $this->view->formHidden("response[{$modelQuestion->questionID}][remediationInfoMod]", $mod); return $remediationInfo . $remediationInfoMod; }
/** * Instantiate a new ModelQuestionModel object * * @param array */ public function __construct($args = array()) { $args = array_merge(array('depth' => 'question', 'instance' => null), $args); $this->depth = $args['depth']; $this->compareInstance = $args['instance']; if (!isset(self::$modelTable)) { self::$modelTable = QFrame_Db_Table::getTable('model'); } if (!isset(self::$modelResponseTable)) { self::$modelResponseTable = QFrame_Db_Table::getTable('model_response'); } if (!isset(self::$questionTable)) { self::$questionTable = QFrame_Db_Table::getTable('question'); } if (!isset(self::$pageTable)) { self::$pageTable = QFrame_Db_Table::getTable('page'); } if (isset($args['modelID']) && isset($args['questionID'])) { $this->modelID = $args['modelID']; $this->question = new QuestionModel(array('questionID' => $args['questionID'], 'depth' => $args['depth'])); } else { throw new InvalidArgumentException('Missing arguments to ModelQuestionModel constructor'); } if ($this->depth !== 'question') { $this->_loadModelResponses(); } if (!isset($args['noChildren']) && $this->question->format == '_questionGroup') { $this->_loadChildren(); } }