Skip to content

Commit f150f2e

Browse files
committed
✨ Add configurable subject assignment for offline chat requests
Offline chats previously could not be tagged with a subject automatically, forcing operators to categorize each request manually. This change introduces a "Subject ID" setting on the offline settings page: - 🎛️ Add subject_id field to the offline settings form (validated to only accept existing subject IDs, defaulting to 0 = no subject) - 💾 Persist subject_id in the offline_settings config on save - 🔗 Auto-assign the configured subject to a chat when an offline request is saved, skipping duplicates if the link already exists
1 parent 4ff7996 commit f150f2e

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎lhc_web/design/defaulttheme/tpl/lhsystem/offlinesettings.tpl.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<p><small><i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation("system/offlinesettings","Make sure you have NOT checked 'Do not save offline chats' option above");?></i></small></p>
2222
</div>
2323

24+
<div class="form-group">
25+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/offlinesettings','Subject ID');?></label>
26+
<input type="number" min="0" class="form-control form-control-sm" name="subject_id" value="<?php echo isset($settings['subject_id']) ? (int)$settings['subject_id'] : 0;?>">
27+
<p><small><i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/offlinesettings','Subject which will be assigned to the chat when offline request is saved. Leave 0 to not assign any subject.');?></i></small></p>
28+
</div>
29+
2430
<div class="form-group">
2531
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/timezone','Offline message which will be saved within a chat');?> <button type="button" class="btn btn-xs btn-outline-secondary mb-1" onclick="document.querySelector('textarea[name=&quot;offline_message&quot;]').value = '[b]Visitor query[/b]:\n{args.question}\n\n[b]Phone[/b]: {args.chat.phone}\n[b]E-mail[/b]: {args.chat.email}\n[b]Nick[/b]: {args.chat.nick}\n[b]Additional data[/b]: {args.chat.additional_data}'"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/buttons','Set default');?></button></label>
2632
<textarea rows="5" class="form-control form-control-sm" name="offline_message"><?php echo isset($settings['offline_message']) ? htmlspecialchars($settings['offline_message']) : '[b]Visitor query[/b]:

‎lhc_web/lib/core/lhchat/lhchatvalidator.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,18 @@ public static function saveOfflineRequest($params) {
23142314

23152315
$params['chat']->saveThis();
23162316

2317+
// Assign subject configured in offline settings
2318+
if (isset($data['subject_id']) && (int)$data['subject_id'] > 0) {
2319+
$subjectChat = erLhAbstractModelSubjectChat::findOne(array('filter' => array('chat_id' => $params['chat']->id, 'subject_id' => (int)$data['subject_id'])));
2320+
2321+
if (!($subjectChat instanceof erLhAbstractModelSubjectChat)) {
2322+
$subjectChat = new erLhAbstractModelSubjectChat();
2323+
$subjectChat->subject_id = (int)$data['subject_id'];
2324+
$subjectChat->chat_id = $params['chat']->id;
2325+
$subjectChat->saveThis();
2326+
}
2327+
}
2328+
23172329
if ( $params['question'] != '' ) {
23182330
// Store question as message
23192331
$msg = new erLhcoreClassModelmsg();

‎lhc_web/modules/lhsystem/offlinesettings.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
),
2020
'offline_message' => new ezcInputFormDefinitionElement(
2121
ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'
22+
),
23+
'subject_id' => new ezcInputFormDefinitionElement(
24+
ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)
2225
)
2326
);
2427

@@ -56,6 +59,12 @@
5659
$data['close_offline'] = 0;
5760
}
5861

62+
if ( $form->hasValidData( 'subject_id' ) && erLhAbstractModelSubject::getCount(array('filter' => array('id' => (int)$form->subject_id)) ) > 0) {
63+
$data['subject_id'] = (int)$form->subject_id;
64+
} else {
65+
$data['subject_id'] = 0;
66+
}
67+
5968
$offlineData->explain = '';
6069
$offlineData->type = 0;
6170
$offlineData->hidden = 1;

0 commit comments

Comments
 (0)