Add medias link to mms into received + sended + scheduled + discussion

This commit is contained in:
osaajani 2021-03-21 18:29:23 +01:00
parent 70d01be041
commit f330312b55
8 changed files with 122 additions and 10 deletions

View File

@ -21,6 +21,7 @@ namespace controllers\publics;
private $internal_received;
private $internal_contact;
private $internal_phone;
private $internal_media;
/**
* Cette fonction est appelée avant toute les autres :
@ -37,6 +38,7 @@ namespace controllers\publics;
$this->internal_received = new \controllers\internals\Received($bdd);
$this->internal_contact = new \controllers\internals\Contact($bdd);
$this->internal_phone = new \controllers\internals\Phone($bdd);
$this->internal_media = new \controllers\internals\Media($bdd);
\controllers\internals\Tool::verifyconnect();
}
@ -112,12 +114,26 @@ namespace controllers\publics;
foreach ($sendeds as $sended)
{
$messages[] = [
$medias = [];
if ($sended['mms'])
{
$medias = $this->internal_media->gets_for_sended($sended['id']);
foreach ($medias as &$media)
{
$media = HTTP_PWD_DATA . '/' . $media['path'];
}
}
$message = [
'date' => htmlspecialchars($sended['at']),
'text' => htmlspecialchars($sended['text']),
'type' => 'sended',
'medias' => $medias,
'status' => $sended['status'],
];
$messages[] = $message;
}
foreach ($receiveds as $received)
@ -126,21 +142,43 @@ namespace controllers\publics;
{
$this->internal_received->mark_as_read_for_user($id_user, $received['id']);
}
$medias = [];
if ($sended['mms'])
{
$medias = $this->internal_media->gets_for_received($received['id']);
foreach ($medias as &$media)
{
$media = HTTP_PWD_DATA . '/' . $media['path'];
}
}
$messages[] = [
'date' => htmlspecialchars($received['at']),
'text' => htmlspecialchars($received['text']),
'type' => 'received',
'md5' => md5($received['at'] . $received['text']),
'medias' => $medias,
];
}
foreach ($scheduleds as $scheduled)
{
$medias = [];
if ($sended['mms'])
{
$medias = $this->internal_media->gets_for_scheduled($scheduled['id']);
foreach ($medias as &$media)
{
$media = HTTP_PWD_DATA . '/' . $media['path'];
}
}
$messages[] = [
'date' => htmlspecialchars($scheduled['at']),
'text' => htmlspecialchars($scheduled['text']),
'type' => 'inprogress',
'medias' => $medias,
];
}

View File

@ -19,6 +19,7 @@ namespace controllers\publics;
private $internal_received;
private $internal_contact;
private $internal_phone;
private $internal_media;
/**
* Cette fonction est appelée avant toute les autres :
@ -32,6 +33,7 @@ namespace controllers\publics;
$this->internal_received = new \controllers\internals\Received($bdd);
$this->internal_contact = new \controllers\internals\Contact($bdd);
$this->internal_phone = new \controllers\internals\Phone($bdd);
$this->internal_media = new \controllers\internals\Media($bdd);
\controllers\internals\Tool::verifyconnect();
}
@ -53,6 +55,10 @@ namespace controllers\publics;
foreach ($entities as &$entity)
{
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
if ($entity['mms'])
{
$entity['medias'] = $this->internal_media->gets_for_received($entity['id']);
}
}
header('Content-Type: application/json');
@ -76,6 +82,10 @@ namespace controllers\publics;
foreach ($entities as &$entity)
{
$entity['origin_formatted'] = \controllers\internals\Tool::phone_link($entity['origin']);
if ($entity['mms'])
{
$entity['medias'] = $this->internal_media->gets_for_received($entity['id']);
}
}
header('Content-Type: application/json');

View File

@ -56,6 +56,13 @@ namespace controllers\publics;
public function list_json()
{
$entities = $this->internal_scheduled->list_for_user($_SESSION['user']['id']);
foreach ($entities as &$entity)
{
if ($entity['mms'])
{
$entity['medias'] = $this->internal_media->gets_for_scheduled($entity['id']);
}
}
header('Content-Type: application/json');
echo json_encode(['data' => $entities]);

View File

@ -19,6 +19,7 @@ namespace controllers\publics;
private $internal_sended;
private $internal_phone;
private $internal_contact;
private $internal_media;
/**
* Cette fonction est appelée avant toute les autres :
@ -32,6 +33,7 @@ namespace controllers\publics;
$this->internal_sended = new \controllers\internals\Sended($bdd);
$this->internal_phone = new \controllers\internals\Phone($bdd);
$this->internal_contact = new \controllers\internals\Contact($bdd);
$this->internal_media = new \controllers\internals\Media($bdd);
\controllers\internals\Tool::verifyconnect();
}
@ -55,6 +57,10 @@ namespace controllers\publics;
foreach ($entities as &$entity)
{
$entity['destination_formatted'] = \controllers\internals\Tool::phone_link($entity['destination']);
if ($entity['mms'])
{
$entity['medias'] = $this->internal_media->gets_for_sended($entity['id']);
}
}
header('Content-Type: application/json');

View File

@ -76,7 +76,7 @@
<?php if ($_SESSION['user']['settings']['detect_url']) { ?>
//On ajoute la detection de lien dans le texte du message
message.text = Autolinker.link(message.text, {newWindow:true});
<?php } ?>
<?php } ?>
switch (message.type)
{
@ -85,7 +85,10 @@
'<div class="clearfix message-container">' +
'<div class="discussion-message message-received">' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-date">' + message.date + '</div>' +
'<div class="discussion-message-medias">' + message.medias.map((mediaUrl, index) => {
return '<a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + (index + 1) + '</a>';
}).join(' - ') + '</div>' +
'<div class="discussion-message-date">' + message.date + '</div>' +
'</div>' +
'</div>';
@ -101,6 +104,9 @@
'<div class="clearfix message-container">' +
'<div class="discussion-message message-sended">' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-medias">' + message.medias.map((mediaUrl, index) => {
return '<a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + (index + 1) + '</a>';
}).join(' - ') + '</div>' +
'<div class="discussion-message-date">' + message.date + ' ' + (message.status == 'delivered' ? '<span class="fa fa-check-circle fa-fw text-success"></span>' : (message.status == 'failed' ? '<span class="fa fa-times-circle fa-fw text-danger"></span>' : '<span class="fa fa-clock-o fa-fw text-info"></span>' )) + '</div>' +
'</div>' +
'</div>';
@ -111,6 +117,9 @@
'<div class="discussion-message message-sended">' +
'<div class="message-in-progress-hover"><i class="fa fa-spinner fa-spin"></i></div>' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-medias">' + message.medias.map((mediaUrl, index) => {
return '<a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + (index + 1) + '</a>';
}).join(' - ') + '</div>' +
'<div class="discussion-message-date">' + message.date + '</div>' +
'</div>' +
'</div>';

View File

@ -45,8 +45,8 @@
<table class="table table-bordered table-hover table-striped datatable" id="table-receiveds">
<thead>
<tr>
<th>De</th>
<th>À</th>
<th>Expéditeur</th>
<th>Destinataire</th>
<th>Message</th>
<th>Date</th>
<th>Status</th>
@ -104,7 +104,21 @@ jQuery(document).ready(function ()
},
},
{data: 'phone_name', render: jQuery.fn.dataTable.render.text()},
{data: 'text', render: jQuery.fn.dataTable.render.text()},
{
data: 'text',
render: function (data, type, row, meta) {
if (row.mms == 1) {
var medias = [];
for (i = 0; i < row.medias.length; i++) {
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
}
html = data + '<br/>' + medias.join(' - ');
return html;
}
return data;
},
},
{data: 'at', render: jQuery.fn.dataTable.render.text()},
{
data: 'status',

View File

@ -87,7 +87,21 @@ jQuery(document).ready(function ()
},
"columns" : [
{data: 'at', render: jQuery.fn.dataTable.render.text()},
{data: 'text', render: jQuery.fn.dataTable.render.text()},
{
data: 'text',
render: function (data, type, row, meta) {
if (row.mms == 1) {
var medias = [];
for (i = 0; i < row.medias.length; i++) {
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
}
html = data + '<br/>' + medias.join(' - ');
return html;
}
return data;
},
},
{
data: 'id',
render: function (data, type, row, meta) {

View File

@ -39,8 +39,8 @@
<table class="table table-bordered table-hover table-striped datatable" id="table-sendeds">
<thead>
<tr>
<th>De</th>
<th>À</th>
<th>Expéditeur</th>
<th>Destinataire</th>
<th>Message</th>
<th>Date</th>
<th>Statut</th>
@ -94,7 +94,21 @@ jQuery(document).ready(function ()
return row.destination_formatted;
},
},
{data: 'text', render: jQuery.fn.dataTable.render.text()},
{
data: 'text',
render: function (data, type, row, meta) {
if (row.mms == 1) {
var medias = [];
for (i = 0; i < row.medias.length; i++) {
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
}
html = data + '<br/>' + medias.join(' - ');
return html;
}
return data;
},
},
{data: 'at', render: jQuery.fn.dataTable.render.text()},
{
data: 'status',