/** * Updates an existing Po 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); $countPoItems = PoItem::find()->where(['po_id' => $id])->count(); $modelsPoItem = PoItem::find()->where(['po_id' => $id])->all(); if ($model->load(Yii::$app->request->post())) { // $model->save(); $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { PoItem::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'modelsPoItem' => $modelsPoItem]); } }
public function actionCreate() { $model = new Po(); $modelsPoItem = [new PoItem()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modelsPoItem = Model::createMultiple(PoItem::classname()); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->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('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); } }
/** * Creates a new Matricula model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Matricula(); $modeldetallemat = [new Detallemat()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modeldetallemat = Model::createMultiple(Detallemat::classname()); Model::loadMultiple($modeldetallemat, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modeldetallemat) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modeldetallemat as $modeldetallemat) { $modeldetallemat->idMatricula = $model->idMatricula; if (!($flag = $modeldetallemat->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->idMatricula]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->idMatricula]); } else { return $this->render('create', ['model' => $model, 'modeldetallemat' => empty($modeldetallemat) ? [new Detallemat()] : $modeldetallemat]); } }
/** * Creates a new Prerrequisito model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Prerrequisito(); $modelsDetallepre = [new Detallepre()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $modelsDetallepre = Model::createMultiple(Detallepre::classname()); Model::loadMultiple($modelsDetallepre, Yii::$app->request->post()); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsDetallepre) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { foreach ($modelsDetallepre as $modelsDetallepre) { $modelsDetallepre->idPrerreq = $model->idPrerreq; if (!($flag = $modelsDetallepre->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->idPrerreq]); } } catch (Exception $e) { $transaction->rollBack(); } } return $this->redirect(['view', 'id' => $model->idPrerreq]); } else { return $this->render('create', ['model' => $model, 'modelsDetallepre' => empty($modelsDetallepre) ? [new Detallepre()] : $modelsDetallepre]); } }
/** * Creates a new Po model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Po(); $modelsPoItem = [new PoItem()]; if ($model->load(Yii::$app->request->post()) && $model->save()) { $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem); echo PoItem::classname(); echo '<pre>'; print_r($modelsPoItem); print_r($oldIDs); echo '</pre>'; die; Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // ajax validation // if (Yii::$app->request->isAjax) { // Yii::$app->response->format = Response::FORMAT_JSON; // return ArrayHelper::merge( // ActiveForm::validateMultiple($modelsPoItem), // ActiveForm::validate($modelCustomer) // ); // } // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; // echo '<pre>'; // print_r($valid); // echo '</pre>'; // die(); if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { PoItem::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->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('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); } }
/** * Updates an existing Po 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); $modelsPoItem = $model->poItems; if ($model->load(Yii::$app->request->post())) { $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id'); $modelsPoItem = Model::createMultiple(Address::classname(), $modelsPoItem); Model::loadMultiple($modelsPoItem, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id'))); // ajax validation /*if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ArrayHelper::merge( ActiveForm::validateMultiple($modelsPoItem), ActiveForm::validate($model) ); }*/ // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsPoItem) && $valid; if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { Address::deleteAll(['id' => $deletedIDs]); } foreach ($modelsPoItem as $modelPoItem) { $modelPoItem->po_id = $model->id; if (!($flag = $modelPoItem->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, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]); }
/** * Updates an existing Booths 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); $modelsBoothSchedules = $model->boothSchedules; if ($model->load(Yii::$app->request->post())) { //Load data from post $oldIDs = ArrayHelper::map($modelsBoothSchedules, 'id', 'id'); $modelsBoothSchedules = Model::createMultiple(BoothSchedules::classname(), $modelsBoothSchedules); Model::loadMultiple($modelsBoothSchedules, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsBoothSchedules, 'id', 'id'))); $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d'); // validate all models $valid = $model->validate(); if ($valid || !$valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { BoothSchedules::deleteAll(['id' => $deletedIDs]); } foreach ($modelsBoothSchedules as $modelBoothSchedule) { if (!empty($modelBoothSchedule->attendee_id)) { $attendeeDetails = $modelBoothSchedule->attendee; if (empty($modelBoothSchedule->booth_id)) { $modelBoothSchedule->booth_id = $model->id; //Below two lines can be removed $modelBoothSchedule->function_id = $attendeeDetails->function_Id; $modelBoothSchedule->cost_center_id = $attendeeDetails->group_Id; $modelBoothSchedule->isNewRecord = true; } $flag = $modelBoothSchedule->save(false); if (!$flag) { //If data is not saved then rollback the transaction and break the loop $transaction->rollBack(); break; } } } } if ($flag) { //If data is not saved then rollback the transaction and redirect to view page $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (\Exception $e) { $transaction->rollBack(); } } } else { //Booth date should be between congress start date and end date $congressDetail = CongressDetails::findOne($model->congress_id); $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y'); $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y'); return $this->render('update', ['model' => $model, 'modelsBoothSchedules' => empty($modelsBoothSchedules) ? [new BoothSchedules()] : $modelsBoothSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]); } }
/** * Updates an existing Comunicado 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); $modelsContactos = $model->comunicadosContactos; $vista = \common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id); if ($model->load(Yii::$app->request->post())) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'ccontactos_id', 'ccontactos_id'); $modelsContactos = Model::createMultipleccontacto(ComunicadosContactos::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'ccontactos_id', 'ccontactos_id'))); // validate all models $valid = $model->validate(); // Debido a que el campo dependenciaid no se captura ( y es un campo obligatorio) $valid = Model::validateMultiple($modelsContactos, ['nombre', 'cargo', 'telefono', 'correo']) && $valid; // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { ComunicadosContactos::deleteAll(['ccontactos_id' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->dependenciaid = $model->dependencia_id; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect([\common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id), 'id' => $model->tipocomunicado_id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { if ($vista == 'gobierno-federal') { return $this->render('update-gob', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'embajadas') { return $this->render('update-embajada', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'gdf') { return $this->render('update-gdf', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'estatales') { return $this->render('update-estatales', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'partidos-politicos') { return $this->render('update-ppoliticos', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } elseif ($vista == 'delegaciones') { return $this->render('update-delegacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]); } } }
/** * Updates an existing MeetingDetails 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); $modelMeetingSchedules = $model->meetingSchedules; if ($model->load(Yii::$app->request->post())) { $oldIDs = ArrayHelper::map($modelMeetingSchedules, 'id', 'id'); $modelMeetingSchedules = Model::createMultiple(MeetingSchedules::classname(), $modelMeetingSchedules); Model::loadMultiple($modelMeetingSchedules, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelMeetingSchedules, 'id', 'id'))); // ajax validation if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ArrayHelper::merge(ActiveForm::validateMultiple($modelMeetingSchedules), ActiveForm::validate($model)); } $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d'); // validate all models $valid = $model->validate(); if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { MeetingSchedules::deleteAll(['id' => $deletedIDs]); } foreach ($modelMeetingSchedules as $modelMeetingSchedule) { if (empty($modelMeetingSchedule->congress_id)) { $modelMeetingSchedule->meeting_id = $model->id; $modelMeetingSchedule->congress_id = $model->congress_id; $modelMeetingSchedule->isNewRecord = true; } if ($modelMeetingSchedule->attendee_id > 0 || $modelMeetingSchedule->ol_attendee_id > 0) { $flag = $modelMeetingSchedule->save(false); } } $postData = \Yii::$app->request->post(); $olAttendeeData = isset($postData['OlAttendees']) ? $postData['OlAttendees'] : []; foreach ($olAttendeeData as $olAttendeeInfo) { // print_r($olAttendeeInfo); if (!empty($olAttendeeInfo['name']) && (!isset($olAttendeeInfo['id']) || empty($olAttendeeInfo['id']))) { $olAttendeeModel = new \backend\models\OlAttendees(); $olAttendeeModel->user_type_id = 1; $parts = explode(" ", $olAttendeeInfo['name']); $lastname = array_pop($parts); $firstname = implode(" ", $parts); $olAttendeeModel->first_name = $firstname; $olAttendeeModel->last_name = $lastname; $olAttendeeModel->name = $olAttendeeInfo['name']; $olAttendeeModel->ol_bio = $olAttendeeInfo['ol_bio']; $olAttendeeModel->ol_phone_no = $olAttendeeInfo['ol_phone_no']; $olAttendeeModel->ol_email = $olAttendeeInfo['ol_email']; $olAttendeeModel->is_active = 1; $olAttendeeModel->isNewRecord = true; if ($olAttendeeModel->validate()) { if ($flag = $olAttendeeModel->save(false)) { $olAttendeeId = $olAttendeeModel->id; $meetingScheduleModel = new MeetingSchedules(); $meetingScheduleModel->meeting_id = $model->id; $meetingScheduleModel->congress_id = $model->congress_id; $meetingScheduleModel->ol_attendee_id = $olAttendeeId; $meetingScheduleModel->isNewRecord = true; $flag = $meetingScheduleModel->save(false); if (!$flag) { $transaction->rollBack(); break; } } } } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (\Exception $e) { $transaction->rollBack(); } } } else { //Meeting date should be between congress start date and end date $congressDetail = CongressDetails::findOne($model->congress_id); $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y'); $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y'); return $this->render('update', ['model' => $model, 'modelMeetingSchedules' => empty($modelMeetingSchedules) ? [new MeetingSchedules()] : $modelMeetingSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]); } }
/** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); }
/** * Updates an existing Proveedores 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); $modelsContactos = $model->proveedoresContactos; if ($model->load(Yii::$app->request->post())) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'pcontacto_id', 'pcontacto_id'); $modelsContactos = Model::createMultiplepcontacto(ProveedoresContacto::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'pcontacto_id', 'pcontacto_id'))); // validate all models $valid = $model->validate(); // Debido a que el campo dependenciaid no se captura ( y es un campo obligatorio) $valid = Model::validateMultiple($modelsContactos, ['nombre', 'apellido', 'telefono', 'celular', 'email']) && $valid; // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { ProveedoresContacto::deleteAll(['pcontacto_id' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->proveedorid = $model->proveedor_id; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); return $this->redirect(['index']); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('update', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ProveedoresContacto()] : $modelsContactos]); } }
/** * Updates an existing Sda 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); $modelsSdaSchedules = $model->sdaSchedules; if ($model->load(Yii::$app->request->post())) { $oldIDs = ArrayHelper::map($modelsSdaSchedules, 'id', 'id'); $modelsSdaSchedules = Model::createMultiple(SdaSchedules::classname(), $modelsSdaSchedules); Model::loadMultiple($modelsSdaSchedules, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsSdaSchedules, 'id', 'id'))); // ajax validation if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ArrayHelper::merge(ActiveForm::validateMultiple($modelsSdaSchedules), ActiveForm::validate($model)); } $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d'); // validate all models $valid = $model->validate(); if ($valid || !$valid) { //change condition for update without being validate $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { SdaSchedules::deleteAll(['id' => $deletedIDs]); } foreach ($modelsSdaSchedules as $modelSdaSchedule) { if (!empty($modelSdaSchedule->attendee_id)) { if (empty($modelSdaSchedule->congress_id)) { $modelSdaSchedule->sda_id = $model->id; $modelSdaSchedule->congress_id = $model->congress_id; $modelSdaSchedule->assigned = 0; $modelSdaSchedule->isNewRecord = true; } $flag = $modelSdaSchedule->save(false); if (!$flag) { $transaction->rollBack(); break; } } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { $congressDetail = CongressDetails::findOne($model->congress_id); $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y'); $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y'); return $this->render('update', ['model' => $model, 'modelsSdaSchedules' => empty($modelsSdaSchedules) ? [new SdaSchedules()] : $modelsSdaSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]); } }
/** * Updates an existing Cuentas 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); $modelsContactos = $model->contactos; $vista = \common\models\Refactor::TipoCuentabyVista($model->tipocuenta_id); if ($model->load(Yii::$app->request->post()) && $model->save()) { // Lista todos los contactos $oldIDs = ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid'); $modelsContactos = Model::createMultiple(Contactos::classname(), $modelsContactos); Model::loadMultiple($modelsContactos, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid'))); // validate all models $valid = $model->validate(); $valid = Model::validateMultiple($modelsContactos) && $valid; // Obteniendo el archivo que se subió. /* FUNCIONA CORRECTAMENTE PERO ES PARA MOSTRAR Y GUARDAR UN SOLO ARCHIVO, EL CODIGO UTILIZADO ES PARA VARIOS ARCHIVOS $model->archivo = UploadedFile::getInstance($model, 'archivo'); if ($model->archivo && $model->validate()) { if ($model->docto_propuesta && file_exists(Yii::$app->basePath.'/web/'.$model->docto_propuesta)) { unlink(Yii::$app->basePath.'/web/'.$model->docto_propuesta); } $nombreImagen = $model->cuenta .'-'.date('Ymd-His'); // Guardando la direccion en la BD $model->docto_propuesta = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension; $model->save(); $model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension ); } */ // Obteniendo el archivo que se subió. $model->archivo = UploadedFile::getInstance($model, 'archivo'); if ($model->archivo && $model->validate()) { $archivo = $model->archivo->name; echo $model->docto_propuesta; // Desserializando los valores de la BD $dato_inicial = unserialize($model->docto_propuesta); // Obteniendo el nuevo archivo del formulario //$nombreImagen = $model->cuenta .'-'.date('Ymd-His'); //$dato_nuevo = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension; $dato_nuevo = 'doctos/' . $archivo; // Serializando los nuevos datos if (!is_array($dato_inicial)) { $dato_inicial = explode("\n", $dato_inicial); } $temporal[0] = $dato_nuevo; $i = 1; foreach ($dato_inicial as $valor) { $temporal[$i] = $dato_inicial[$i - 1]; $i++; } // Guardando en la BD $model->docto_propuesta = serialize($temporal); $model->save(); //$model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension ); $model->archivo->saveAs('doctos/' . $archivo); } // Modificando los contactos if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { Contactos::deleteAll(['contactosid' => $deletedIDs]); } foreach ($modelsContactos as $modelContacto) { $modelContacto->cuenta_id = $model->cuentasid; if (!($flag = $modelContacto->save(false))) { $transaction->rollBack(); break; } } } if ($flag) { $transaction->commit(); //return $this->redirect([$vista, 'id' => $model->cuentasid]); return $this->redirect(Yii::$app->session->get('regresa_anterior')); } } catch (Exception $e) { $transaction->rollBack(); } } //return $this->redirect([$vista, 'id' => $model->cuentasid]); } else { Yii::$app->session->set('regresa_anterior', Yii::$app->request->referrer); if ($vista == 'estatales') { return $this->render('update_estatal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'gdf') { return $this->render('update_gdf', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'gobierno-federal') { return $this->render('update_gobiernofederal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'iniciativa-privada') { return $this->render('update_ip', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'partidos') { return $this->render('update_partidos', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'delegacion') { return $this->render('update_delegacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'intercambio') { return $this->render('update_intercambio', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } elseif ($vista == 'fundacion') { return $this->render('update_fundacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]); } } }
/** * Updates an existing Arqueo 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); $modelsNotas = $model->conteonotas; //$modelsNotas = Conteonotas::findAll(['arqueo_id' => 70]); //var_dump($modelsNotas->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql); exit(); if ($model->load(Yii::$app->request->post())) { Model::loadMultiple($modelsNotas, Yii::$app->request->post()); $valid = $model->validate(); $valid = Model::validateMultiple($modelsNotas) && $valid; if ($valid) { $transaction = Yii::$app->db->beginTransaction(); try { foreach ($modelsNotas as $modelNotas) { $modelNotas->arqueo_id = $model->id; if (!($flag = $modelNotas->save(false))) { $transaction->rollBack(); break; } } $this->actualizaArqueo($model); $model->save(false); /* if ($flag = $model->save(false)) { }*/ if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (Exception $e) { $transaction->rollBack(); } } } else { return $this->render('update', ['model' => $model, 'modelsNotas' => $modelsNotas]); } }