Пример #1
0
 /**
  * Updates an existing Cals model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsCalitems = $model->calitem;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $oldIDs = ArrayHelper::map($modelsCalitems, 'id', 'id');
         $modelsCalitems = Model::createMultiple(Calitems::classname(), $modelsCalitems);
         Model::loadMultiple($modelsCalitems, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsCalitems, 'id', 'id')));
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsCalitems) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Calitems::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsCalitems as $modelCalitems) {
                         $modelCalitems->cal_id = $model->id;
                         if (!($flag = $modelCalitems->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('update', ['model' => $model, 'modelsCalitems' => empty($modelsCalitems) ? [new Calitems()] : $modelsCalitems]);
     }
 }
Пример #2
0
 public function actionUpdateD($id)
 {
     $modelTransaksi = $this->findModel($id);
     $modelsTransaksiItem = $modelTransaksi->addresses;
     if ($modelTransaksi->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsTransaksiItem, 'id', 'id');
         $modelsTransaksiItem = Model::createMultiple(TransaksiItem::classname(), $modelsTransaksiItem);
         Model::loadMultiple($modelsTransaksiItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsTransaksiItem, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsTransaksiItem), ActiveForm::validate($modelTransaksi));
         }
         // validate all models
         $valid = $modelTransaksi->validate();
         $valid = Model::validateMultiple($modelsTransaksiItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelTransaksi->save(false)) {
                     if (!empty($deletedIDs)) {
                         TransaksiItem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsTransaksiItem as $modelAddress) {
                         $modelAddress->customer_id = $modelTransaksi->id;
                         if (!($flag = $modelAddress->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelTransaksi->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('_formD', ['modelTransaksi' => $modelTransaksi, 'modelsTransaksiItem' => empty($modelsTransaksiItem) ? [new Address()] : $modelsTransaksiItem]);
 }
 /**
  * Creates a new Curriculos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = 'main-curriculos';
     $model = new Curriculos();
     $curriculosEndereco = new CurriculosEndereco();
     $curriculosFormacao = new CurriculosFormacao();
     $modelsComplemento = [new CurriculosComplemento()];
     $modelsEmpregos = [new CurriculosEmpregos()];
     if (isset($_COOKIE['PHPSESSID']) && !empty($_COOKIE['PHPSESSID'])) {
         session_id($_COOKIE['PHPSESSID']);
     }
     session_start();
     //session numero de edital e do id do processo
     $session = Yii::$app->session;
     $model->edital = $session["numeroEdital"];
     $id = $session["id"];
     $model->data = date('Y-m-d H:i:s');
     //NÚMERO DE INSCRIÇÃO 'ANO CORRENTE + 000000 + ID DO CANDIDATO'
     $query_id = "SELECT max(id) as id FROM curriculos LIMIT 1";
     $last_id = Curriculos::findBySql($query_id)->all();
     foreach ($last_id as $value) {
         $incremento = $value['id'];
         $incremento++;
     }
     $model->numeroInscricao = date('Y') . '00000' . $incremento;
     $curriculosEndereco->curriculos_id = $incremento;
     $curriculosFormacao->curriculos_id = $incremento;
     //localizando somente os cargos que fazem parte do edital selecionado
     $cargos = Cargos::find()->innerJoinWith('cargosProcessos')->where(['processo_id' => $id])->AndWhere('cargo_id = idcargo')->all();
     //Caso não tenha puxado nenhum edital, será redirecionado para a página de processo seletivo
     if ($model->edital == NULL) {
         return $this->redirect('http://www.am.senac.br/trabsenac.php');
     }
     if ($model->load(Yii::$app->request->post()) && $curriculosEndereco->load(Yii::$app->request->post()) && $curriculosFormacao->load(Yii::$app->request->post()) && Model::validateMultiple([$model, $curriculosEndereco, $curriculosFormacao])) {
         //Calcular a idade do candidato
         $datetime1 = new \DateTime($model->datanascimento, new \DateTimeZone('UTC'));
         $datetime2 = new \DateTime();
         $diff = $datetime1->diff($datetime2);
         $model->idade = $diff->y;
         $model->save(false);
         // skip validation as model is already validated
         $curriculosEndereco->curriculos_id = $model->id;
         $curriculosFormacao->curriculos_id = $model->id;
         $curriculosEndereco->save(false);
         $curriculosFormacao->save(false);
         //ENVIA E-MAIL DA INSCRIÇÃO PARA O CANDIDATO
         Yii::$app->mailer->compose()->setFrom(['*****@*****.**' => 'Processo Seletivo - Senac AM'])->setTo($model->email)->setSubject('Inscrição para o Edital: ' . $model->edital)->setTextBody('Prezado Candidato, confirmamos o envio de seu currículo para concorrer a vaga de ' . $model->cargo . ' para o Edital ' . $model->edital . ' ')->setHtmlBody("Prezado Senhor(a), <strong>" . $model->nome . "</strong><br><br>" . "Recebemos a sua inscrição em nosso processo de seleção com sucesso para o Edital: <strong>" . $model->edital . " </strong>e pedimos que acompanhe em nosso site o resultado das próximas etapas.<br><br>" . "<strong><font color='red'><center>NÃO RESPONDA A ESSE E-MAIL!!!!</center></font></strong><br><br>" . "<strong>INFORMAÇÕES GERAIS</STRONG><br><br>" . "<strong>Número de Inscrição: </strong><font color='red'>" . $model->numeroInscricao . "</font><br><br>" . "<strong>Data do envio: </strong> " . $model->data . "<br>" . "<strong>Processo Seletivo: </strong> " . $model->edital . "<br>" . "<strong>Cargo: </strong> " . $model->cargo . "<br><br>")->send();
         //Inserir vários cursos complementares
         $modelsComplemento = Model::createMultiple(CurriculosComplemento::classname());
         Model::loadMultiple($modelsComplemento, Yii::$app->request->post());
         //Inserir vários emprgos anteriores
         $modelsEmpregos = Model::createMultiple(CurriculosEmpregos::classname());
         Model::loadMultiple($modelsEmpregos, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsComplemento) && $valid;
         $valid2 = $model->validate();
         $valid_empregos = Model::validateMultiple($modelsEmpregos) && $valid2;
         if ($valid && $valid_empregos) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsComplemento as $modelComplemento) {
                         //cursos complementares
                         $modelComplemento->curriculos_id = $model->id;
                         if (!($flag = $modelComplemento->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     foreach ($modelsEmpregos as $modelEmpregos) {
                         //empregos anteriores
                         $modelEmpregos->curriculos_id = $model->id;
                         if (!($flag = $modelEmpregos->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect('http://www.am.senac.br/trabsenac_success.php');
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect('http://www.am.senac.br/trabsenac_success.php');
     } else {
         return $this->render('create', ['model' => $model, 'cargos' => $cargos, 'curriculosEndereco' => $curriculosEndereco, 'curriculosFormacao' => $curriculosFormacao, 'modelsComplemento' => empty($modelsComplemento) ? [new CurriculosComplemento()] : $modelsComplemento, 'modelsEmpregos' => empty($modelsEmpregos) ? [new CurriculosEmpregos()] : $modelsEmpregos]);
     }
 }
 /**
  * Updates an existing Tour model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsCustomField = $model->customFields;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsCustomField, 'id', 'id');
         $modelsCustomField = Model::createMultiple(CustomField::classname(), $modelsCustomField);
         Model::loadMultiple($modelsCustomField, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsCustomField, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsCustomField), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsCustomField) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         CustomField::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsCustomField as $modelCustomField) {
                         $modelCustomField->tour_id = $model->id;
                         if (!($flag = $modelCustomField->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsCustomField' => empty($modelsCustomField) ? [new CustomField()] : $modelsCustomField]);
 }
Пример #5
0
 /**
  * Updates an existing Purchase model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelDetails = $model->getPurchasesDetails()->all();
     if ($model->load(Yii::$app->request->post())) {
         $oldModelDetails = array();
         foreach ($modelDetails as $modelDetail) {
             $oldModelDetails[$modelDetail->id] = ['item_id' => $modelDetail->item_id, 'quantity' => $modelDetail->quantity];
         }
         $oldIDs = ArrayHelper::map($modelDetails, 'id', 'id');
         $modelDetails = Model::createMultiple(PurchaseDetail::classname(), $modelDetails);
         Model::loadMultiple($modelDetails, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelDetails, 'id', 'id')));
         // validate all models
         $valid = $model->validate() & Model::validateMultiple($modelDetails);
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         $flag = PurchaseDetail::deleteAll(['id' => $deletedIDs]) > 0;
                         if ($flag) {
                             foreach ($deletedIDs as $id) {
                                 $item = Item::findOne($oldModelDetails[$id]['item_id']);
                                 $item->stock -= $oldModelDetails[$id]['quantity'];
                                 if (!($flag = $item->save())) {
                                     $transaction->rollBack();
                                     break;
                                 }
                             }
                         } else {
                             $transaction->rollBack();
                         }
                     }
                     if ($flag) {
                         foreach ($modelDetails as $modelDetail) {
                             $quantity = $modelDetail->quantity;
                             if (!empty($modelDetail->id) && $modelDetail->item_id == $oldModelDetails[$modelDetail->id]['item_id']) {
                                 $quantity -= $oldModelDetails[$modelDetail->id]['quantity'];
                             }
                             $modelDetail->purchase_id = $model->id;
                             if (($flag = $modelDetail->save(false)) && $quantity !== 0) {
                                 $item = Item::findOne($modelDetail->item_id);
                                 $item->stock += $quantity;
                                 $flag = $item->save();
                             }
                             if (!$flag) {
                                 $transaction->rollBack();
                                 break;
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelDetails' => empty($modelDetails) ? [new PurchaseDetail()] : $modelDetails]);
 }
Пример #6
0
 /**
  * Updates an existing RceExamen model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsPago = $model->pagos;
     $modelsBitacora = $model->bitacoras;
     $modelsExamenes = $model->rceExamenExamens;
     foreach ($modelsExamenes as $modelExamen) {
         $examen = Examen::find()->where(['id' => $modelExamen->examen_id])->one();
         $modelExamen->descripcion = $examen->descripcion;
         $modelExamen->observaciones = $examen->observaciones;
     }
     if ($model->load(Yii::$app->request->post())) {
         $oldIDsPago = ArrayHelper::map($modelsPago, 'id', 'id');
         $modelsPago = Model::createMultiple(Pago::classname(), $modelsPago);
         Model::loadMultiple($modelsPago, Yii::$app->request->post());
         $deletedIDsPago = array_diff($oldIDsPago, array_filter(ArrayHelper::map($modelsPago, 'id', 'id')));
         $oldIDsExamen = ArrayHelper::map($modelsExamenes, 'id', 'id');
         $modelsExamenes = Model::createMultiple(Examen::classname(), $modelsExamenes);
         Model::loadMultiple($modelsExamenes, Yii::$app->request->post());
         $deletedIDsExamen = array_diff($oldIDsExamen, array_filter(ArrayHelper::map($modelsExamenes, 'id', 'id')));
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPago) && $valid;
         $valid = Model::validateMultiple($modelsBitacora) && $valid;
         $valid = Model::validateMultiple($modelsExamenes) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDsPago)) {
                         Pago::deleteAll(['id' => $deletedIDsPago]);
                     } else {
                         if (!empty($deletedIDsBitacora)) {
                             Bitacora::deleteAll(['id' => $deletedIDsBitacora]);
                         } else {
                             if (!empty($deletedIDsREE)) {
                                 RceExamenExamen::deleteAll(['id' => $deletedIDsREE]);
                             }
                         }
                     }
                     foreach ($modelsPago as $modelPago) {
                         $modelPago->rce_examen_id = $model->id;
                         if (!($flag = $modelPago->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     foreach ($modelsBitacora as $modelBitacora) {
                         $modelBitacora->rce_examen_id = $model->id;
                         if (!($flag = $modelBitacora->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     $reserva = Reserva::find()->where(['id' => $model->reserva_id])->one();
                     $hora = Hora::find()->where(['id' => $reserva->hora_medica_id])->one();
                     $examenes = HoraExamenSolicitado::find()->where(['hora_id' => $hora->id])->all();
                     for ($i = 0; $i < count($examenes); ++$i) {
                         $examen = Examen::find()->where(['id' => $examenes[$i]->examen_id])->one();
                         $modelsExamenes[$i] = new RceExamenExamen();
                         $modelsExamenes[$i]->rce_examen_id = $model->id;
                         $modelsExamenes[$i]->examen_id = $examenes[$i]->examen_id;
                         $modelsExamenes[$i]->monto_a_pagar = $examen->monto;
                         if (!($flag = $modelsExamenes[$i]->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsPago' => empty($modelsPago) ? [new Pago()] : $modelsPago, 'modelsBitacora' => empty($modelsBitacora) ? [new Bitacora()] : $modelsBitacora, 'modelsExamenes' => empty($modelsExamenes) ? [new RceExamenExamen()] : $modelsExamenes]);
 }
Пример #7
0
 /**
  * Updates an existing Client model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $modelClient = Client::findOne($id);
     $modelsOrder = Order::findAll(['id_client' => $modelClient->id]);
     if (Yii::$app->request->post() && $modelClient->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsOrder, 'id', 'id');
         $modelsOrder = Model::createMultiple(Order::classname(), $modelsOrder);
         Model::loadMultiple($modelsOrder, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsOrder, 'id', 'id')));
         // validate all models
         $valid = $modelClient->validate();
         $valid = Model::validateMultiple($modelsOrder) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelClient->save(false)) {
                     if (!empty($deletedIDs)) {
                         Order::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsOrder as $modelOrder) {
                         $modelOrder->id_client = $modelClient->id;
                         if (!($flag = $modelOrder->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelClient->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['modelClient' => $modelClient, 'modelsOrder' => empty($modelsOrder) ? [new Order()] : $modelsOrder]);
 }
 /**
  * Updates an existing Monitoring1 model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsStr = $model->mon1str;
     if (!Yii::$app->user->can('admin')) {
         if ($model->user_id != Yii::$app->user->id) {
             $this->redirect(['index']);
         }
     }
     if (!Yii::$app->user->can('admin')) {
         if ($model->status == 1) {
             $this->redirect(['index']);
         }
     }
     $months = Month::find()->all();
     $years = Year::find()->all();
     //        $model->user_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post())) {
         $model->date = date('Y-m-d', strtotime($model->date));
         if (!Monitoring1::find()->where(['date' => $model->date, 'user_id' => Yii::$app->user->id])->one()) {
             if ($model->save()) {
                 $oldIDs = ArrayHelper::map($modelsStr, 'id', 'id');
                 $modelsStr = Model::createMultiple(Mon1str::classname(), $modelsStr);
                 Model::loadMultiple($modelsStr, Yii::$app->request->post());
                 $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsStr, 'id', 'id')));
                 // ajax validation
                 if (Yii::$app->request->isAjax) {
                     Yii::$app->response->format = Response::FORMAT_JSON;
                     return ArrayHelper::merge(ActiveForm::validateMultiple($modelsStr), ActiveForm::validate($model));
                 }
                 // validate all models
                 $valid = $model->validate();
                 $valid = Model::validateMultiple($modelsStr) && $valid;
                 if ($valid) {
                     $transaction = \Yii::$app->db->beginTransaction();
                     try {
                         if ($flag = $model->save(false)) {
                             if (!empty($deletedIDs)) {
                                 Mon1str::deleteAll(['id' => $deletedIDs]);
                             }
                             foreach ($modelsStr as $modelStr) {
                                 $modelStr->monitoring1_id = $model->id;
                                 if (!($flag = $modelStr->save(false))) {
                                     $transaction->rollBack();
                                     break;
                                 }
                             }
                         }
                         if ($flag) {
                             $transaction->commit();
                             return $this->redirect(['view', 'id' => $model->id]);
                         }
                     } catch (Exception $e) {
                         $transaction->rollBack();
                     }
                 }
             }
         }
     }
     return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years, 'modelsStr' => empty($modelsStr) ? [new Mon1str()] : $modelsStr]);
 }
Пример #9
0
 /**
  * Updates an existing Reserva model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelHora = $model->horaMedica;
     $modelsExamen = $modelHora->horaExamenSolicitados;
     if ($model->load(Yii::$app->request->post()) && $modelHora->load(Yii::$app->request->post())) {
         $oldIDHora = ArrayHelper::map($modelHora, 'id', 'id');
         $modelHora = new Hora();
         Model::load($modelHora, Yii::$app->request->post());
         $deletedIDHora = array_diff($oldIDHora, array_filter(ArrayHelper::map($modelHora, 'id', 'id')));
         $oldIDsExamen = ArrayHelper::map($modelsExamen, 'id', 'id');
         $modelsExamen = Model::createMultiple(Pago::classname(), $modelsExamen);
         Model::loadMultiple($modelsExamen, Yii::$app->request->post());
         $deletedIDsExamen = array_diff($oldIDsExamen, array_filter(ArrayHelper::map($modelsExamen, 'id', 'id')));
         $valid = $model->validate();
         $valid = $modelHora->validate();
         $valid = Model::validateMultiple($modelsExamen) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDHora)) {
                         Hora::deleteAll(['id' => $deletedIDHora]);
                     } else {
                         if (!empty($deletedIDsExamen)) {
                             HoraExamenSolicitado::deleteAll(['id' => $deletedIDsExamen]);
                         }
                     }
                     foreach ($modelsExamen as $modelExamen) {
                         $modelExamen->hora_id = $model->hora_medica_id;
                         if (!($flag = $modelExamen->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelHora' => $modelHora, 'modelsExamen' => empty($modelsExamen) ? [new HoraExamenSolicitado()] : $modelsExamen]);
 }
Пример #10
0
 /**
  * Updates an existing Subscriber model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsPhone = $model->phones;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsPhone, 'id', 'id');
         $modelsPhone = Model::createMultiple(Phone::classname(), $modelsPhone);
         Model::loadMultiple($modelsPhone, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPhone, 'id', 'id')));
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPhone) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Phone::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsPhone as $modelPhone) {
                         $modelPhone->subscriber_id = $model->id;
                         if (!($flag = $modelPhone->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsPhone' => empty($modelsPhone) ? [new Phone()] : $modelsPhone]);
 }
Пример #11
0
 /**
  * Updates an existing Usuario model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $user = new Usuario();
     $user = $this->findModel($id);
     $modelsConocimientos = $user->conocimientos;
     $modelsConocimientos = Conocimiento::find()->where(['id_conocimiento' => $user->id_usuario])->all();
     $institucion = ArrayHelper::map(Institucion::find()->all(), 'id_institucion', 'nombre');
     $cont = Contacto::find()->where(['id_contacto' => $user->id_usuario])->one();
     $dir = Direccion::find()->where(['id_direccion' => $user->id_usuario])->one();
     $repr = Representante::find()->where(['id_representante' => $user->id_usuario])->one();
     if ($user->load(Yii::$app->request->post()) && $cont->load(Yii::$app->request->post()) && $dir->load(Yii::$app->request->post()) && $repr->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsConocimientos, 'id', 'id');
         $modelsConocimientos = Model::createMultiple(Conocimiento::classname(), $modelsConocimientos);
         Model::loadMultiple($modelsConocimientos, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsConocimientos, 'id_conocimiento', 'id_conocimiento')));
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsConocimientos), ActiveForm::validate($user));
         }
         // validate all models
         $valid = $user->validate();
         $valid = Model::validateMultiple($modelsConocimientos) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $user->save(false)) {
                     if (!empty($deletedIDs)) {
                         Conocimiento::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsConocimientos as $modelConocimientos) {
                         $modelConocimientos->Usuarioid_usuario = $user->id_usuario;
                         if (!($flag = $modelConocimientos->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $user->id_usuario]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         if ($repr->save() && $cont->save() && $dir->save()) {
             return $this->redirect(['view', 'id' => $user->id_usuario]);
         } else {
             return $this->redirect(['index', 'id' => $user->id_usuario]);
         }
     } else {
         return $this->render('update', ['user' => $user, 'cont' => $cont, 'dir' => $dir, 'repr' => $repr, 'institucion' => $institucion, 'modelsConocimientos' => empty($modelsConocimientos) ? [new Conocimiento()] : $modelsConocimientos]);
     }
 }