preparations for picker

This commit is contained in:
mrilyew 2024-12-29 23:16:21 +03:00
parent 6bb92aed3c
commit 1602313160
13 changed files with 107 additions and 35 deletions

View file

@ -161,13 +161,16 @@ class Document extends Media
return in_array($this->getVKAPIType(), [3, 4]); return in_array($this->getVKAPIType(), [3, 4]);
} }
function isCopiedBy(User $user): bool function isCopiedBy($user = NULL): bool
{ {
if($user->getId() === $this->getOwnerID()) if(!$user)
return false;
if($user->getRealId() === $this->getOwnerID())
return true; return true;
return DatabaseConnection::i()->getContext()->table("documents")->where([ return DatabaseConnection::i()->getContext()->table("documents")->where([
"owner" => $user->getId(), "owner" => $user->getRealId(),
"copy_of" => $this->getId(), "copy_of" => $this->getId(),
"deleted" => 0, "deleted" => 0,
])->count() > 0; ])->count() > 0;
@ -221,6 +224,15 @@ class Document extends Media
return true; return true;
} }
function getOwner(bool $real = false): RowModel
{
$oid = (int) $this->getRecord()->owner;
if($oid > 0)
return (new Users)->get($oid);
else
return (new Clubs)->get($oid * -1);
}
function getFileExtension(): string function getFileExtension(): string
{ {
if($this->tmp_format) { if($this->tmp_format) {

View file

@ -30,17 +30,19 @@ class Documents
function getDocumentById(int $virtual_id, int $real_id, ?string $access_key = NULL): ?Document function getDocumentById(int $virtual_id, int $real_id, ?string $access_key = NULL): ?Document
{ {
$doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]); $doc = $this->documents->where(['virtual_id' => $virtual_id, 'id' => $real_id]);
/*if($access_key) {
if($access_key) {
$doc->where("access_key", $access_key); $doc->where("access_key", $access_key);
} }*/
$doc = $doc->fetch(); $doc = $doc->fetch();
if(!is_null($doc)) if(is_null($doc))
return new Document($doc);
else
return NULL; return NULL;
$n_doc = new Document($doc);
if(!$n_doc->checkAccessKey($access_key))
return NULL;
return $n_doc;
} }
function getDocumentsByOwner(int $owner, int $order = 0, int $type = -1): EntityStream function getDocumentsByOwner(int $owner, int $order = 0, int $type = -1): EntityStream
@ -85,14 +87,6 @@ class Documents
]; ];
} }
if(sizeof($response) < 1) {
return [[
"count" => 0,
"type" => 0,
"name" => tr("document_type_0"),
]];
}
return $response; return $response;
} }

View file

@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Entities\{Club, Photo, Post}; use openvk\Web\Models\Entities\{Club, Photo, Post};
use Nette\InvalidStateException; use Nette\InvalidStateException;
use openvk\Web\Models\Entities\Notifications\ClubModeratorNotification; use openvk\Web\Models\Entities\Notifications\ClubModeratorNotification;
use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers, Topics, Audios, Posts}; use openvk\Web\Models\Repositories\{Clubs, Users, Albums, Managers, Topics, Audios, Posts, Documents};
use Chandler\Security\Authenticator; use Chandler\Security\Authenticator;
final class GroupPresenter extends OpenVKPresenter final class GroupPresenter extends OpenVKPresenter
@ -27,12 +27,15 @@ final class GroupPresenter extends OpenVKPresenter
if ($club->isBanned()) { if ($club->isBanned()) {
$this->template->_template = "Group/Banned.xml"; $this->template->_template = "Group/Banned.xml";
} else { } else {
$docs = (new Documents)->getDocumentsByOwner($club->getRealId());
$this->template->albums = (new Albums)->getClubAlbums($club, 1, 3); $this->template->albums = (new Albums)->getClubAlbums($club, 1, 3);
$this->template->albumsCount = (new Albums)->getClubAlbumsCount($club); $this->template->albumsCount = (new Albums)->getClubAlbumsCount($club);
$this->template->topics = (new Topics)->getLastTopics($club, 3); $this->template->topics = (new Topics)->getLastTopics($club, 3);
$this->template->topicsCount = (new Topics)->getClubTopicsCount($club); $this->template->topicsCount = (new Topics)->getClubTopicsCount($club);
$this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($club->getRealId()); $this->template->audios = (new Audios)->getRandomThreeAudiosByEntityId($club->getRealId());
$this->template->audiosCount = (new Audios)->getClubCollectionSize($club); $this->template->audiosCount = (new Audios)->getClubCollectionSize($club);
$this->template->docsCount = $docs->size();
$this->template->docs = $docs->offsetLimit(0, 2);
} }
if(!is_null($this->user->identity) && $club->getWallType() == 2) { if(!is_null($this->user->identity) && $club->getWallType() == 2) {

View file

@ -51,18 +51,16 @@
{if $count > 0} {if $count > 0}
{foreach $docs as $doc} {foreach $docs as $doc}
{if $is_gallery} {if $is_gallery}
{include "components/image.xml", doc => $doc, scroll_context => true} {include "components/image.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
{else} {else}
{include "components/doc.xml", doc => $doc, scroll_context => true} {include "components/doc.xml", doc => $doc, scroll_context => true, club => isset($group) ? $group : NULL}
{/if} {/if}
{/foreach} {/foreach}
{else} {else}
{include "../components/error.xml", description => tr("there_is_no_documents_alright")} {include "../components/error.xml", description => tr("there_is_no_documents_alright")}
{/if} {/if}
</div> </div>
{include "../components/paginator.xml", conf => $paginatorConf} {include "../components/paginator.xml", conf => $paginatorConf}
</div> </div>
</div> </div>
{/block} {/block}

View file

@ -1,6 +1,6 @@
{var $preview = $doc->hasPreview() ? $doc->getPreview() : NULL} {var $preview = $doc->hasPreview() ? $doc->getPreview() : NULL}
{var $tags = $doc->getTags()} {var $tags = $doc->getTags()}
{var $copied = $doc->isCopiedBy($thisUser)} {var $copied = !isset($club) ? $doc->isCopiedBy($thisUser) : $doc->isCopiedBy($club)}
{var $modifiable = $doc->canBeModifiedBy($thisUser)} {var $modifiable = $doc->canBeModifiedBy($thisUser)}
<div n:class="docMainItem, docListViewItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}"> <div n:class="docMainItem, docListViewItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}">
@ -19,7 +19,7 @@
<div class="doc_content_info"> <div class="doc_content_info">
<span>{$doc->getPublicationTime()}</span>, <span>{$doc->getPublicationTime()}</span>,
<span>{readable_filesize($doc->getFilesize())}</span>{if sizeof($tags) > 0} - <span>{readable_filesize($doc->getFilesize())}</span>{if sizeof($tags) > 0} -
<span class="doc_tags" style="text-wrap: wrap;"> <span n:if="!$noTags" class="doc_tags" style="text-wrap: wrap;">
{foreach $tags as $tag} {foreach $tags as $tag}
<a href="/search?section=docs&tags={urlencode($tag)}"> <a href="/search?section=docs&tags={urlencode($tag)}">
{$tag}{if $tag != $tags[sizeof($tags) - 1]},{/if} {$tag}{if $tag != $tags[sizeof($tags) - 1]},{/if}
@ -28,7 +28,7 @@
</span>{/if} </span>{/if}
</div> </div>
</div> </div>
<div class="doc_volume"> <div class="doc_volume" n:if="!$hideButtons">
<div n:if="!$modifiable" id="report_icon"></div> <div n:if="!$modifiable" id="report_icon"></div>
<div n:if="$modifiable" id="edit_icon"></div> <div n:if="$modifiable" id="edit_icon"></div>
<div n:if="!$copied || $copied && $copyImportance" id="add_icon"></div> <div n:if="!$copied || $copied && $copyImportance" id="add_icon"></div>

View file

@ -1,15 +1,15 @@
{var $preview = $doc->hasPreview() ? $doc->getPreview() : NULL} {var $preview = $doc->hasPreview() ? $doc->getPreview() : NULL}
{var $copied = $doc->isCopiedBy($thisUser)} {var $copied = !isset($club) ? $doc->isCopiedBy($thisUser) : $doc->isCopiedBy($club)}
{var $modifiable = $doc->canBeModifiedBy($thisUser)} {var $modifiable = $doc->canBeModifiedBy($thisUser)}
<a href="/doc{$doc->getPrettyId()}" n:class="docMainItem, viewerOpener, docGalleryItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}"> <a href="/doc{$doc->getPrettyId()}" n:class="docMainItem, viewerOpener, docGalleryItem, $scroll_context ? scroll_node" data-id="{$doc->getPrettiestId()}">
<img loading="lazy" src="{$preview->getURLBySizeId('medium')}" alt="gallery photo"> <img loading="lazy" src="{$preview->getURLBySizeId('medium')}" alt="gallery photo">
<div class="doc_top_panel doc_shown_by_hover"> <div class="doc_top_panel doc_shown_by_hover">
<div n:if="!$modifiable" id="report_icon"></div> <div class="doc_volume_action" n:if="!$modifiable" id="report_icon"></div>
<div n:if="$modifiable" id="edit_icon"></div> <div class="doc_volume_action" n:if="$modifiable" id="edit_icon"></div>
<div n:if="!$copied || $copied && $copyImportance" id="add_icon"></div> <div class="doc_volume_action" n:if="!$copied || $copied && $copyImportance" id="add_icon"></div>
<div n:if="$copied && !$copyImportance" id="remove_icon"></div> <div class="doc_volume_action" n:if="$copied && !$copyImportance" id="remove_icon"></div>
</div> </div>
<div class="doc_bottom_panel doc_shown_by_hover doc_content"> <div class="doc_bottom_panel doc_shown_by_hover doc_content">

View file

@ -291,6 +291,24 @@
</div> </div>
</div> </div>
</div> </div>
<div n:if="($docsCount > 0 || ($thisUser && $club->canBeModifiedBy($thisUser)))">
<div class="content_title_expanded" onclick="hidePanel(this, {$topicsCount});">
{_documents}
</div>
<div>
<div class="content_subtitle">
{tr("documents", $topicsCount)}
<div style="float: right;">
<a href="/docs{$club->getRealId()}">{_all_title}</a>
</div>
</div>
<div>
{foreach $docs as $doc}
{include "../Documents/components/doc.xml", doc => $doc, hideButtons => true, noTags => true}
{/foreach}
</div>
</div>
</div>
</div> </div>
{/block} {/block}

View file

@ -65,6 +65,10 @@
<div style="width:100%;" data-att_type='audio' data-att_id="{$attachment->getPrettyId()}"> <div style="width:100%;" data-att_type='audio' data-att_id="{$attachment->getPrettyId()}">
{include "../Audio/player.xml", audio => $attachment} {include "../Audio/player.xml", audio => $attachment}
</div> </div>
{elseif $attachment instanceof \openvk\Web\Models\Entities\Document}
<div style="width:100%;" data-att_type='audio' data-att_id="{$attachment->getPrettyId()}">
{include "../Documents/components/doc.xml", doc => $attachment, copyImportance => true, noTags => true}
</div>
{else} {else}
<span style="color:red;">{_version_incompatibility}</span> <span style="color:red;">{_version_incompatibility}</span>
{/if} {/if}

View file

@ -4074,7 +4074,10 @@ hr {
.docGalleryItem .doc_top_panel > div { .docGalleryItem .doc_top_panel > div {
width: 10px; width: 10px;
height: 10px; height: 10px;
background-color: white; background: url('/assets/packages/static/openvk/img/docs_controls.png?v=8');
background-size: 57px;
background-position-y: -24px;
background-repeat: no-repeat;
} }
#docs_page_wrapper select { #docs_page_wrapper select {
@ -4151,7 +4154,7 @@ hr {
.docListViewItem .doc_volume > div { .docListViewItem .doc_volume > div {
width: 20px; width: 20px;
height: 20px; height: 20px;
background: url('/assets/packages/static/openvk/img/docs_controls.png?v=3'); background: url('/assets/packages/static/openvk/img/docs_controls.png?v=8');
} }
.docListViewItem:hover .doc_volume { .docListViewItem:hover .doc_volume {
@ -4163,7 +4166,7 @@ hr {
background-position-y: -21px; background-position-y: -21px;
} }
.docListViewItem .doc_volume #report_icon { .docListViewItem .doc_volume #report_icon, .docGalleryItem .doc_top_panel #report_icon {
background-position-x: -40px; background-position-x: -40px;
} }
@ -4175,10 +4178,27 @@ hr {
background-position-x: -60px; background-position-x: -60px;
} }
.docGalleryItem .doc_top_panel #add_icon {
background-position-x: -35px;
}
.docGalleryItem .doc_top_panel #edit_icon {
background-position-x: -12px;
}
.docListViewItem .doc_volume #mark_icon { .docListViewItem .doc_volume #mark_icon {
background-position-x: -80px; background-position-x: -80px;
} }
.docGalleryItem .doc_top_panel #mark_icon {
background-position-x: -46px;
}
.doc_viewer_wrapper { .doc_viewer_wrapper {
overflow: hidden; overflow: hidden;
} }
.attachments .docListViewItem {
min-height: 30px;
border-bottom: unset;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 6 KiB

View file

@ -111,6 +111,11 @@ u(document).on('click', '.docMainItem #edit_icon', async (e) => {
const docs = await window.OVKAPI.call('docs.getById', {docs: id, return_tags: 1}) const docs = await window.OVKAPI.call('docs.getById', {docs: id, return_tags: 1})
const doc = docs[0] const doc = docs[0]
if(!doc) {
fastError("(")
CMessageBox.toggleLoader()
return
}
const cmsg_2 = new CMessageBox({ const cmsg_2 = new CMessageBox({
title: tr("document_editing_in_general"), title: tr("document_editing_in_general"),
@ -248,6 +253,9 @@ u(document).on('click', '.docMainItem #report_icon', (e) => {
u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", async (e) => { u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", async (e) => {
e.preventDefault() e.preventDefault()
if(e.target.closest('.doc_volume_action')) {
return
}
const target = u(e.target) const target = u(e.target)
const link = target.closest('a') const link = target.closest('a')
@ -262,7 +270,7 @@ u(document).on("click", ".docListViewItem a.viewerOpener, a.docGalleryItem", asy
const preview = body.querySelector('.photo-page-wrapper-photo') const preview = body.querySelector('.photo-page-wrapper-photo')
const details = body.querySelector('.ovk-photo-details') const details = body.querySelector('.ovk-photo-details')
preview.querySelector('img').setAttribute('id', 'ovk-photo-img') u(preview.querySelector('img')).attr('id', 'ovk-photo-img')
const photo_viewer = new CMessageBox({ const photo_viewer = new CMessageBox({
title: '', title: '',

View file

@ -264,6 +264,7 @@ function parseAttachments($attachments, array $allow_types = ['photo', 'video',
'doc' => [ 'doc' => [
'repo' => 'openvk\Web\Models\Repositories\Documents', 'repo' => 'openvk\Web\Models\Repositories\Documents',
'method' => 'getDocumentById', 'method' => 'getDocumentById',
'withKey' => true,
] ]
]; ];
@ -281,6 +282,14 @@ function parseAttachments($attachments, array $allow_types = ['photo', 'video',
$repository_class = $repositories[$attachment_type]['repo']; $repository_class = $repositories[$attachment_type]['repo'];
if(!$repository_class) continue; if(!$repository_class) continue;
$attachment_model = (new $repository_class)->{$repositories[$attachment_type]['method']}($attachment_id); $attachment_model = (new $repository_class)->{$repositories[$attachment_type]['method']}($attachment_id);
$output_attachments[] = $attachment_model;
} elseif($repositories[$attachment_type]['withKey']) {
[$attachment_owner, $attachment_id, $access_key] = explode('_', $attachment_ids);
$repository_class = $repositories[$attachment_type]['repo'];
if(!$repository_class) continue;
$attachment_model = (new $repository_class)->{$repositories[$attachment_type]['method']}((int)$attachment_owner, (int)$attachment_id, $access_key);
$output_attachments[] = $attachment_model; $output_attachments[] = $attachment_model;
} else { } else {
[$attachment_owner, $attachment_id] = array_map('intval', explode('_', $attachment_ids)); [$attachment_owner, $attachment_id] = array_map('intval', explode('_', $attachment_ids));

View file

@ -2236,6 +2236,12 @@
"document_type_7" = "Книги"; "document_type_7" = "Книги";
"document_type_8" = "Остальные"; "document_type_8" = "Остальные";
"documents_one" = "$1 документ";
"documents_few" = "$1 документа";
"documents_many" = "$1 документов";
"documents_other" = "$1 документов";
"documents_zero" = "$1 документов";
"you_have_x_documents_one" = "У Вас $1 документ"; "you_have_x_documents_one" = "У Вас $1 документ";
"you_have_x_documents_few" = "У Вас $1 документа"; "you_have_x_documents_few" = "У Вас $1 документа";
"you_have_x_documents_many" = "У Вас $1 документов"; "you_have_x_documents_many" = "У Вас $1 документов";