diff --git a/Web/Models/Entities/Message.php b/Web/Models/Entities/Message.php index de840606..97f3cf69 100644 --- a/Web/Models/Entities/Message.php +++ b/Web/Models/Entities/Message.php @@ -60,6 +60,17 @@ class Message extends RowModel { return new DateTime($this->getRecord()->created); } + + function getSendTimeHumanized(): string + { + $dateTime = new DateTime($this->getRecord()->created); + + if($dateTime->format("%d.%m.%y") == ovk_strftime_safe("%d.%m.%y", time())) { + return $dateTime->format("%T %p"); + } else { + return $dateTime->format("%d.%m.%y"); + } + } /** * Get date of last edit, if any edits were made, otherwise null. @@ -125,7 +136,7 @@ class Message extends RowModel "name" => $author->getFirstName().$unreadmsg, ], "timing" => [ - "sent" => (string) $this->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X"), + "sent" => (string) $this->getSendTimeHumanized(), "edited" => is_null($this->getEditTime()) ? NULL : (string) $this->getEditTime(), ], "text" => $this->getText(), diff --git a/Web/Models/Repositories/Messages.php b/Web/Models/Repositories/Messages.php index ba95d6d0..4c870806 100644 --- a/Web/Models/Repositories/Messages.php +++ b/Web/Models/Repositories/Messages.php @@ -44,4 +44,15 @@ class Messages yield new Correspondence($correspondent, $anotherCorrespondent); } } + + function getCorrespondenciesCount(RowModel $correspondent): ?int + { + $id = $correspondent->getId(); + $class = get_class($correspondent); + $query = file_get_contents(__DIR__ . "/../sql/get-correspondencies-count.tsql"); + DatabaseConnection::i()->getConnection()->query(file_get_contents(__DIR__ . "/../sql/mysql-msg-fix.tsql")); + $count = DatabaseConnection::i()->getConnection()->query($query, $id, $class, $id, $class)->fetch()->cnt; + bdump($count); + return $count; + } } diff --git a/Web/Models/sql/get-correspondencies-count.tsql b/Web/Models/sql/get-correspondencies-count.tsql new file mode 100644 index 00000000..b24390b9 --- /dev/null +++ b/Web/Models/sql/get-correspondencies-count.tsql @@ -0,0 +1,20 @@ +SELECT COUNT(id) AS cnt FROM +( + ( + SELECT + recipient_id AS id + FROM messages + WHERE + sender_id = ? + AND + sender_type = ? + ) UNION ( + SELECT + sender_id AS id + FROM messages + WHERE + recipient_id = ? + AND + recipient_type = ? + ) +) dt \ No newline at end of file diff --git a/Web/Presenters/MessengerPresenter.php b/Web/Presenters/MessengerPresenter.php index 968c1936..cea440ba 100644 --- a/Web/Presenters/MessengerPresenter.php +++ b/Web/Presenters/MessengerPresenter.php @@ -34,10 +34,18 @@ final class MessengerPresenter extends OpenVKPresenter if(isset($_GET["sel"])) $this->pass("openvk!Messenger->app", $_GET["sel"]); - $page = $_GET["p"] ?? 1; + $page = (int) ($_GET["p"] ?? 1); $correspondences = iterator_to_array($this->messages->getCorrespondencies($this->user->identity, $page)); - + + // #КакаоПрокакалось + $this->template->corresps = $correspondences; + $this->template->paginatorConf = (object) [ + "count" => $this->messages->getCorrespondenciesCount($this->user->identity), + "page" => (int) ($_GET["p"] ?? 1), + "amount" => sizeof($this->template->corresps), + "perPage" => OPENVK_DEFAULT_PER_PAGE, + ]; } function renderApp(int $sel): void diff --git a/Web/Presenters/templates/@listView.xml b/Web/Presenters/templates/@listView.xml index 811f8724..8ea93728 100644 --- a/Web/Presenters/templates/@listView.xml +++ b/Web/Presenters/templates/@listView.xml @@ -4,7 +4,7 @@
- {tr("results", $count)} -
++ {tr("results", $count)} +
+