Example #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $pregunta = Pregunta::model()->findByPk($id);
     if (isset($_POST['Pregunta'])) {
         $pregunta->attributes = $_POST['Pregunta'];
         if ($pregunta->validate()) {
             if (!$pregunta->save()) {
                 Yii::app()->user->setFlash('mensaje', 'La pregunta ' . $pregunta->pregunta . ' no se pudo guardar');
             }
             if (isset($_POST['Respuesta'])) {
                 foreach ($_POST['Respuesta'] as $k => $r) {
                     if ($k > 0) {
                         $respuesta = Respuesta::model()->findByPk($k);
                     } else {
                         $respuesta = new Respuesta();
                     }
                     $respuesta->respuesta = $r['respuesta'];
                     $respuesta->es_correcta = $r['es_correcta'];
                     $respuesta->save();
                 }
             }
         }
         //if($preguntaForm->validate())
     }
     //if(isset($_POST['Pregunta']))/**/
     $this->render('modificar', array('model' => $pregunta));
 }
 public function crearEncuesta($encuesta, $email, $nombre = 'sin dato', $empresa = 'sin dato')
 {
     if (Session::token() != Input::get('_token')) {
         die;
     }
     $respuesta = Input::all();
     //array respuestas form //print_r($respuesta);
     $datosEncuesta = DB::table('encuesta')->where('id', $encuesta)->first();
     $cantidad = DB::table('pregunta')->where('idEncuesta', $encuesta)->count();
     //Inserta usuario por email e ip
     $ip = Request::getClientIp();
     $usuariosEmail = DB::table('users')->where('email', $email)->first();
     //codigo rand
     $usuariosEmail = DB::table('users')->where('email', $email)->first();
     $base = 1245;
     $cant = DB::table('users')->count();
     $random = $base + $cant;
     if (empty($usuariosEmail)) {
         $x = new User();
         $x->email = $email;
         $x->nombre = $nombre;
         $x->empresa = $empresa;
         $x->ip = $ip;
         $x->codigo = $random;
         $x->save();
     } else {
         $mensaje = 'Usted ya ha completado la encuesta, sólo puede realizar esta acción una vez';
         return View::make('encuesta.completado', array('mensaje' => $mensaje, 'encuesta' => $datosEncuesta));
     }
     $usuarios = DB::table('users')->where('email', $email)->first();
     $usuario = $usuarios->id;
     $codigo = $usuarios->codigo;
     Session::put('codigo', $codigo);
     //Inserta usuario_encuesta
     $x = new UsuarioEncuesta();
     $x->idUsuario = $usuario;
     $x->idEncuesta = $encuesta;
     $x->save();
     $usuarioEnc = DB::table('usuario_encuesta')->where('idUsuario', $usuario)->first();
     $usuarioEncuesta = $usuarioEnc->id;
     //Inserta respuestas
     for ($i = 1; $i <= $cantidad; $i++) {
         $valor = Input::get('pregunta' . $i);
         if ($valor != '') {
             $x = new Respuesta();
             $x->idUsuarioEncuesta = $usuarioEncuesta;
             $x->idEncuestaPregunta = $i;
             $x->valor = $valor;
             $x->save();
         }
     }
     return Redirect::to('/formulario-ok');
     //return View::make('encuesta.completado', array('encuesta' => $datosEncuesta,'email' => $email, 'nombre' => $nombre, 'empresa' => $empresa, 'codigo' => $random));
 }
Example #3
0
 public function guardar()
 {
     $respuesta = Input::get('respuestas');
     $table = new Respuesta();
     $table->user_id = Auth::user()->id;
     $table->sexo = $respuesta['sexo'];
     $table->edad = $respuesta['edad'];
     $table->p1 = strtoupper($respuesta['p1']);
     $table->p1A = strtoupper($respuesta['p1A']);
     $table->p2 = $respuesta['p2'];
     $table->p3 = $respuesta['p3'];
     $table->p4 = $respuesta['p4'];
     $table->p4A = $respuesta['p4A'];
     $table->p5 = $respuesta['p5'];
     $table->p6 = $respuesta['p6'];
     $table->p7 = $respuesta['p7'];
     $table->p8 = $respuesta['p8'];
     $table->p9 = $respuesta['p9'];
     $table->p10 = $respuesta['p10'];
     $table->p11 = $respuesta['p11'];
     $table->p12 = $respuesta['p12'];
     $table->p13 = $respuesta['p13'];
     $table->p14 = $respuesta['p14'];
     $table->p15 = $respuesta['p15'];
     $table->p15A = $respuesta['p15A'];
     $table->p16 = $respuesta['p16'];
     $table->p17 = $respuesta['p17'];
     $table->p18 = $respuesta['p18'];
     $table->p18A = $respuesta['p18A'];
     $table->p19 = $respuesta['p19'];
     $table->p20 = $respuesta['p20'];
     $table->p21 = $respuesta['p21'];
     $table->p22 = $respuesta['p22'];
     $table->p23 = $respuesta['p23'];
     $table->p24 = $respuesta['p24'];
     $table->p25 = $respuesta['p25'];
     $table->p26 = $respuesta['p26'];
     $table->p27 = $respuesta['p27'];
     if ($table->save()) {
         return 'success';
     }
     return 'error refresque la pagina y intente de nuevo';
 }
 public function run()
 {
     Respuesta::create(['id_estado' => 6, 'id_canal' => 1, 'id_encuesta' => 1, 'id_pregunta' => 1, 'id_pregunta_detalle' => 1, 'id_cliente' => 1]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 1, 'id_encuesta' => 1, 'id_pregunta' => 2, 'id_pregunta_detalle' => 2, 'id_cliente' => 1]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 1, 'id_encuesta' => 1, 'id_pregunta' => 3, 'id_pregunta_detalle' => 3, 'id_cliente' => 1]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 1, 'id_encuesta' => 1, 'id_pregunta' => 4, 'id_pregunta_detalle' => 4, 'id_cliente' => 1]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 3, 'id_encuesta' => 1, 'id_pregunta' => 1, 'id_pregunta_detalle' => 1, 'id_cliente' => 2]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 3, 'id_encuesta' => 1, 'id_pregunta' => 2, 'id_pregunta_detalle' => 2, 'id_cliente' => 2]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 3, 'id_encuesta' => 1, 'id_pregunta' => 3, 'id_pregunta_detalle' => 3, 'id_cliente' => 2]);
     Respuesta::create(['id_estado' => 6, 'id_canal' => 3, 'id_encuesta' => 1, 'id_pregunta' => 4, 'id_pregunta_detalle' => 4, 'id_cliente' => 2]);
 }
 public function store()
 {
     $pass = false;
     $inputs = Input::all();
     if (!array_key_exists('pregunta_1', $inputs) or !array_key_exists('pregunta_2', $inputs) or !array_key_exists('pregunta_3', $inputs) or !array_key_exists('pregunta_4', $inputs)) {
         echo $errors = 'Debe contestar todas las preguntas';
         return Redirect::back()->withErrors($errors)->withInput();
     } else {
         foreach ($inputs as $key => $value) {
             if ($key != '_token') {
                 if (array_get($value, 'value', '') == '') {
                     echo $errors = 'Debe contestar todas las preguntas';
                     return Redirect::back()->withErrors($errors)->withInput();
                 }
             }
         }
     }
     $cr = new ClientesRespuesta();
     $cr->id_cliente = Auth::user()->id_cliente;
     $cr->ultima_respuesta = Carbon::now();
     $cr->id_estado = 15;
     if ($cr->save()) {
         $cli_resp = $cr->id_cliente_respuesta;
     } else {
         Event::fire('form_error');
     }
     if (!is_null($cli_resp)) {
         $respuesta_detalle = array();
         foreach ($inputs as $key => $value) {
             if ($key != '_token') {
                 $respuesta = Respuesta::insertGetId(array('fecha' => Carbon::now(), 'id_estado' => '6', 'id_canal' => Session::get('canal'), 'id_encuesta' => Session::get('encuesta', 1), 'id_pregunta' => (int) str_replace('pregunta_', '', $key), 'id_pregunta_detalle' => 1, 'id_cliente' => Auth::user()->id_cliente, 'id_cliente_respuesta' => $cli_resp, 'created_at' => Carbon::now()));
                 if (!is_null($respuesta)) {
                     $val = array_get($value, 'value');
                     $text = array_get($value, 'text');
                     array_push($respuesta_detalle, array('valor1' => trim($val) != '' ? $val : null, 'valor2' => trim($text) != '' && Str::length($text) > 0 ? $text : null, 'id_respuesta' => $respuesta, 'created_at' => Carbon::now()));
                 } else {
                     Event::fire('form_error');
                 }
             }
         }
     }
     unset($resp_d);
     unset($resp);
     unset($inputs);
     if (RespuestasDetalle::insert($respuesta_detalle)) {
         Session::flush();
         $msg = array('data' => array('type' => 'success', 'text' => '<i class="fa fa-check fa-fw"></i>Gracias por tu tiempo y disponibilidad en responder, ¡Tu opinión es muy importante!'));
         $script = "setTimeout('window.location.href=\"http://www.umayor.cl/\";', 5000); if (typeof window.event == 'undefined'){ document.onkeypress = function(e){ var test_var=e.target.nodeName.toUpperCase(); if (e.target.type) var test_type=e.target.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return e.keyCode; }else if (e.keyCode == 8 || e.keyCode == 116 || e.keyCode == 122){ e.preventDefault(); } } }else{ document.onkeydown = function(){ var test_var=event.srcElement.tagName.toUpperCase(); if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase(); if ((test_var == 'INPUT' && test_type == 'TEXT') || test_var == 'TEXTAREA'){ return event.keyCode; } else if (event.keyCode == 8 || e.keyCode == 116 || e.keyCode == 122){ event.returnValue=false; } } } ";
         return View::make('messages', compact('msg', 'script'));
     } else {
         Event::fire('form_error');
     }
 }
Example #6
0
 public function obtener_pregunta($nivel = 5, $pregunta_id = 0)
 {
     if ($pregunta_id) {
         $pregunta = $this->findByPk($pregunta_id);
     } else {
         $pregunta = $this->pregunta_al_azar($nivel);
     }
     $rcriteria = new CDbCriteria();
     $rcriteria->select = array('id', 'respuesta');
     $rcriteria->condition = 'pregunta_id=:pregunta_id';
     $rcriteria->params = array(':pregunta_id' => $pregunta->id);
     $respuestas = Respuesta::model()->findAll($rcriteria);
     $result = array('pregunta' => $pregunta, 'respuestas' => $respuestas);
     return $result;
 }
 function getListPagina($pagina = 0, $rpp = 10, $condicion = "1=1", $parametros = array(), $orderby = "1")
 {
     $pos = $pagina * $rpp;
     $sql = "select * from encuesta e join pregunta p on e.id=p.idencuesta join respuesta r on p.id=r.idpregunta;";
     $r = $this->bd->setConsulta($sql, $parametros);
     $respuesta = array();
     //$cont=0;
     while ($fila = $this->bd->getFila()) {
         $objeto1 = new Encuesta();
         $objeto1->set($fila);
         $objeto2 = new Pregunta();
         $objeto2->set($fila, 3);
         $objeto3 = new Respuesta();
         $objeto3->set($fila, 6);
         $respuesta[] = new JoinEPR($objeto1, $objeto2, $objeto3);
         /*
                       $respuesta[$cont][0] = $objeto1;
                       $respuesta[$cont][1] = $objeto2;
                       $respuesta[$cont][2] = $objeto3;
                       $cont++;
         */
     }
     return $respuesta;
 }
Example #8
0
 public function actionIndex()
 {
     //Cargo la pregunta para responder
     $triviaForm = new TriviaForm();
     if (isset($_POST['TriviaForm'])) {
         $triviaForm->attributes = $_POST['TriviaForm'];
         //Verifico que la pregunta sea la misma que la cargada en la sesión
         if ($triviaForm->pregunta != $this->_preguntaid) {
             $this->_error();
         }
         //Agregar la pregunta a ronda_x_respuesta
         $rxr = new RondaXRespuesta();
         $rxr->ronda_id = $this->_ronda;
         $rxr->respuesta_id = $triviaForm->respuesta;
         $rxr->usuario_id = $this->_usuario_id;
         $rxr->save();
         //Verifico si es la respuesta correcta
         $r = Respuesta::model()->findByPk($triviaForm->respuesta);
         if ($r->es_correcta) {
             $situacion = 3;
             //3. Respuesta correcta
             $puntos = $rxr->ronda->puntos;
             Yii::app()->user->setFlash('error', 'respuesta-bien');
             Yii::app()->user->setFlash('puntos', $puntos);
             //Sumar puntos
         } else {
             $situacion = 4;
             //4. Respuesta mala
             Yii::app()->user->setFlash('error', 'respuesta-mal');
         }
         Yii::app()->session['situacion'] = $this->_situacion = $situacion;
         $this->_error();
     }
     //if( isset($_POST['TriviaForm']) )
     if ($this->_situacion == 2) {
         $pregunta = Pregunta::model()->obtener_pregunta($this->_ronda, $this->_preguntaid);
     } else {
         $pregunta = Pregunta::model()->obtener_pregunta($this->_ronda);
     }
     Yii::app()->session['preguntaid'] = $this->_preguntaid = $pregunta->id;
     Yii::app()->session['situacion'] = $this->_situacion = 2;
     //2. pregunta
     foreach ($pregunta->respuestas as $r) {
         $respuestas[$r->id] = $r->respuesta;
     }
     $this->render('index', array('model' => $triviaForm, 'pregunta' => $pregunta, 'respuestas' => $respuestas));
 }
Example #9
0
//dame tareas para el combobox
function damepregunta()
{
    $consulta_mysql = "SELECT tb_pregunta.intidpregunta,tb_pregunta.nvchdescripcion,tb_pregunta.nvchpregunta from tb_pregunta";
    $resultado_consulta_mysql = mysql_query($consulta_mysql);
    while ($registro = mysql_fetch_array($resultado_consulta_mysql)) {
        echo "\n            <option style='font-size:15px; margin:5px' value='" . $registro['intidpregunta'] . "'>\n              " . $registro['nvchdescripcion'] . "-" . $registro['nvchpregunta'] . "\n            </option>\n        ";
    }
}
//end dame tareas para el combobox
//definiendo la estructura del mvc
require_once 'respuesta.entidad.php';
require_once 'respuesta.model.php';
$buttonname = 'Registrar';
// Logica
$rsp = new Respuesta();
$model = new RespuestaModel();
if (isset($_REQUEST['action'])) {
    switch ($_REQUEST['action']) {
        case 'actualizar':
            $rsp->__SET('intidrespuesta', $_REQUEST['intidrespuesta']);
            $rsp->__SET('intidpregunta', $_REQUEST['intidpregunta']);
            $rsp->__SET('nvchrespuesta', $_REQUEST['nvchrespuesta']);
            $rsp->__SET('chrvf', $_REQUEST['chrvf']);
            $model->Actualizar($rsp);
            header('Location: respuesta.php');
            break;
        case 'registrar':
            //$preg->__SET('intidpregunta',$_REQUEST['intidpregunta']);
            $rsp->__SET('intidpregunta', $_REQUEST['intidpregunta']);
            $rsp->__SET('nvchrespuesta', $_REQUEST['nvchrespuesta']);
Example #10
0
 public function actionResponder()
 {
     $this->verificar_sesion();
     if (!Yii::app()->request->isAjaxRequest) {
         throw new CHttpException('403', 'Forbidden access.');
     }
     if (!isset($_POST['r']) && !is_int($_POST['r'])) {
         throw new CHttpException('403', 'Forbidden access.');
     }
     $respuesta = $_POST['r'];
     $tiempo = $_POST['t'];
     $r = Respuesta::model()->findByPk($respuesta);
     //Agrego la pregunta al array para no repetirla esta ronda
     $this->_preguntas[] = $this->_preguntaid;
     Yii::app()->session['preguntas'] = $this->_preguntas;
     if ($r->es_correcta) {
         $nivel = Nivel::model()->findByPk($this->_nivel);
         $ronda = Ronda::model()->findByPk($this->_ronda);
         $puntosr = $ronda->puntos + $nivel->puntos;
         $a = array('tiempo' => $ronda->tiempo + ($nivel->tiempo - $tiempo), 'preguntas' => $this->_preguntan, 'nivel' => $this->_nivel, 'puntos' => $puntosr);
         $ronda->updateByPk($this->_ronda, $a);
         //Agregar la pregunta a pregunta_x_ronda
         $pxr = PreguntaXRonda::model()->findByAttributes(array('ronda_id' => $this->_ronda, 'pregunta_id' => $this->_preguntaid));
         $pxr->estado = 1;
         $pxr->update();
         Yii::app()->session['preguntaid'] = $this->_preguntaid = 0;
         Yii::app()->session['puntosr'] = $this->_puntosr = $puntosr;
         //Sumo puntos
         $pt = Jugador::model()->setPuntos($nivel->puntos, $this->_jugador_id);
         if ($pt) {
             Yii::app()->session['puntost'] = $this->_puntost = $pt;
         }
         if ($this->_preguntan < Yii::app()->params['preguntasxnivel'] * $this->_nivel) {
             $tmpsituacion = 3;
             //3. Respuesta correcta
         } else {
             if ($this->_nivel < 5) {
                 $tmpsituacion = 5;
                 //5. Cambio de nivel
                 $newnivel = Nivel::model()->findByPk($this->_nivel + 1);
                 Yii::app()->session['nivel'] = $this->_nivel = $this->_nivel + 1;
                 Yii::app()->session['tiempo'] = $this->_tiempo = $newnivel->tiempo;
             } else {
                 $tmpsituacion = 6;
                 //6. Ronda completada
             }
         }
         $situacion = $tmpsituacion;
     } else {
         $situacion = 4;
         //4. Respuesta mala
         $nivel = Nivel::model()->findByPk($this->_nivel);
         $ronda = Ronda::model()->findByPk($this->_ronda);
         $puntosr = $ronda->puntos;
         if ($tiempo < 0) {
             $tiempo = 0;
         }
         $a = array('tiempo' => $ronda->tiempo + ($nivel->tiempo - $tiempo), 'preguntas' => $this->_preguntan, 'nivel' => $this->_nivel, 'puntos' => $puntosr);
         $ronda->updateByPk($this->_ronda, $a);
     }
     Yii::app()->session['situacion'] = $this->_situacion = $situacion;
     header('Content-Type: application/json; charset="UTF-8"');
     echo CJSON::encode(array('s' => $situacion, 'n' => $this->_nivel, 'pn' => $this->_preguntan, 'pr' => $this->_puntosr, 'pt' => $this->_puntost, 'a' => $this->_ayudas));
     if ($this->_situacion == 6 || $this->_situacion == 4) {
         $this->limpiar_sesion();
     }
     Yii::app()->end();
 }
Example #11
0
<?php

$this->pageCaption = 'Adminsitrar ';
$this->pageTitle = Yii::app()->name . ' - ' . $this->pageCaption;
$this->pageDescription = 'respuestas encuesta';
$this->breadcrumbs = array('Respuestas Encuesta' => array('index'), 'Adminsitrar');
$this->menu = array(array('label' => 'Listar RespuestasEncuesta', 'url' => array('index')), array('label' => 'Crear RespuestasEncuesta', 'url' => array('create')));
$this->widget('bootstrap.widgets.TbGridView', array('id' => 'respuestas-encuesta-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', array('name' => 'encuesta_did', 'value' => '$data->encuesta->nombre', 'filter' => CHtml::listData(Encuesta::model()->findAll(), 'id', 'nombre')), array('name' => 'respuesta_did', 'value' => '$data->respuesta->nombre', 'filter' => CHtml::listData(Respuesta::model()->findAll(), 'id', 'nombre')), 'ip', 'fechaCreacion_f', array('name' => 'estatus_did', 'value' => '$data->estatus->nombre', 'filter' => CHtml::listData(Estatus::model()->findAll(), 'id', 'nombre')), array('class' => 'bootstrap.widgets.TbButtonColumn'))));
 public function actionDelete($id)
 {
     $prx = new PreguntaXRonda();
     $rxj = new RespuestaXJugador();
     $res = new Respuesta();
     $pre = new Pregunta();
     $criteria = new CDbCriteria();
     $criteria->join = 'inner join pregunta p ON respuesta_x_jugador.pregunta_id = p.id';
     $criteria->condition = 'p.id=' . $id;
     $prx->deleteAll("pregunta_id = {$id}");
     $rxj->deleteAll($criteria);
     $res->deleteAll("pregunta_id = {$id}");
     $pre->deleteAll("id = {$id}");
     $log = new Logs();
     try {
         $log->accion = 'Elimino la pregunta id #' . $id . ' como admin';
         $log->usuario = Yii::app()->user->id;
         $log->msg = 'IP: ' . $_SERVER['REMOTE_ADDR'] . ' : ' . $_SERVER['REMOTE_PORT'];
         $log->fecha = date('Y-m-d G:i:s');
         $log->save();
     } catch (Exception $e) {
         $log->accion = 'Error log';
         $log->msg = '';
         $log->fecha = '';
         $log->save();
     }
     $this->redirect(array('index'));
 }
Example #13
0
			
			<?php 
echo $form->dropDownList($model, "encuesta_did", CHtml::listData(Encuesta::model()->findAll(), 'id', 'nombre'));
?>
		</div>
	</div>


	<div class="clearfix">
		<?php 
echo $form->label($model, 'respuesta_did');
?>
		<div class="input">
			
			<?php 
echo $form->dropDownList($model, "respuesta_did", CHtml::listData(Respuesta::model()->findAll(), 'id', 'nombre'));
?>
		</div>
	</div>


	<div class="clearfix">
		<?php 
echo $form->label($model, 'ip');
?>
		<div class="input">
			
			<?php 
echo $form->textField($model, 'ip', array('size' => 20, 'maxlength' => 20, 'class' => 'form-control'));
?>
		</div>
 public function actionRespuesta()
 {
     $this->layout = "single";
     if (!Yii::app()->request->isAjaxRequest) {
         throw new CHttpException('403', 'Forbidden access.');
     }
     $id = Yii::app()->request->restParams['id'];
     // Validar token
     if ($this->validarToken()) {
         if ($this->validarCuentas()) {
             $respuesta = Respuesta::model()->find('id = ?', array(0 => $id));
             $pregunta = Pregunta::model()->find('id = ?', array(0 => $respuesta->pregunta->id));
             $puntos = $respuesta->pregunta->nivel->puntos;
             //$pregunta->estado = 0;
             //$pregunta->save();
             $respuestaJugador = new RespuestaXJugador();
             $log = new Logs();
             $respuestaJugador->pregunta_id = $respuesta->pregunta->id;
             $respuestaJugador->respuesta_id = $id;
             $respuestaJugador->jugador_id = Yii::app()->session['jugador_id'];
             $respuestaJugador->fecha = date('Y-m-d G:i:s');
             $respuestaJugador->ip = $_SERVER['REMOTE_ADDR'] . ' : ' . $_SERVER['REMOTE_PORT'];
             try {
                 if (Yii::app()->user->id) {
                     $jugador = Jugador::model()->find('usuario_id = ' . Yii::app()->user->id);
                     if ($jugador != NULL) {
                         $log->usuario = 'id ' . $jugador->id . ' - ' . $jugador->nombre;
                     } else {
                         $log->usuario = 'id ' . $jugador->id;
                     }
                 }
                 $msg_res = $respuesta->es_correcta == 1 ? 'correcta' : 'incorrecta';
                 $log->accion = 'Contesto Pregunta # ' . $respuesta->pregunta->id;
                 $log->msg = 'IP: ' . $_SERVER['REMOTE_ADDR'] . ' : ' . $_SERVER['REMOTE_PORT'] . '- Contesto "' . $pregunta->pregunta . '"' . '- Su Respuesta fue # ' . $id . '- "' . $respuesta->respuesta . '"' . '- Con respuesta ' . $msg_res;
                 $log->fecha = date('Y-m-d G:i:s');
                 $log->save();
             } catch (Exception $e) {
                 $log->accion = 'Error log';
                 $log->msg = '';
                 $log->fecha = date('Y-m-d G:i:s');
                 $log->save();
             }
             $respuestaJugador->save();
             $respuesta = Respuesta::model()->find('id = ?', array(0 => $id));
             $r = array();
             switch ($respuesta->es_correcta == 1) {
                 case true:
                     // Respuesta correcta , que por ley no se puede informar al usuario.
                     $r['message'] = 'Gracias por participar, recuerda revisar tu perfil al final del día para saber los resultados.';
                     $r['status'] = 'success';
                     break;
                 case false:
                     // Respuesta Incorrecta , que por ley no se puede informar al usuario.
                     $r['message'] = 'Gracias por participar, recuerda revisar tu perfil al final del día para saber los resultados.';
                     /**
                      * formato viejo 
                      **/
                     $r['status'] = 'success';
                     // $r['status']    = 'error';
                     break;
             }
             /** 
              *
              * Formato Viejo , por seguridad ya no se m
              * mandan los puntos al JS.
              **/
             //$r['puntos'] = $puntos;
             $r['puntos'] = 'null';
             $this->clearTokenVal();
         } else {
             $r = array();
             $r['message'] = 'Moral error: No puedes jugar aun.';
             $r['status'] = 'error';
             // Codigo 3 debe estar en el contenido de la base de datos .
             $this->redirect(array('site/contenido', 'id' => 3));
             Yii::app()->end();
         }
     } else {
         $r = array();
         $r['message'] = 'Error , token de seguridad invalido.';
         $r['status'] = 'error';
     }
     header('Content-Type: application/json; charset="UTF-8"');
     echo CJSON::encode($r);
     Yii::app()->end();
 }
Example #15
0
 public function consultaInformativa($columna)
 {
     $data = Respuesta::select(DB::raw("{$columna} as respuesta"))->get();
     return $data;
 }
Example #16
0
 public function Registrar(Respuesta $data)
 {
     try {
         $sql = "INSERT INTO tb_respuesta (intidpregunta,nvchrespuesta,chrvf) \n\t\t        VALUES (?, ?, ?)";
         $this->pdo->prepare($sql)->execute(array($data->__GET('intidpregunta'), $data->__GET('nvchrespuesta'), $data->__GET('chrvf')));
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
 public function addRespuesta($post)
 {
     $respuesta = array('code' => 404, 'message' => 'recurso no encontrado');
     $pregunta_id = strip_tags(htmlspecialchars($post['pregunta']));
     $pregunta_id = intval($pregunta_id);
     $pregunta_id = filter_var($pregunta_id, FILTER_VALIDATE_INT);
     $descripcion = strip_tags(htmlspecialchars($post['post']['descripcion']));
     $session = Utilities::getSession();
     if (is_null($session)) {
         $respuesta['message'] = 'No se encontro alguna sesion activa :s';
     } else {
         if (!$pregunta_id) {
             $respuesta['message'] = 'Pregunta no valiad';
         } else {
             if (strcmp($descripcion, '') == 0) {
                 $respuesta['message'] = 'Debe escribir una respuesta';
             } else {
                 $pregunta = Pregunta::find($pregunta_id);
                 if (count($pregunta) == 0) {
                     $respuesta['message'] = 'La pregunta no existe';
                 } else {
                     $fecha_actual = date('Y-m-d');
                     $reply = new Respuesta();
                     $reply->perfil_id = $session['user_id'];
                     $reply->pregunta_id = $pregunta->pregunta_id;
                     $reply->descripcion = $descripcion;
                     $reply->fechaRespuesta = $fecha_actual;
                     if ($reply->save()) {
                         $respuesta['code'] = 200;
                         $respuesta['message'] = 'Se guardo correctamente';
                         $respuesta['username'] = $session['username'];
                         $respuesta['respuesta'] = $reply;
                     } else {
                         $respuesta['message'] = 'Lo sentimos, no se pudo guardar su respuesta';
                     }
                 }
             }
         }
     }
     return json_encode($respuesta);
 }
Example #18
0
 public function postActualizargrupo()
 {
     $data = Input::all();
     $grupo_id = $data["id"];
     DB::beginTransaction();
     DB::table("grupos")->where('id', $grupo_id)->update(array('nombre' => array_key_exists('titulo', $data) ? $data['titulo'] : "", 'descripcion' => array_key_exists('descripcion', $data) ? $data['descripcion'] : "", 'fb_url' => array_key_exists('fb_url', $data) ? $data['fb_url'] : "", 'region' => array_key_exists('departamento', $data) ? $data['departamento'] : "", 'provincia' => array_key_exists('provincia', $data) ? $data['provincia'] : "", 'distrito' => array_key_exists('distrito', $data) ? $data['distrito'] : "", 'edad_desde' => array_key_exists('edad_desde', $data) ? $data['edad_desde'] : "", 'edad_hasta' => array_key_exists('edad_hasta', $data) ? $data['edad_hasta'] : "", 'sexo' => array_key_exists('sexo', $data) ? $data['sexo'] : ""));
     DB::table("grupo_pregunta")->where('grupo_id', '=', $grupo_id)->delete();
     foreach ($data['preguntas'] as $pre) {
         DB::table("grupo_pregunta")->insert(array("pregunta_id" => $pre['id'], "grupo_id" => $grupo_id, "respuesta" => array_key_exists('respuesta', $pre) ? $pre['respuesta'] : "", "estado" => array_key_exists('estado', $pre) && $pre['estado'] == "true" ? 1 : ""));
     }
     $mensaje = new Mensaje();
     $mensaje->mensaje = array_key_exists('fb_url', $data) ? $data['fb_url'] : "";
     $mensaje->asunto = "Fan Page Actualizado";
     $mensaje->activista_id = Auth::user()->id;
     $mensaje->estado = 1;
     $mensaje->save();
     $respuesta = new Respuesta();
     $respuesta->mensaje_id = $mensaje->id;
     $respuesta->respondido_por = Auth::user()->id;
     $respuesta->respondido_at = date("Y-m-d H:i:s");
     $respuesta->respuesta = $data['titulo'] . ": " . $data['descripcion'];
     $respuesta->estado = 1;
     $respuesta->url = 1;
     $respuesta->save();
     // @todo manejar errores
     $results = array("code" => "ok", "message" => "Datos correctamente guardados");
     DB::commit();
     return Response::json($results);
 }
 function getListaPaginadaJSON($pagina = 0, $rpp = 3, $condicion = "1=1", $parametros = array(), $orderby = "1")
 {
     $pos = $pagina * $rpp;
     $sql = "select * from " . $this->tabla . " where {$condicion} order by {$orderby} limit {$pos}, {$rpp}";
     $this->bd->setConsulta($sql, $parametros);
     $r = "[ ";
     while ($fila = $this->bd->getFila()) {
         $objeto = new Respuesta();
         $objeto->set($fila);
         $r .= $objeto->getJSON() . ",";
     }
     $r = substr($r, 0, -1) . "]";
     return $r;
 }
Example #20
0
 public function actionInsertarRespuesta()
 {
     $comentario = $_POST['respuesta'];
     $id_posteo = $_POST['id_posteo'];
     $usuario = Usuario::model()->findByPk(Yii::app()->user->id);
     $topIdRespuesta;
     //if($id_posteo != null && $id_posteo != "" && $res != null && $res != ""){
     $listaRespuesta = Yii::app()->db->createCommand("select r.id_respuesta from respuesta r where r.id_posteo=" . $id_posteo)->queryAll();
     if ($listaRespuesta != null) {
         foreach ($listaRespuesta as $res) {
             $topIdRespuesta = $res['id_respuesta'];
         }
         $topIdRespuesta++;
     } else {
         $topIdRespuesta = 1;
     }
     $respuesta = new Respuesta();
     $respuesta->id_posteo = $id_posteo;
     $respuesta->id_usuario = $usuario->id_usuario;
     $respuesta->respuesta = $comentario;
     $respuesta->id_respuesta = $topIdRespuesta;
     $respuesta->fhcreacion = new CDbExpression('NOW()');
     $respuesta->cusuario = "juancito";
     $respuesta->save();
     echo "saved";
 }
function TerminarEntrevista()
{
    session_start();
    if (!isset($_SESSION['Usuario'])) {
        Respoder(false, 'Debe iniciar sesión', null);
    }
    if ($_SESSION['Usuario']['tipo'] != 'A') {
        Respoder(false, 'No tiene autorización', null);
    }
    if (!isset($_SESSION['Respondiendo'])) {
        Respoder(false, 'Debe indicar una entrevista', null);
    }
    $Invitacion = $_SESSION['Respondiendo']['Invitacion'];
    $Preguntas = $_SESSION['Respondiendo']['Preguntas'];
    $Respuestas = $_SESSION['Respondiendo']['Respuestas'];
    $video = $_SESSION['Respondiendo']['video'];
    if (count($Respuestas) != count($Preguntas)) {
        Respoder(false, 'Falta responder algunas preguntas', null);
    }
    foreach ($Respuestas as $key => $res) {
        $encontrado = false;
        foreach ($Preguntas as $key => $pre) {
            if ($res['idPregunta'] == $pre['idPregunta']) {
                $encontrado = true;
            }
        }
        if (!$encontrado) {
            Respoder(false, 'Una respuesta no coincide con su pregunta', null);
        }
    }
    $invit = new Invitacion();
    if (!$invit->get('idInvitacion', $Invitacion['idInvitacion'])) {
        Respoder(false, 'No se encontró la invitación', null);
    }
    foreach ($Respuestas as $key => $res) {
        $rpta = new Respuesta();
        $rpta->audio = $res['audio'];
        $rpta->idInvitacion = $invit->idInvitacion;
        $rpta->idPregunta = $res['idPregunta'];
        if (!$rpta->set()) {
            Respoder(false, 'Una respuesta no se guardó', null, $rpta);
        }
    }
    $invit->respondido = true;
    $invit->video = $video;
    $invit->fchRpta = new DateTime();
    if ($invit->edit()) {
        unset($_SESSION['Respondiendo']);
        Respoder(true, 'Entrevista guardada', null);
    } else {
        Respoder(false, 'No se pudo guardar su entrevista', null, $invit);
    }
}
Example #22
0
 public function update()
 {
     $this->preguntasController->listados();
     if (isset($_SESSION["currentuser"])) {
         if (isset($_POST["submit"])) {
             if ($_POST["submit"] == i18n("Modify")) {
                 $respuesta = new Respuesta();
                 if (strlen($_POST["descripcion"]) > 1) {
                     $respuesta->setId($_POST["respuesta"]);
                     $respuesta->setPregunta($_POST["pregunta"]);
                     $respuesta->setDescripcion($_POST["descripcion"]);
                     $respuesta->setUsuario($_SESSION["currentuser"]);
                     $res = $this->respuestaMapper->update($respuesta);
                     $this->view->redirect("preguntas", "index");
                 } else {
                     $errors["general"] = i18n("You can not comment with empty fields");
                     $this->view->setVariable("errors", $errors);
                     $this->view->render("preguntas", "modRespuesta");
                 }
             } else {
                 if ($_POST["submit"] == i18n("Delete")) {
                     $this->respuestaMapper->delete($_POST["respuesta"], $_POST["pregunta"]);
                     $this->view->redirect("preguntas", "index");
                 } else {
                     $this->view->redirect("preguntas", "index");
                 }
             }
         } else {
             $this->view->render("preguntas", "pregunta");
         }
     } else {
         $this->view->setFlash(sprintf(i18n("To ask you have login")));
         $this->view->render("users", "login");
     }
 }