From 36560555b6f89a0e5480c6606a77ed59ce852017 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:54:32 +0300 Subject: [PATCH] better ui, search, uploading (icons by myslivets) Co-Authored-By: Daniel <60743585+myslivets@users.noreply.github.com> --- VKAPI/Handlers/Docs.php | 5 +- Web/Models/Entities/Club.php | 8 + Web/Models/Entities/Document.php | 35 ++++ Web/Models/Entities/Report.php | 3 +- Web/Models/Repositories/Documents.php | 4 +- Web/Presenters/DocumentsPresenter.php | 15 +- Web/Presenters/ReportPresenter.php | 4 +- Web/Presenters/templates/@layout.xml | 9 +- Web/Presenters/templates/Documents/List.xml | 13 +- .../templates/Documents/components/doc.xml | 10 +- Web/Presenters/templates/Report/Tabs.xml | 3 + .../templates/Report/ViewContent.xml | 2 + Web/Presenters/templates/Search/Index.xml | 26 +++ Web/static/css/main.css | 36 +++- Web/static/img/docs_controls.png | Bin 0 -> 5482 bytes Web/static/js/al_docs.js | 161 +++++++++++++++++- install/sqls/00054-docs.sql | 2 +- locales/ru.strings | 19 +++ 18 files changed, 332 insertions(+), 23 deletions(-) create mode 100644 Web/static/img/docs_controls.png diff --git a/VKAPI/Handlers/Docs.php b/VKAPI/Handlers/Docs.php index 271e64cd..11938ba7 100644 --- a/VKAPI/Handlers/Docs.php +++ b/VKAPI/Handlers/Docs.php @@ -36,6 +36,9 @@ final class Docs extends VKAPIRequestHandler if(!$doc->canBeModifiedBy($this->getUser())) $this->fail(1153, "Access to document is denied"); + + $doc->delete(); + return 1; } @@ -161,7 +164,7 @@ final class Docs extends VKAPIRequestHandler $params["tags"] = $tags; if($search_own === 1) - $params["owner_id"] = $this->getUser()->getId(); + $params["from_me"] = $this->getUser()->getId(); $documents = (new Documents)->find($q, $params, $o_order); $res = (object)[ diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 6121b69d..2e90937f 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -433,6 +433,14 @@ class Club extends RowModel return $this->isEveryoneCanUploadAudios() || $this->canBeModifiedBy($user); } + function canUploadDocs(?User $user): bool + { + if(!$user) + return false; + + return $this->canBeModifiedBy($user); + } + function getAudiosCollectionSize() { return (new \openvk\Web\Models\Repositories\Audios)->getClubCollectionSize($this); diff --git a/Web/Models/Entities/Document.php b/Web/Models/Entities/Document.php index 4b95ffa2..71588a59 100644 --- a/Web/Models/Entities/Document.php +++ b/Web/Models/Entities/Document.php @@ -151,6 +151,11 @@ class Document extends Media return false; } + function isAnonymous(): bool + { + return false; + } + function isCopiedBy(User $user): bool { if($user->getId() === $this->getOwnerID()) @@ -159,11 +164,20 @@ class Document extends Media return DatabaseConnection::i()->getContext()->table("documents")->where([ "owner" => $user->getId(), "copy_of" => $this->getId(), + "deleted" => 0, ])->count() > 0; } function copy(User $user): Document { + $item = DatabaseConnection::i()->getContext()->table("documents")->where([ + "owner" => $user->getId(), + "copy_of" => $this->getId(), + ]); + if($item->count() > 0) { + $older = new Document($item->fetch()); + } + $this_document_array = $this->getRecord()->toArray(); $new_document = new Document; @@ -186,6 +200,22 @@ class Document extends Media return $new_document; } + function setTags(?string $tags): bool + { + if(!$tags) { + return false; + } + + $parsed = explode(",", $tags); + $result = ""; + foreach($parsed as $tag) { + $result .= mb_trim($tag) . ($tag != end($parsed) ? "," : ''); + } + + $this->stateChanges("tags", $result); + return true; + } + function getFileExtension(): string { if($this->tmp_format) { @@ -200,6 +230,11 @@ class Document extends Media return $this->getVirtualId() . "_" . $this->getId(); } + function getPrettiestId(): string + { + return $this->getVirtualId() . "_" . $this->getId() . "_" . $this->getAccessKey(); + } + function getOriginal(): Document { return $this->getRecord()->copy_of; diff --git a/Web/Models/Entities/Report.php b/Web/Models/Entities/Report.php index 33bf84f7..3bb6b083 100644 --- a/Web/Models/Entities/Report.php +++ b/Web/Models/Entities/Report.php @@ -5,7 +5,7 @@ use Nette\Database\Table\ActiveRow; use openvk\Web\Models\RowModel; use openvk\Web\Models\Entities\Club; use Chandler\Database\DatabaseConnection; -use openvk\Web\Models\Repositories\{Applications, Comments, Notes, Reports, Audios, Users, Posts, Photos, Videos, Clubs}; +use openvk\Web\Models\Repositories\{Applications, Comments, Notes, Reports, Audios, Documents, Users, Posts, Photos, Videos, Clubs}; use Chandler\Database\DatabaseConnection as DB; use Nette\InvalidStateException as ISE; use Nette\Database\Table\Selection; @@ -75,6 +75,7 @@ class Report extends RowModel else if ($this->getContentType() == "app") return (new Applications)->get($this->getContentId()); else if ($this->getContentType() == "user") return (new Users)->get($this->getContentId()); else if ($this->getContentType() == "audio") return (new Audios)->get($this->getContentId()); + else if ($this->getContentType() == "doc") return (new Documents)->get($this->getContentId()); else return null; } diff --git a/Web/Models/Repositories/Documents.php b/Web/Models/Repositories/Documents.php index 2ede28e7..3482924b 100644 --- a/Web/Models/Repositories/Documents.php +++ b/Web/Models/Repositories/Documents.php @@ -75,7 +75,7 @@ class Documents $result = DatabaseConnection::i()->getConnection()->query("SELECT `type`, COUNT(*) AS `count` FROM `documents` WHERE `owner` = $owner_id GROUP BY `type` ORDER BY `type`"); $response = []; foreach($result as $res) { - if($res->count < 1) continue; + if($res->count < 1 || $res->type == 0) continue; $name = tr("document_type_".$res->type); $response[] = [ @@ -118,7 +118,7 @@ class Documents case "tags": $result->where("tags", $paramValue); break; - case "owner_id": + case "from_me": $result->where("owner", $paramValue); break; } diff --git a/Web/Presenters/DocumentsPresenter.php b/Web/Presenters/DocumentsPresenter.php index 9c4bab73..29eae0ce 100644 --- a/Web/Presenters/DocumentsPresenter.php +++ b/Web/Presenters/DocumentsPresenter.php @@ -34,6 +34,7 @@ final class DocumentsPresenter extends OpenVKPresenter $docs = (new Documents)->getDocumentsByOwner($owner_id, (int)$order, (int)$tab); $this->template->tabs = (new Documents)->getTypes($owner_id); $this->template->current_tab = $tab; + $this->template->order = $order; $this->template->count = $docs->size(); $this->template->docs = iterator_to_array($docs->page($page, OPENVK_DEFAULT_PER_PAGE)); $this->template->locale_string = "you_have_x_documents"; @@ -42,7 +43,8 @@ final class DocumentsPresenter extends OpenVKPresenter } elseif($current_tab != 0) { $this->template->locale_string = "x_documents_in_tab"; } - + + $this->template->canUpload = $owner_id == $this->user->id || $this->template->group->canBeModifiedBy($this->user->identity); $this->template->paginatorConf = (object) [ "count" => $this->template->count, "page" => $page, @@ -68,7 +70,7 @@ final class DocumentsPresenter extends OpenVKPresenter if(!is_null($this->queryParam("gid"))) { $gid = (int) $this->queryParam("gid"); $group = (new Clubs)->get($gid); - if(!$group) + if(!$group || $group->isBanned()) $this->flashFail("err", tr("forbidden"), tr("not_enough_permissions_comment"), null, $isAjax); if(!$group->canUploadDocs($this->user->identity)) @@ -105,5 +107,14 @@ final class DocumentsPresenter extends OpenVKPresenter ]); $document->save(); + + if(!$isAjax) { + $this->redirect("/docs" . (isset($group) ? $group->getRealId() : "")); + } else { + $this->returnJson([ + "success" => true, + "redirect" => "/docs" . (isset($group) ? $group->getRealId() : ""), + ]); + } } } diff --git a/Web/Presenters/ReportPresenter.php b/Web/Presenters/ReportPresenter.php index dfd2b962..ae9a6e75 100644 --- a/Web/Presenters/ReportPresenter.php +++ b/Web/Presenters/ReportPresenter.php @@ -23,7 +23,7 @@ final class ReportPresenter extends OpenVKPresenter if ($_SERVER["REQUEST_METHOD"] === "POST") $this->assertNoCSRF(); - $act = in_array($this->queryParam("act"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"]) ? $this->queryParam("act") : NULL; + $act = in_array($this->queryParam("act"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio", "doc"]) ? $this->queryParam("act") : NULL; if (!$this->queryParam("orig")) { $this->template->reports = $this->reports->getReports(0, (int)($this->queryParam("p") ?? 1), $act, $_SERVER["REQUEST_METHOD"] !== "POST"); @@ -93,7 +93,7 @@ final class ReportPresenter extends OpenVKPresenter if ($this->queryParam("type") === "user" && $id === $this->user->id) exit(json_encode([ "error" => "You can't report yourself" ])); - if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"])) { + if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio", "doc"])) { if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) { $report = new Report; $report->setUser_id($this->user->id); diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 732c527c..69afe7c9 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -142,6 +142,7 @@ +