public function SaveData($DataOBJ)
 {
     $user_id = Yii::$app->session->get('user');
     $data = $DataOBJ->getAttributes();
     $qObj = questionnaire::find()->select(['id']);
     //$NoErrors = true;
     $dbRq = Yii::$app->db->createCommand('INSERT INTO ' . self::tableName() . ' (user_id, id_Q, user_response)
     values (' . $user_id . ', :id_QV, :user_responseV)');
     if (intval($user_id) > 0) {
         foreach ($data as $atrName => $atrVal) {
             $dbRq->bindValues([':id_QV' => current($qObj->where(['post_index' => $atrName])->asArray()->one()), ':user_responseV' => $atrVal])->execute();
             /*
             // --- bad not work
             // --- $this->id_Q = current($qObj->where(['post_index' => $atrName])->asArray()->one());
             // --- $this->user_response = $atrVal;
             // --- $NoErrors = (($this->save()) && ($NoErrors === true))? true: false;
             
             // its work label_1
             $NoErrors = (($this->SeveOne(id_Q, current($qObj->where(['post_index' => $atrName])->asArray()->one()), $atrVal))
                     && ($NoErrors === true))? true: false;
             */
         }
         //return $NoErrors;
         return true;
     } else {
         return false;
     }
 }
示例#2
0
 private function getItems($formName)
 {
     $Items = questionnaire::find()->select(['type', 'title', 'post_index']);
     return $Items->where(['formName' => $formName])->asArray()->all();
 }