Skip to content

Commit debed11

Browse files
committed
✨ Add "Next auto assignment" tab to department statistics with read-only queue replay 🔄👥
- ✨ New `AutoAssign` helper methods (`nextPendingChats`, `unassignedChat`, `operatorQueue`, `queueOverview`) to replay the auto assignment workflow without locking 🧠🔍 - 📊 New `autoassign_queue.tpl.php` template showing pending chats, operator queue with verdicts/blocked reasons, and gate checks ✅ - 🔄 Auto-refreshing tab polls `statistic/departmentstats/(action)/autoassign` every 2s to reload only the queue markup ⏱️ - 🎯 Eligibility filter with live count of operators valid for auto assignment, survives partial refreshes 🟢 - 🖥️ Wider modal (`xxxl`) and tab activation support via new `autoassign` tab param 📐 - 🛡️ New `action` uparam on `departmentstats` view for partial queue rendering 🔧
1 parent fe96aa6 commit debed11

5 files changed

Lines changed: 446 additions & 3 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* Read only replay of the department auto assignment queue.
4+
*
5+
* Rendered in two places:
6+
* - included by `lhstatistic/departmentstats.tpl.php` inside the `Next auto assignment` tab
7+
* - rendered standalone by `statistic/departmentstats/(action)/autoassign` so the tab can refresh
8+
* only this part every 2 seconds without reloading the whole modal.
9+
*
10+
* Expects `$department` (erLhcoreClassModelDepartament) to be set.
11+
*/
12+
$autoAssignQueue = \LiveHelperChat\Mcp\AutoAssign::queueOverview($department, 5);
13+
?>
14+
<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Next auto assignment');?></h6>
15+
<p class="small text-muted"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','This is a read only replay of the auto assignment workflow. A chat is assigned by the `cron/workflow` cron job or by the next chat status check, so the operator and the order below can change in the meantime. Extension events (`chat.workflow.autoassign`, `chat.workflow.autoassign_permit`) are not visible here.');?></p>
16+
17+
<?php if ($autoAssignQueue['enabled'] !== true) : ?>
18+
<div class="alert alert-warning p-2 m-0 mb-2"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Auto assignment is disabled on this department (`active_balancing` = 0), pending chats wait until an operator accepts them manually.');?></div>
19+
<?php endif; ?>
20+
21+
<?php if ($autoAssignQueue['simulated']) : ?>
22+
<div class="alert alert-info p-2 m-0 mb-2"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','There are no pending chats in this department. The operator queue below is simulated for a chat which just arrived with priority 0.');?></div>
23+
<?php else : ?>
24+
<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Pending chats in queue');?></h6>
25+
<table class="table table-sm table-striped w-100">
26+
<thead>
27+
<tr>
28+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Chat');?></th>
29+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Priority');?></th>
30+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Waiting');?></th>
31+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Auto assignment');?></th>
32+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Variant');?></th>
33+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Blocked by');?></th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<?php foreach ($autoAssignQueue['chats'] as $queueChat) : ?>
38+
<tr>
39+
<td><a target="_blank" href="<?php echo erLhcoreClassDesign::baseurl('chat/single')?>/<?php echo (int)$queueChat['chat']['id']?>">#<?php echo (int)$queueChat['chat']['id']?></a></td>
40+
<td><?php echo (int)$queueChat['chat']['priority']?></td>
41+
<td><?php echo erLhcoreClassChat::formatSeconds(max(0, time() - (int)$queueChat['chat']['ctime']))?></td>
42+
<td>
43+
<?php if ($queueChat['gates']['allowed'] && $queueChat['pick']['picked_user_id'] > 0) : ?>
44+
<span class="badge bg-success"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Yes');?></span>
45+
<?php $queueChatUser = erLhcoreClassModelUser::fetch($queueChat['pick']['picked_user_id']); ?>
46+
<a target="_blank" href="<?php echo erLhcoreClassDesign::baseurl('user/edit')?>/<?php echo (int)$queueChat['pick']['picked_user_id']?>"><?php echo htmlspecialchars($queueChatUser !== false ? $queueChatUser->name_official : '#' . (int)$queueChat['pick']['picked_user_id'])?></a>
47+
<?php else : ?>
48+
<span class="badge bg-danger"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','No');?></span>
49+
<?php endif; ?>
50+
</td>
51+
<td><?php echo $queueChat['pick']['variant'] === null ? '-' : htmlspecialchars((string)$queueChat['pick']['variant'])?></td>
52+
<td>
53+
<?php foreach ($queueChat['gates']['blocked_by'] as $queueBlockedBy) : ?><span class="badge bg-secondary me-1"><?php echo htmlspecialchars($queueBlockedBy)?></span> <?php endforeach; ?>
54+
<?php if (empty($queueChat['gates']['blocked_by']) && $queueChat['pick']['picked_user_id'] == 0) : ?><span class="badge bg-secondary">no_matching_operator</span><?php endif; ?>
55+
</td>
56+
</tr>
57+
<?php endforeach; ?>
58+
</tbody>
59+
</table>
60+
<?php endif; ?>
61+
62+
<h6>
63+
<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Operator queue');?>
64+
<?php if ((int)$autoAssignQueue['reference_chat']['id'] > 0) : ?>
65+
<span class="small text-muted">- #<?php echo (int)$autoAssignQueue['reference_chat']['id']?> (<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','priority');?> <?php echo (int)$autoAssignQueue['reference_chat']['priority']?>)</span>
66+
<?php endif; ?>
67+
</h6>
68+
<?php if (empty($autoAssignQueue['operators'])) : ?>
69+
<p><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','No operator is assigned to this department. Rows with `dep_id` 0 (all departments) are not used by the auto assignment queries.');?></p>
70+
<?php else : ?>
71+
<div class="small text-muted mb-1"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','At most');?> <?php echo (int)\LiveHelperChat\Mcp\AutoAssign::QUEUE_OPERATOR_LIMIT?> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','next operators from the queue are listed, the rest is listed with the reason they are skipped.');?></div>
72+
<table class="table table-sm table-striped w-100">
73+
<thead>
74+
<tr>
75+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Queue position');?></th>
76+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Operator');?></th>
77+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Online');?></th>
78+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Last assigned ago');?></th>
79+
<th title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Active / pending / inactive chats');?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Chats');?></th>
80+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Max chats');?></th>
81+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Assignment priority');?></th>
82+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Verdict');?></th>
83+
</tr>
84+
</thead>
85+
<tbody>
86+
<?php $queuePosition = 0; foreach ($autoAssignQueue['operators'] as $queueOperator) : ?>
87+
<tr class="<?php if (!$queueOperator['pickable']) : ?>text-muted<?php endif;?>" data-autoassign-valid="<?php echo $queueOperator['pickable'] ? 1 : 0;?>">
88+
<td>
89+
<?php if ($queueOperator['pickable']) : $queuePosition++; ?>
90+
<span class="badge bg-success"><?php echo $queuePosition?></span>
91+
<?php else : ?>
92+
-
93+
<?php endif; ?>
94+
</td>
95+
<td>
96+
<?php $queueOperatorUser = erLhcoreClassModelUser::fetch($queueOperator['user_id']); ?>
97+
<a <?php if (!$queueOperator['pickable']) : ?>class="text-muted"<?php endif;?> title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Edit operator');?>" href="<?php echo erLhcoreClassDesign::baseurl('user/edit')?>/<?php echo (int)$queueOperator['user_id']?>"><span class="material-icons">account_box</span><?php echo htmlspecialchars($queueOperatorUser !== false ? $queueOperatorUser->name_official : '#' . (int)$queueOperator['user_id'])?></a>
98+
<span class="badge bg-secondary">user_dep_id <?php echo (int)$queueOperator['user_dep_id']?></span>
99+
<?php if ((int)$queueOperator['operator']['ro'] === 1) : ?><span class="badge bg-warning text-dark">ro</span><?php endif; ?>
100+
<?php if ((int)$queueOperator['operator']['only_priority'] === 1) : ?><span class="badge bg-info text-dark">only_priority</span><?php endif; ?>
101+
<?php if ((int)$queueOperator['operator']['always_on'] === 1) : ?><span class="badge bg-info text-dark">always_on</span><?php endif; ?>
102+
</td>
103+
<td>
104+
<span class="material-icons <?php echo $queueOperator['online'] ? 'text-success' : 'text-danger';?>" title="<?php echo $queueOperator['online'] ? erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Online for the auto assignment') : erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Offline for the auto assignment'); ?>"><?php echo (int)$queueOperator['operator']['hide_online'] == 0 ? 'flash_on' : 'flash_off';?></span>
105+
<?php if ($queueOperator['operator']['last_activity_age'] !== null) : ?><span class="small text-muted"><?php echo erLhcoreClassChat::formatSeconds($queueOperator['operator']['last_activity_age'])?></span><?php endif; ?>
106+
</td>
107+
<td><?php echo $queueOperator['operator']['last_accepted_age'] === null ? '-' : erLhcoreClassChat::formatSeconds($queueOperator['operator']['last_accepted_age'])?></td>
108+
<td><?php echo (int)$queueOperator['operator']['active_chats']?> / <?php echo (int)$queueOperator['operator']['pending_chats']?> / <?php echo (int)$queueOperator['operator']['inactive_chats']?></td>
109+
<td><?php echo (int)$queueOperator['operator']['max_chats'] == 0 ? '&infin;' : (int)$queueOperator['operator']['max_chats']?></td>
110+
<td><?php echo (int)$queueOperator['operator']['assign_priority']?></td>
111+
<td>
112+
<?php if ($queueOperator['pickable']) : ?>
113+
<span class="material-icons text-success" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Would receive the next chat');?>">done</span>
114+
<?php else : ?>
115+
<?php foreach ($queueOperator['blocked_by'] as $queueBlockedBy) : ?><span class="badge bg-secondary me-1"><?php echo htmlspecialchars($queueBlockedBy)?></span> <?php endforeach; ?>
116+
<?php endif; ?>
117+
</td>
118+
</tr>
119+
<?php endforeach; ?>
120+
</tbody>
121+
</table>
122+
<?php endif; ?>
123+
124+
<h6><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Gates of the next chat');?></h6>
125+
<ul class="list-unstyled small">
126+
<?php foreach ($autoAssignQueue['gates']['checks'] as $queueGate) : ?>
127+
<li>
128+
<span class="material-icons align-middle <?php echo $queueGate['allowed'] ? 'text-success' : 'text-danger';?>"><?php echo $queueGate['allowed'] ? 'check_circle' : 'cancel';?></span>
129+
<span class="badge bg-secondary"><?php echo htmlspecialchars($queueGate['requirement'])?></span>
130+
<?php echo htmlspecialchars($queueGate['details'])?>
131+
</li>
132+
<?php endforeach; ?>
133+
</ul>

0 commit comments

Comments
 (0)