From a47b8193ab29309f73c4dee5bfa53069012bdb60 Mon Sep 17 00:00:00 2001 From: Victor Magalhaes Date: Thu, 5 Sep 2024 15:08:54 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20reimplementa=20duplica=C3=A7=C3=A3o=20d?= =?UTF-8?q?e=20oportunidade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/Controllers/Opportunity.php | 71 ------------------- .../Traits/EntityOpportunityDuplicator.php | 9 +-- .../assets/js/components-base/Entity.js | 26 ++++--- 3 files changed, 21 insertions(+), 85 deletions(-) diff --git a/src/core/Controllers/Opportunity.php b/src/core/Controllers/Opportunity.php index af8e354146..364b738c2e 100644 --- a/src/core/Controllers/Opportunity.php +++ b/src/core/Controllers/Opportunity.php @@ -1333,75 +1333,4 @@ public function ALL_fixNextPhaseRegistrationIds():void $opportunity->fixNextPhaseRegistrationIds(); } - - function ALL_duplicate(){ - $app = App::i(); - - $this->requireAuthentication(); - $opportunity = $this->requestedEntity; - $newOpportunity = clone $opportunity; - - // duplica a oportunidade - $dateTime = new \DateTime(); - $now = $dateTime->format('d-m-Y H:i:s'); - $newOpportunity->setName("$opportunity->name - [Cópia][$now]"); - $newOpportunity->setStatus(Entity::STATUS_DRAFT); - $app->em->persist($newOpportunity); - $app->em->flush(); - - - // duplica o método de avaliação para a oportunidade primária - $evaluationMethodConfigurations = $app->repo('EvaluationMethodConfiguration')->findBy([ - 'opportunity' => $opportunity - ]); - foreach ($evaluationMethodConfigurations as $evaluationMethodConfiguration) { - $newMethodConfiguration = clone $evaluationMethodConfiguration; - $newMethodConfiguration->setOpportunity($newOpportunity); - $newMethodConfiguration->save(true); - - foreach ($evaluationMethodConfiguration->getMetadata() as $metadataKey => $metadataValue) { - $newMethodConfiguration->setMetadata($metadataKey, $metadataValue); - $newMethodConfiguration->save(true); - } - } - - - foreach ($opportunity->getMetadata() as $metadataKey => $metadataValue) { - if (!is_null($metadataValue) && $metadataValue != '') { - $newOpportunity->setMetadata($metadataKey, $metadataValue); - } - } - - $newOpportunity->setTerms(['area' => $opportunity->terms['area']]); - $newOpportunity->saveTerms(); - - foreach ($opportunity->getRegistrationFieldConfigurations() as $registrationFieldConfiguration) { - $fieldConfiguration = clone $registrationFieldConfiguration; - $fieldConfiguration->setOwnerId($newOpportunity->getId()); - $fieldConfiguration->save(true); - } - - foreach ($opportunity->getRegistrationFileConfigurations() as $registrationFileConfiguration) { - $fileConfiguration = clone $registrationFileConfiguration; - $fileConfiguration->setOwnerId($newOpportunity->getId()); - $fileConfiguration->save(true); - } - - foreach ($opportunity->getMetaLists() as $metaList_) { - foreach ($metaList_ as $metaList__) { - $metalist = $metaList__; - $metalist->setOwner($newOpportunity); - - $metalist->save(true); - } - } - - $newOpportunity->save(); - - if($this->isAjax()){ - $this->json($opportunity); - }else{ - $app->redirect($app->request->getReferer()); - } - } } \ No newline at end of file diff --git a/src/core/Traits/EntityOpportunityDuplicator.php b/src/core/Traits/EntityOpportunityDuplicator.php index 52c53d5853..ff058da2cb 100644 --- a/src/core/Traits/EntityOpportunityDuplicator.php +++ b/src/core/Traits/EntityOpportunityDuplicator.php @@ -1,12 +1,13 @@ format('d-m-Y H:i:s'); $name = $this->opportunity->name; - $this->newOpportunity->setName("$name - [Cópia][$now]"); - $this->newOpportunity->setStatus(Entity::STATUS_DRAFT); + $this->newOpportunity->name = "$name - [Cópia][$now]"; + $this->newOpportunity->status = Entity::STATUS_DRAFT; $this->newOpportunity->registrationCategories = []; $app->em->persist($this->newOpportunity); $app->em->flush(); @@ -203,7 +204,7 @@ private function duplicateFiles() : void private function duplicateAgentRelations() : void { - foreach ($this->opportunity->getAgentRelations(null, true) as $agentRelation_) { + foreach ($this->opportunity->getAgentRelations() as $agentRelation_) { $agentRelation = clone $agentRelation_; $agentRelation->owner = $this->newOpportunity; $agentRelation->save(true); diff --git a/src/modules/Components/assets/js/components-base/Entity.js b/src/modules/Components/assets/js/components-base/Entity.js index d24aae6578..1383ba8f41 100644 --- a/src/modules/Components/assets/js/components-base/Entity.js +++ b/src/modules/Components/assets/js/components-base/Entity.js @@ -145,7 +145,14 @@ class Entity { } catchErrors(res, data) { - const message = data.data.message; + const message = data.data.message ?? + data.data.avatar ?? + data.data.header ?? + data.data.gallery ?? + data.data.logo ?? + data.data.background ?? + data.data.share ?? + data.data.institute; // getting errors from validation errors; if (res.status >= 500 && res.status <= 599) { this.sendMessage(message || this.text('erro inesperado'), 'error'); @@ -532,9 +539,8 @@ class Entity { return this.doPromise(res, (entity) => { this.sendMessage(this.text('entidade duplicada')); this.populate(entity); - if(removeFromLists) { - this.removeFromLists(); - } + + window.open('/minhas-oportunidades/#draft', '_blank').focus(); }); } catch (error) { return this.doCatch(error); @@ -780,9 +786,9 @@ class Entity { /* let index; index = this.seals.indexOf(seal); this.seals.splice(index,1); */ - }); - } catch (error) { - return this.doCatch(error); - } - } -} \ No newline at end of file + }); + } catch (error) { + return this.doCatch(error); + } + } +}