Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reimplementa duplicação de oportunidade #482

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions src/core/Controllers/Opportunity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
9 changes: 5 additions & 4 deletions src/core/Traits/EntityOpportunityDuplicator.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
namespace MapasCulturais\Traits;

use MapasCulturais\App;
use MapasCulturais\Entities\ProjectOpportunity;
use MapasCulturais\Entities\User;
use MapasCulturais\Entity;

trait EntityOpportunityDuplicator {

private ProjectOpportunity $opportunity;
private ProjectOpportunity $newOpportunity;

function ALL_duplicate(){
Expand Down Expand Up @@ -44,8 +45,8 @@ private function cloneOpportunity() : ProjectOpportunity
$dateTime = new \DateTime();
$now = $dateTime->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();
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 16 additions & 10 deletions src/modules/Components/assets/js/components-base/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -780,9 +786,9 @@ class Entity {
/* let index;
index = this.seals.indexOf(seal);
this.seals.splice(index,1); */
});
} catch (error) {
return this.doCatch(error);
}
}
}
});
} catch (error) {
return this.doCatch(error);
}
}
}
Loading