From ab9f398d7b367a8064aa69579bc03bd6c8af0049 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Fri, 15 Sep 2023 23:58:50 +0300 Subject: [PATCH] - fix tab counter failed if only one tab open --- src/includes/api/TasksController.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/includes/api/TasksController.php b/src/includes/api/TasksController.php index 99bc452..e2fb7bb 100644 --- a/src/includes/api/TasksController.php +++ b/src/includes/api/TasksController.php @@ -258,11 +258,8 @@ class TasksController extends ApiController { function postNewCounter() { checkReadAccess(); - $lists = $this->req->jsonBody['lists'] ?? false; - if (!is_array($lists)) { - $this->response->data = [ 'total' => 0 ]; - return; - } + $lists = $this->req->jsonBody['lists'] ?? []; + if (!is_array($lists)) $lists = []; $userLists = []; if (!haveWriteAccess()) { $userLists = $this->getUserListsSimple(true); @@ -281,18 +278,20 @@ class TasksController extends ApiController { if ($later <= 0) continue; $sqlWhereList[] = "(list_id = ". (int)$item['listId']. " AND compl=0 AND d_created > $later)"; } - $sqlWhere = implode(' OR ', $sqlWhereList); - $db = DBConnection::instance(); $a = []; - $q = $db->dq("SELECT list_id, COUNT(id) c FROM {$db->prefix}todolist - WHERE $sqlWhere GROUP BY list_id"); - while ($r = $q->fetchAssoc()) { - $a[] = [ - 'listId' => (int)$r['list_id'], - 'counter' => (int)$r['c'], - ]; + + if ($sqlWhereList) { + $sqlWhere = implode(' OR ', $sqlWhereList); + $q = $db->dq("SELECT list_id, COUNT(id) c FROM {$db->prefix}todolist + WHERE $sqlWhere GROUP BY list_id"); + while ($r = $q->fetchAssoc()) { + $a[] = [ + 'listId' => (int)$r['list_id'], + 'counter' => (int)$r['c'], + ]; + } } $b = [];