예제 #1
0
 private static function crearPreguntasDesdeInput(array $input, Encuesta $encuesta)
 {
     $data = json_decode($input['data']);
     $questions = [];
     foreach ($data->questions as $question) {
         $pregunta = Pregunta::forceCreate(['encuesta_id' => $encuesta->id, 'titulo' => $question->titulo, 'html' => $question->html, 'tipo' => $question->tipo, 'name' => $question->name]);
         foreach ($question->answers as $answer) {
             SolucionPosible::forceCreate(['pregunta_id' => $pregunta->id, 'valor' => $answer->valor, 'descripcion' => $answer->id]);
         }
         $questions[] = $pregunta;
     }
     return new Collection($questions);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Pregunta::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'codFormulario', $this->codFormulario])->andFilterWhere(['like', 'descripcion', $this->descripcion]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * Finds the Pregunta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Pregunta the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Pregunta::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 public function deletePregunta($id)
 {
     $model = Pregunta::findOne($id);
     $model->eliminado = 1;
     $model->save();
 }
예제 #5
0
파일: Tipo.php 프로젝트: rolion/taller1
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPreguntas()
 {
     return $this->hasMany(Pregunta::className(), ['id_tipo' => 'id']);
 }
예제 #6
0
 public function destroyPregunta($id)
 {
     try {
         $pre = Pregunta::find($id);
         $list = DB::table('respuesta')->where('pregunta', '=', $pre->id)->get();
         //return $list;
         if (!empty($list)) {
             foreach ($list as &$value) {
                 $res = Respuesta::find($value->id);
                 $res->delete();
             }
         }
         $pre->delete();
         return JsonResponse::create(array('message' => "Pregunta Eliminada Correctamente", "request" => json_encode($id)), 200);
     } catch (Exception $ex) {
         return JsonResponse::create(array('message' => "No se pudo Eliminar la pregunta", "exception" => $ex->getMessage(), "request" => json_encode($id)), 401);
     }
 }
예제 #7
0
파일: Examen.php 프로젝트: rolion/taller1
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPreguntas()
 {
     return $this->hasMany(Pregunta::className(), ['id_examen' => 'id'])->orderBy('nro_pregunta');
 }
 public function guardarRespuestas(array $respuestas)
 {
     DB::transaction(function () use($respuestas) {
         foreach ($respuestas as $name => $value) {
             //ubicamos la pregunta por su nombre
             /** @var Pregunta $pregunta */
             $pregunta = Pregunta::where(function ($query) use($name) {
                 $query->where('name', $name)->orWhere('name', "{$name}[]");
             })->where('encuesta_id', $this->encuesta_id)->first();
             if (!$pregunta) {
                 continue;
             }
             //Cargamos su respuesta
             /** @var Respuesta $respuesta */
             $respuesta = Respuesta::where('resolucion_id', $this->id)->where('pregunta_id', $pregunta->id)->first();
             if ($pregunta && $respuesta) {
                 $respuesta->texto = is_array($value) ? implode('<br />', $value) : $value;
                 $respuesta->save();
             }
         }
         $this->fecha_entrega = date('Y-m-d H:i:s');
         $this->estado = 'completa';
         $this->save();
     });
 }
예제 #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdPregunta0()
 {
     return $this->hasOne(Pregunta::className(), ['id' => 'idPregunta', 'codFormulario' => 'codFormulario']);
 }
예제 #10
0
 /**
  * Finds the Pregunta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @param string $codFormulario
  * @return Pregunta the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $codFormulario)
 {
     if (($model = Pregunta::findOne(['id' => $id, 'codFormulario' => $codFormulario])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPreguntas()
 {
     return $this->hasMany(Pregunta::className(), ['codFormulario' => 'codigo']);
 }
예제 #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdPregunta()
 {
     return $this->hasOne(Pregunta::className(), ['id' => 'id_pregunta']);
 }