示例#1
0
 public function actionBuscarAjax()
 {
     if (isset($_POST['cedula']) && $_POST['cedula'] != NULL) {
         $cedula = $_POST['cedula'];
         $pdata = PersonaData::model()->findByAttributes(array('cedula' => $cedula));
         if ($pdata != NULL) {
             $persona = Persona::model()->find(array('condition' => 'pd.cedula=' . $cedula, 'join' => 'JOIN persona_data as pd ON t.pdata_id = pd.id'));
             if ($persona != NULL) {
                 echo CJSON::encode(array('value1' => $persona->id, 'value2' => $pdata->nombre, 'value3' => $pdata->profesion_id, 'value4' => $pdata->sexo_id, 'value5' => $persona->dependencia_id, 'value6' => $persona->cargo_id));
             } else {
                 echo CJSON::encode(array('value1' => 0, 'value2' => $pdata->nombre, 'value3' => $pdata->profesion_id, 'value4' => $pdata->sexo_id, 'value5' => 0, 'value6' => 0));
             }
             Yii::app()->end();
         }
     }
     echo CJSON::encode(array('value1' => 0, 'value2' => '', 'value3' => 0, 'value4' => 0, 'value5' => 0, 'value6' => 0));
     Yii::app()->end();
 }
示例#2
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionEliminar($id)
 {
     $eliminadas = 0;
     $fallos = 0;
     $model = PersonaData::model()->findByPk($id);
     $personas = Persona::model()->findAll(array('condition' => 'pdata_id=' . $model->id));
     foreach ($personas as $persona) {
         $existeR = Responsable::model()->exists('persona_id=' . $persona->id);
         $existeT = BmTraspaso::model()->exists('emisor_id=' . $persona->id . ' OR receptor_id=' . $persona->id);
         $existeF = FBm3::model()->exists('observador_id=' . $persona->id);
         if (!$existeR && !$existeT && !$existeF) {
             $persona->delete();
             $eliminadas++;
         } else {
             $fallos++;
         }
     }
     if ($fallos == 0) {
         $model->delete();
         $this->redirect(array('index'));
     } else {
         Yii::app()->user->setFlash('error', 'No puede efectuarse la operación. Existen registros que utilizan este dato.');
         $this->redirect(array('view', 'pid' => $model->id));
     }
 }