/** * actionSelectEvaAttributes */ public function actionSelectEvaAttributes() { $this->setPageTitle('Select Evaluation Attributes'); $evaDetails = $this->getEvaDetails(); //print_r($evaDetails); die; // Check if the evaluation is component based and check if components are selected $componentsCriteria = new CDbCriteria(); $componentsCriteria->condition = 't.evalId=:evaId AND evaElements.inputName=:name'; $componentsCriteria->with = ['evaluationHead', 'evaElements', 'options']; $componentsCriteria->params = [':evaId' => $this->evaContextId, ':name' => 'evaType']; $rsComponents = EvaluationDetails::model()->find($componentsCriteria); //print_r($rsComponents); die; if ($rsComponents->options->label == 'Component' && empty($rsComponents->evaluationHead->components)) { Yii::app()->user->setFlash('notice', 'Please select the surveillance components to evaluate first'); $this->redirect('selectComponents'); } $this->docName = 'evaAttributes'; if (isset($_POST['pageId'])) { SystemController::savePage('selectEvaAttributes'); } $page = SystemController::getPageContent($this->docName); $groups = EvaQuestionGroups::model()->find("section='evaCriteriaMethod'"); $groupsArray = json_decode($groups->questions); $group = $this->getQuestionGroup($groupsArray); // check if risk based options should be included $rsRiskBased = EvaluationDetails::model()->with('options')->find('evalId=:eva AND evalElementsId=:elemId', [':eva' => $this->evaContextId, ':elemId' => self::RISK_BASED_ELEMENT_ID]); if (isset($rsRiskBased->options) && $rsRiskBased->options->label == 'Yes') { array_push($group, self::RISK_BASED_OPTS_GROUP); } // var_dump($group); die; $attributesCriteria = new CDbCriteria(); $attributesCriteria->with = ['attributeTypes', 'attribute']; $attributesCriteria->order = 'relevance DESC'; $attributesCriteria->condition = 'surveillanceObj=' . $this->objectiveId; $attributesCriteria->addInCondition("evaQuestionGroup", $group); //$attributesCriteria->params = [':survObj' => $this->objectiveId, ':group' => [$group]]; $attributes = ModelToArray::convertModelToArray(EvaAttributesMatrix::model()->findAll($attributesCriteria)); $evaluationModel = EvaluationHeader::model()->findByPk($this->evaContextId, ['select' => 'evalId, evaAttributes']); //print_r($attributes); die; //$evaAttributes = isset($evaluationModel->evaAttributes) ? json_decode($evaluationModel->evaAttributes) : []; $evaluationModel->scenario = 'selectEvaAttributes'; if (isset($_POST['saveEvaAttr'])) { // $evaluationModel->evaAttributes = json_encode($_POST['EvaluationHeader']['evaAttributes']); $evaluationModel->evaAttributes = isset($_POST['EvaluationHeader']) ? json_encode($_POST['EvaluationHeader']['evaAttributes']) : null; if ($evaluationModel->validate() && $evaluationModel->update(['evaAttributes'])) { Yii::app()->user->setFlash('success', 'Evaluation attributes saved successfully'); if ($_POST['saveEvaAttr'] == 'Next') { $this->redirect('selectEvaAssMethod'); return; } } //var_dump($_POST, $evaluationModel); die; } $this->render('selectEvaAttributes', ['attributes' => $attributes, 'evaDetails' => $evaDetails, 'page' => $page, 'evaluationModel' => $evaluationModel]); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return EvaAttributesMatrix the loaded model * @throws CHttpException */ public function loadModel($id) { $model = EvaAttributesMatrix::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php /** * Created by PhpStorm. * User: james * Date: 8/2/15 * Time: 11:04 AM * @var array $model */ ?> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'attributeRelevance-form', 'enableAjaxValidation' => true)); $this->widget('ext.widgets.tabularinput.XTabularInput', ['models' => $model, 'containerTagName' => 'table', 'headerTagName' => 'thead', 'header' => ' <tr> <td>' . CHtml::activeLabelEX(EvaAttributesMatrix::model(), 'surveillanceObj') . '</td> <td>' . CHtml::activeLabelEX(EvaAttributesMatrix::model(), 'evaQuestionGroup') . '</td> <td>' . CHtml::activeLabelEX(EvaAttributesMatrix::model(), 'attributeId') . '</td> <td>' . CHtml::activeLabelEX(EvaAttributesMatrix::model(), 'relevance') . '</td> <td></td> </tr> ', 'inputContainerTagName' => 'tbody', 'inputTagName' => 'tr', 'inputView' => '_evaMatrixAsTable', 'inputUrl' => $this->createUrl('addMatrixRow'), 'addTemplate' => '<tfoot><tr><td colspan="1">{link}</td></tr></tfoot>', 'addLabel' => Yii::t('ui', 'Add'), 'addHtmlOptions' => ['class' => 'btn'], 'removeTemplate' => '<td>{link}</td>', 'removeLabel' => Yii::t('ui', 'Delete'), 'removeHtmlOptions' => ['class' => 'btn']]); echo CHtml::submitButton('Save'); $this->endWidget(); ?> </div>