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
$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']]]);
$entity['contact'] = $this->getContactLinkCount($entity['id']);
$entity['hasChildren'] = count($children) > 0;
$documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$args['id']]]);
$entity['documents'] = count($documents);
......@@ -195,6 +196,13 @@ class EntityController
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)
{
if (!PrivilegeController::hasPrivilege(['privilegeId' => 'manage_entities', 'userId' => $GLOBALS['id']])) {
......@@ -532,10 +540,20 @@ class EntityController
'data' => ['"'.$dyingEntity['id'].'"']
]);
//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([
'tableName' => 'entities',
'recordId' => $aArgs['id'],
......
......@@ -15,6 +15,12 @@
<b>{{data.entity.entity_label}}</b> {{'lang.isCopyTo' | translate}}
<b>{{data.entity.instances}}</b> {{'lang.documents' | translate}}</p>
</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-icon color="primary" mat-list-icon class="fa fa-user fa-2x"></mat-icon>
<p mat-line>
......
......@@ -378,6 +378,7 @@
"contacts": "Contacts",
"contactsAdmin": "Administration des contacts",
"contactsAlt": "Contact(s)",
"contactsEntity": "courrier(s) en tant que contact",
"contactsFillingAdministration": "Complétude des informations contacts",
"contactsFillingCriteria": "Critères 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