Commit cfa40410 authored by mathieu.pionier's avatar mathieu.pionier
Browse files

FIX #18863 TIME 0:05 add entity contact replacement on mail when deleting one

parent 2782e876
...@@ -180,6 +180,7 @@ class EntityController ...@@ -180,6 +180,7 @@ class EntityController
$entity['users'] = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); $entity['users'] = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname', 'users.status']]);
$children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$args['id']]]); $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$args['id']]]);
$entity['contact'] = $this->getContactLinkCount($entity['id']);
$entity['hasChildren'] = count($children) > 0; $entity['hasChildren'] = count($children) > 0;
$documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$args['id']]]); $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$args['id']]]);
$entity['documents'] = count($documents); $entity['documents'] = count($documents);
...@@ -195,6 +196,13 @@ class EntityController ...@@ -195,6 +196,13 @@ class EntityController
return $response->withJson(['entity' => $entity]); return $response->withJson(['entity' => $entity]);
} }
public function getContactLinkCount(int $id)
{
$linkCount = count(ResourceContactModel::get(['select' => ['distinct res_id'], 'where' => ['item_id = ?', 'type = ?'], 'data' => [$id, 'entity']]));
return $linkCount;
}
public function create(Request $request, Response $response) public function create(Request $request, Response $response)
{ {
if (!PrivilegeController::hasPrivilege(['privilegeId' => 'manage_entities', 'userId' => $GLOBALS['id']])) { if (!PrivilegeController::hasPrivilege(['privilegeId' => 'manage_entities', 'userId' => $GLOBALS['id']])) {
...@@ -532,10 +540,20 @@ class EntityController ...@@ -532,10 +540,20 @@ class EntityController
'data' => ['"'.$dyingEntity['id'].'"'] 'data' => ['"'.$dyingEntity['id'].'"']
]); ]);
//ResourceContact //ResourceContact
ResourceContactModel::update(['set' => ['item_id' => $successorEntity['id']], 'where' => ['item_id = ?', 'type = ?'], 'data' => [$dyingEntity['id'], 'entity']]); $dyingOcc = ResourceContactModel::get(['select' => ['id', 'res_id', 'item_id', 'mode'], 'where' => ['type = ?', 'item_id = ?'], 'data' => ['entity', $dyingEntity['id']]]);
$succOcc = ResourceContactModel::get(['select' => ['id', 'res_id', 'item_id', 'mode'], 'where' => ['type = ?', 'item_id = ?', 'res_id in (?)'], 'data' => ['entity', $successorEntity['id'], array_uniq(array_column($dyingOcc, 'res_id'))]]);
$dyingIds = array_column($dyingOcc, 'id');
$idsToDelete = [];
foreach ($dyingOcc as $d) {
foreach ($succOcc as $s) {
if ($d['mode'] == $s['mode'] && $d['res_id'] == $s['res_id']) {
$idsToDelete[] = $d['id'];
}
}
}
ResourceContactModel::delete(['where' => ['id in (?)'], 'data' => [$idsToDelete]]);
ResourceContactModel::update(['set' => ['item_id' => $successorEntity['id']], 'where' => ['id in (?)'], 'data' => [$dyingIds]]);
EntityModel::delete(['where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]);
HistoryController::add([ HistoryController::add([
'tableName' => 'entities', 'tableName' => 'entities',
'recordId' => $aArgs['id'], 'recordId' => $aArgs['id'],
......
...@@ -15,6 +15,12 @@ ...@@ -15,6 +15,12 @@
<b>{{data.entity.entity_label}}</b> {{'lang.isCopyTo' | translate}} <b>{{data.entity.entity_label}}</b> {{'lang.isCopyTo' | translate}}
<b>{{data.entity.instances}}</b> {{'lang.documents' | translate}}</p> <b>{{data.entity.instances}}</b> {{'lang.documents' | translate}}</p>
</mat-list-item> </mat-list-item>
<mat-list-item *ngIf="data.entity.contact > 0">
<mat-icon color="primary" mat-list-icon class="fa fa-address-book fa-2x"></mat-icon>
<p mat-line>
<b>{{data.entity.entity_label}}</b> {{'lang.isLinkedTo' | translate | lowercase}}
<b>{{data.entity.contact}}</b> {{'lang.contactsEntity' | translate | lowercase}}</p>
</mat-list-item>
<mat-list-item *ngIf="data.entity.users.length > 0"> <mat-list-item *ngIf="data.entity.users.length > 0">
<mat-icon color="primary" mat-list-icon class="fa fa-user fa-2x"></mat-icon> <mat-icon color="primary" mat-list-icon class="fa fa-user fa-2x"></mat-icon>
<p mat-line> <p mat-line>
...@@ -40,4 +46,4 @@ ...@@ -40,4 +46,4 @@
(click)="dialogRef.close(data.entity)" (click)="dialogRef.close(data.entity)"
[disabled]="data.entity.redirectEntity === undefined || data.entity.redirectEntity == data.entity.entity_id">{{'lang.delete' | translate}}</button> [disabled]="data.entity.redirectEntity === undefined || data.entity.redirectEntity == data.entity.entity_id">{{'lang.delete' | translate}}</button>
</mat-dialog-actions> </mat-dialog-actions>
</div> </div>
\ No newline at end of file
...@@ -378,6 +378,7 @@ ...@@ -378,6 +378,7 @@
"contacts": "Contacts", "contacts": "Contacts",
"contactsAdmin": "Administration des contacts", "contactsAdmin": "Administration des contacts",
"contactsAlt": "Contact(s)", "contactsAlt": "Contact(s)",
"contactsEntity": "courrier(s) en tant que contact",
"contactsFillingAdministration": "Complétude des informations contacts", "contactsFillingAdministration": "Complétude des informations contacts",
"contactsFillingCriteria": "Critères de complétude", "contactsFillingCriteria": "Critères de complétude",
"contactsFillingRate": "Taux de complétude", "contactsFillingRate": "Taux de complétude",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment