コード例 #1
0
 /**
  * actionSelectEvaAssMethod
  * @param $id mixed
  */
 public function actionSelectEvaAssMethod($id = null)
 {
     $evaAttrCriteria = new CDbCriteria();
     $evaAttrCriteria->select = 'evaAttributes';
     $evaAttrCriteria->condition = 'evalId=' . $this->evaContextId;
     $evaluationAttributes = EvaluationHeader::model()->find($evaAttrCriteria);
     $evaAttributes = json_decode($evaluationAttributes->evaAttributes);
     // Get attribute names
     $evaAttributeMapCriteria = new CDbCriteria();
     $evaAttributeMapCriteria->select = 'attributeId, name';
     $evaAttributeMapCriteria->addInCondition('attributeId', $evaAttributes);
     $evaAttributeMap = CHtml::listData(EvaAttributes::model()->findAll($evaAttributeMapCriteria), 'attributeId', 'name');
     $assessModel = new EvaAssessmentMethods('default');
     $assessModel->evaluationId = $this->evaContextId;
     if (isset($id)) {
         // check if assessment method(s) exist
         $assessMethods = ModelToArray::convertModelToArray(EvaAttributesAssessmentMethods::model()->with('evaAssessmentMethods')->findAll('t.evaAttribute=:attribute', [':attribute' => $id]));
         // Check if there is any custom method
         $customMethod = ModelToArray::convertModelToArray($assessModel->find('evaluationId=:evaId AND customAssessmentMethod IS NOT NULL', [':evaId' => $this->evaContextId]));
         //			$response = $assessModel;
         //			if(!is_null($customMethod)) {
         //				$response = array_merge($assessMethods, $customMethod);
         //			}
         //print_r($assessMethods); die;
         echo json_encode(['aaData' => $assessMethods, 'customMethod' => $customMethod]);
         return;
     }
     if (isset($_POST['EvaAssessmentMethods'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $assessModel->deleteAll('evaluationId=:evalId', [':evalId' => $this->evaContextId]);
             foreach ($_POST['EvaAssessmentMethods'] as $row) {
                 if ($row != '') {
                     $assessModel->attributes = $row;
                     if ($_POST['EvaAssessmentMethods']['customAssessmentMethod'] != '') {
                         $assessModel->setScenario('customMethod');
                         $assessModel->customAssessmentMethod = $_POST['EvaAssessmentMethods']['customAssessmentMethod'];
                         $assessModel->unsetAttributes(['assessmentMethod']);
                         $assessModel->save();
                         $assessModel->setScenario('default');
                         break;
                     }
                     if (isset($assessModel->assessmentMethod)) {
                         $assessModel->setIsNewRecord(true);
                         $assessModel->id = null;
                         $assessModel->save();
                     }
                 }
             }
             if (!$assessModel->hasErrors()) {
                 $transaction->commit();
                 //print_r($_POST); die;
                 if (isset($_POST['next'])) {
                     Yii::app()->user->setFlash('success', 'Assessment method(s) saved successfully');
                     $this->redirect('evaSummary');
                     return;
                 }
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', 'An error occurred while saving the assessment method(s),' . ' please try again or contact your administrator if the problem persists');
         }
     }
     if (isset($_POST['pageId'])) {
         SystemController::savePage('selectEvaAssMethod');
     }
     $this->docName = 'evaAssMethods';
     $page = SystemController::getPageContent($this->docName);
     $this->render('selectEvaAssMethod', ['assessModel' => $assessModel, 'evaAttributeMap' => $evaAttributeMap, 'page' => $page]);
 }
コード例 #2
0
 /**
  * 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 EvaAttributesAssessmentMethods the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = EvaAttributesAssessmentMethods::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }