Example #1
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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = BmTraspaso::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #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));
     }
 }