Commerce: allow disabling commerce in configuration

Resolves #183
This commit is contained in:
Celestora 2021-10-12 09:15:55 +00:00 committed by Celestora
parent e782d502b8
commit ec4757f356
8 changed files with 43 additions and 8 deletions

View file

@ -216,12 +216,15 @@ class User extends RowModel
function getCoins(): int function getCoins(): int
{ {
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"])
return 0;
return $this->getRecord()->coins; return $this->getRecord()->coins;
} }
function getRating(): int function getRating(): int
{ {
return $this->getRecord()->rating; return OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"] ? $this->getRecord()->rating : 0;
} }
function getReputation(): int function getReputation(): int
@ -400,11 +403,9 @@ class User extends RowModel
$total = max(100 - $incompleteness + $this->getRating(), 0); $total = max(100 - $incompleteness + $this->getRating(), 0);
if(ovkGetQuirk("profile.rating-bar-behaviour") === 0) if(ovkGetQuirk("profile.rating-bar-behaviour") === 0)
if ($total >= 100) if ($total >= 100)
$percent = round(($total / 10**strlen(strval($total))) * 100, 0); $percent = round(($total / 10**strlen(strval($total))) * 100, 0);
else
$percent = min($total, 100);
else else
$percent = min($total, 100); $percent = min($total, 100);
return (object) [ return (object) [
"total" => $total, "total" => $total,

View file

@ -20,6 +20,12 @@ final class AdminPresenter extends OpenVKPresenter
parent::__construct(); parent::__construct();
} }
private function warnIfNoCommerce(): void
{
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"])
$this->flash("warn", "Коммерция отключена системным администратором", "Настройки ваучеров и подарков будут сохранены, но не будут оказывать никакого влияния.");
}
private function searchResults(object $repo, &$count) private function searchResults(object $repo, &$count)
{ {
$query = $this->queryParam("q") ?? ""; $query = $this->queryParam("q") ?? "";
@ -112,12 +118,16 @@ final class AdminPresenter extends OpenVKPresenter
function renderVouchers(): void function renderVouchers(): void
{ {
$this->warnIfNoCommerce();
$this->template->count = $this->vouchers->size(); $this->template->count = $this->vouchers->size();
$this->template->vouchers = iterator_to_array($this->vouchers->enumerate((int) ($this->queryParam("p") ?? 1))); $this->template->vouchers = iterator_to_array($this->vouchers->enumerate((int) ($this->queryParam("p") ?? 1)));
} }
function renderVoucher(int $id): void function renderVoucher(int $id): void
{ {
$this->warnIfNoCommerce();
$voucher = NULL; $voucher = NULL;
$this->template->form = (object) []; $this->template->form = (object) [];
if($id === 0) { if($id === 0) {
@ -163,12 +173,16 @@ final class AdminPresenter extends OpenVKPresenter
function renderGiftCategories(): void function renderGiftCategories(): void
{ {
$this->warnIfNoCommerce();
$this->template->act = $this->queryParam("act") ?? "list"; $this->template->act = $this->queryParam("act") ?? "list";
$this->template->categories = iterator_to_array($this->gifts->getCategories((int) ($this->queryParam("p") ?? 1), NULL, $this->template->count)); $this->template->categories = iterator_to_array($this->gifts->getCategories((int) ($this->queryParam("p") ?? 1), NULL, $this->template->count));
} }
function renderGiftCategory(string $slug, int $id): void function renderGiftCategory(string $slug, int $id): void
{ {
$this->warnIfNoCommerce();
$cat; $cat;
$gen = false; $gen = false;
if($id !== 0) { if($id !== 0) {
@ -222,6 +236,8 @@ final class AdminPresenter extends OpenVKPresenter
function renderGifts(string $catSlug, int $catId): void function renderGifts(string $catSlug, int $catId): void
{ {
$this->warnIfNoCommerce();
$cat = $this->gifts->getCat($catId); $cat = $this->gifts->getCat($catId);
if(!$cat) if(!$cat)
$this->notFound(); $this->notFound();
@ -234,6 +250,8 @@ final class AdminPresenter extends OpenVKPresenter
function renderGift(int $id): void function renderGift(int $id): void
{ {
$this->warnIfNoCommerce();
$gift = $this->gifts->get($id); $gift = $this->gifts->get($id);
$act = $this->queryParam("act") ?? "edit"; $act = $this->queryParam("act") ?? "edit";
switch($act) { switch($act) {

View file

@ -129,4 +129,12 @@ final class GiftsPresenter extends OpenVKPresenter
header("Content-Type: image/png"); header("Content-Type: image/png");
exit($image); exit($image);
} }
function onStartup(): void
{
if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"])
$this->flashFail("err", tr("error"), tr("feature_disabled"));
parent::onStartup();
}
} }

View file

@ -225,6 +225,9 @@ final class UserPresenter extends OpenVKPresenter
if(!$id) if(!$id)
$this->notFound(); $this->notFound();
if(in_array($this->queryParam("act"), ["finance", "finance.top-up"]) && !OPENVK_ROOT_CONF["openvk"]["preferences"]["commerce"])
$this->flashFail("err", tr("error"), tr("feature_disabled"));
$user = $this->users->get($id); $user = $this->users->get($id);
if($_SERVER["REQUEST_METHOD"] === "POST") { if($_SERVER["REQUEST_METHOD"] === "POST") {
$this->willExecuteWriteAction(); $this->willExecuteWriteAction();

View file

@ -140,6 +140,10 @@
</div> </div>
{/ifset} {/ifset}
{ifset preHeader}
{include preHeader}
{/ifset}
<header class="aui-page-header"> <header class="aui-page-header">
<div class="aui-page-header-inner"> <div class="aui-page-header-inner">
<div class="aui-page-header-main"> <div class="aui-page-header-main">

View file

@ -20,7 +20,7 @@
<div n:attr="id => ($isPrivacy ? 'activetabs' : 'ki')" class="tab"> <div n:attr="id => ($isPrivacy ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isPrivacy ? 'act_tab_a' : 'ki')" href="/settings?act=privacy">{_"privacy"}</a> <a n:attr="id => ($isPrivacy ? 'act_tab_a' : 'ki')" href="/settings?act=privacy">{_"privacy"}</a>
</div> </div>
<div n:attr="id => (($isFinance || $isFinanceTU) ? 'activetabs' : 'ki')" class="tab"> <div n:if="OPENVK_ROOT_CONF['openvk']['preferences']['commerce']" n:attr="id => (($isFinance || $isFinanceTU) ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => (($isFinance || $isFinanceTU) ? 'act_tab_a' : 'ki')" href="/settings?act=finance">{_points}</a> <a n:attr="id => (($isFinance || $isFinanceTU) ? 'act_tab_a' : 'ki')" href="/settings?act=finance">{_points}</a>
</div> </div>
<div n:attr="id => ($isInterface ? 'activetabs' : 'ki')" class="tab"> <div n:attr="id => ($isInterface ? 'activetabs' : 'ki')" class="tab">

View file

@ -84,7 +84,7 @@
</a> </a>
{/if} {/if}
<a href="/gifts?act=pick&user={$user->getId()}" class="profile_link">{_send_gift}</a> <a n:if="OPENVK_ROOT_CONF['openvk']['preferences']['commerce']" href="/gifts?act=pick&user={$user->getId()}" class="profile_link">{_send_gift}</a>
{var subStatus = $user->getSubscriptionStatus($thisUser)} {var subStatus = $user->getSubscriptionStatus($thisUser)}
{if $subStatus === 0} {if $subStatus === 0}
@ -152,7 +152,7 @@
{/if} {/if}
</div> </div>
<br /> <br />
<div n:if="($giftCount = $user->getGiftCount()) > 0"> <div n:if="OPENVK_ROOT_CONF['openvk']['preferences']['commerce'] && ($giftCount = $user->getGiftCount()) > 0">
<div class="content_title_expanded" onclick="hidePanel(this, {$giftCount});"> <div class="content_title_expanded" onclick="hidePanel(this, {$giftCount});">
{_gifts} {_gifts}
</div> </div>

View file

@ -37,6 +37,7 @@ openvk:
maxSize: 60000 maxSize: 60000
processingLimit: 3000 processingLimit: 3000
emojiProcessingLimit: 1000 emojiProcessingLimit: 1000
commerce: false
menu: menu:
links: links: