addition of conversation history in customer thread

This commit is contained in:
Marion Muszynski 2017-04-06 16:10:25 +02:00
parent 20a07e3273
commit 2b861808e0
2 changed files with 69 additions and 1 deletions

View File

@ -1150,10 +1150,19 @@ class AdminCustomerThreads extends AdminTab
echo '</div>';
echo '<div style="float:left;margin-top:10px">';
echo '<div style="float:left;margin-top:10px"><div>';
foreach ($messages AS $message) {
echo $this->displayMsgCustom($message);
}
echo '</div>';
$conversations = CustomerThread::getCustomerConversations((int)$customer->id,'ASC',(int)Tools::getValue('id_customer_thread'));
if(!empty($conversations)){
echo '<div>';
$this->displayOldMessages($conversations,$customer);
echo '</div>';
}
echo '</div>';
echo '<div class="clear">&nbsp;</div>';
@ -1237,6 +1246,53 @@ class AdminCustomerThreads extends AdminTab
echo '<div class="clear">&nbsp;</div>';
}
private function displayOldMessages($conversations,$customer)
{
global $cookie;
$output = '<div class="panel-message">';
foreach($conversations as $key => $conv){
$output .= '<div class="panel-head bg-purple">
<div class="panel-head-left">
<div class="user-info">
<span class="anticon anticon-bubbles2"></span>
<a href="index.php?tab=AdminCustomerThreads&id_customer_thread='.(int)($conv['id_customer_thread']).'&viewcustomer_thread&token='.Tools::getAdminTokenLite('AdminCustomerThreads').'" title=Voir la conversation"> Conversation #'.(int)($conv['id_customer_thread']).' ('.$conv['status'].')</a>
</div>
<div class="grey div-date"><span class="anticon anticon-clock"></span> '.Tools::displayDate($conv['date_add'], (int)($cookie->id_lang), true).'</div>
</div>
</div>';
$messages = Db::getInstance()->ExecuteS('
SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name, CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON (ct.id_customer_thread = cm.id_customer_thread)
LEFT JOIN '._DB_PREFIX_.'contact_lang cl ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)$cookie->id_lang.')
LEFT JOIN '._DB_PREFIX_.'employee e ON e.id_employee = cm.id_employee
LEFT JOIN '._DB_PREFIX_.'customer c ON (IFNULL(ct.id_customer, ct.email) = IFNULL(c.id_customer, c.email))
WHERE ct.id_customer_thread = '.(int)($conv['id_customer_thread']).' AND ct.id_customer_thread != '.(int)Tools::getValue('id_customer_thread').'
ORDER BY cm.date_add DESC'
);
foreach ($messages as $key => $message) {
if(!empty($message['employee_name'])) {
$output .= '<p style="margin:0;text-align:right;">Bébé Boutik <span class="anticon anticon-user-tie"></span></p>
<div class="panel-content-message bg-rose" style="margin:0 0 10px 0;">
<b>Message</b><br>
'.$message['message'] = preg_replace('/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui', '<a href="\1">\1</a>\2', html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8')).'
</div>';
} else {
$output .= '<p style="margin:0; text-transform: capitalize;"><span class="anticon anticon-user"></span> '.$customer->firstname.' '.$customer->lastname.'</p>
<div class="panel-content-message bg-purple" style="margin:0 0 10px 0;">
<b>Message</b><br>
'.$message['message'] = preg_replace('/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui', '<a href="\1">\1</a>\2', html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8')).'
</div>';
}
}
}
$output .= '</div>';
echo $output;
}
private function displayButton($content)
{
return '

View File

@ -26,4 +26,16 @@ class CustomerThread extends CustomerThreadCore
}
return '<img src="/img/flags/'.(int) $flag.'.png" alt="" />';
}
public static function getCustomerConversations($id_customer, $order = 'ASC', $except_id = false)
{
return Db::getInstance()->ExecuteS('
SELECT DISTINCT ct.* FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON ct.id_customer_thread = cm.id_customer_thread
WHERE id_customer = '.(int)($id_customer)
.($except_id?' AND ct.id_customer_thread !='.(int)$except_id:'')
.' ORDER BY cm.date_add '.$order
);
}
}