Ejemplo n.º 1
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCliente !== null) {
             if (!$this->aCliente->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCliente->getValidationFailures());
             }
         }
         if ($this->aProducto !== null) {
             if (!$this->aProducto->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aProducto->getValidationFailures());
             }
         }
         if (($retval = VentaPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Ejemplo n.º 2
0
 public function actionAjaxSave()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $model = new Cliente();
         $model->attributes = $_POST['Cliente'];
         $modelUsuario = new Usuario();
         $modelUsuario->attributes = $_POST['Usuario'];
         $modelUsuario->tipo_cliente = 0;
         if ($modelUsuario->validate() && $model->validate()) {
             if ($model->save()) {
                 $modelUsuario->cliente_id = $model->id;
                 if ($modelUsuario->save()) {
                     Yii::app()->session['id-cliente'] = $model->id;
                     echo true;
                 }
             }
         } else {
             echo false;
         }
         Yii::app()->end();
     } else {
         throw new CHttpException(400);
     }
 }
Ejemplo n.º 3
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggregated array of ValidationFailed objects will be returned.
  *
  * @param array $columns Array of column names to validate.
  * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCliente !== null) {
             if (!$this->aCliente->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCliente->getValidationFailures());
             }
         }
         if ($this->aProveedorcliente !== null) {
             if (!$this->aProveedorcliente->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aProveedorcliente->getValidationFailures());
             }
         }
         if (($retval = ExpedientePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collExpedienteanticipos !== null) {
             foreach ($this->collExpedienteanticipos as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collExpedientearchivos !== null) {
             foreach ($this->collExpedientearchivos as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collExpedientegastos !== null) {
             foreach ($this->collExpedientegastos as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collExpedienteservicios !== null) {
             foreach ($this->collExpedienteservicios as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Ejemplo n.º 4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Cliente();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Cliente'])) {
         $model->attributes = $_POST['Cliente'];
         $model->direccion_alternativa = $_POST['Cliente']['direccion_alternativa'];
         $usuario = new Usuario();
         $model->rut = Tools::removeDots($model->rut);
         $usuario->user = $model->rut;
         $arr = explode("-", $model->rut);
         $usuario->clave = CPasswordHelper::hashPassword($arr[0]);
         $usuario->rol = "cliente";
         $usuario->nombre = $_POST['Cliente']['nombre'];
         $usuario->email = $_POST['Cliente']['email'];
         $usuario->apellido = $_POST['Cliente']['apellido'];
         $model->usuario_id = 1;
         if ($model->validate()) {
             if ($usuario->validate()) {
                 if ($usuario->save()) {
                     $model->usuario_id = $usuario->id;
                     if ($model->save()) {
                         $ok = false;
                         $auth = Yii::app()->authManager;
                         Authassignment::model()->deleteAllByAttributes(array('userid' => $usuario->id));
                         $auth->revoke($usuario->rol, $model->usuario_id);
                         $auth->assign($usuario->rol, $model->usuario_id);
                         $fiador = new Fiador();
                         if (isset($_POST['Cliente']['fiador_rut'])) {
                             if (isset($_POST['Cliente']['fiador_rut'])) {
                                 $fiador->rut = $_POST['Cliente']['fiador_rut'];
                                 $fiador->rut = Tools::removeDots($fiador->rut);
                                 $fiador->nombre = $_POST['Cliente']['fiador_nombre'];
                                 $fiador->apellido = $_POST['Cliente']['fiador_apellido'];
                                 $fiador->email = $_POST['Cliente']['fiador_email'];
                                 $fiador->telefono = $_POST['Cliente']['fiador_telefono'];
                                 $fiador->direccion = $_POST['Cliente']['fiador_direccion'];
                                 if ($fiador->validate()) {
                                     if ($fiador->save()) {
                                         $ok = true;
                                     }
                                 } else {
                                     echo "<br>";
                                     echo CHtml::errorSummary($fiador);
                                 }
                             }
                         }
                         if ($ok) {
                             $cliente_fiador = new ClienteFiador();
                             $cliente_fiador->cliente_id = $model->id;
                             $cliente_fiador->fiador_id = $fiador->id;
                             $cliente_fiador->save();
                         }
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 }
             } else {
                 echo "<br>";
                 echo CHtml::errorSummary($usuario);
             }
         } else {
             echo "<br>";
             echo CHtml::errorSummary($model);
         }
     }
     $this->render('create', array('model' => $model));
 }