Fixed edit scheduled ticket updated shoertenClient function to be even more intelligent

This commit is contained in:
johnnyq 2023-09-17 20:08:41 -04:00
parent 1b90a005e4
commit 827b880b28
2 changed files with 33 additions and 18 deletions

View File

@ -705,25 +705,40 @@ function removeEmoji($text){
}
function shortenClient($client) {
$client = trim($client); // Remove any leading/trailing spaces
// Pre-process by removing any non-alphanumeric characters except for certain punctuations.
$cleaned = preg_replace('/[^a-zA-Z0-9&]+/', ' ', $client);
// 1. If the client name is a single word and has three or more characters:
if (strpos($client, ' ') === false && strlen($client) >= 3) {
return substr($client, 0, 3);
}
// 2. If the client name has multiple words:
$words = explode(' ', $client);
// Break into words.
$words = explode(' ', trim($cleaned));
$shortened = '';
foreach ($words as $word) {
$shortened .= $word[0];
// If there's only one word.
if (count($words) == 1) {
$word = $words[0];
if (strlen($word) <= 3) {
return strtoupper($word);
}
// Prefer starting and ending characters.
$shortened = $word[0] . substr($word, -2);
} else {
// Less weightage to common words.
$commonWords = ['the', 'of', 'and'];
foreach ($words as $word) {
if (!in_array(strtolower($word), $commonWords) || strlen($shortened) < 2) {
$shortened .= $word[0];
}
}
// If there are still not enough characters, take from the last word.
while (strlen($shortened) < 3 && !empty($word)) {
$shortened .= substr($word, 1, 1);
$word = substr($word, 1);
}
}
// 3. If there are still not enough characters:
if (strlen($shortened) < 3) {
$remaining = 3 - strlen($shortened);
$shortened .= substr($client, strlen($shortened), $remaining);
}
return strtoupper(substr($shortened, 0, 3)); // Return first three characters
return strtoupper(substr($shortened, 0, 3));
}

View File

@ -19,7 +19,7 @@ function populateScheduledTicketEditModal(client_id, ticket_id) {
document.getElementById("editClientId").value = client_id;
document.getElementById("editTicketSubject").value = ticket.scheduled_ticket_subject;
document.getElementById("editTicketNextRun").value = ticket.scheduled_ticket_next_run;
$('#editTicketDetails').summernote('code', ticket.scheduled_ticket_details);
tinyMCE.get('editTicketDetails').setContent(ticket.scheduled_ticket_details);
// Frequency dropdown