Code improvements

This commit is contained in:
Maxim Leshchenko 2021-11-08 13:38:49 +02:00
parent af92662ef9
commit df3d2fca0c
4 changed files with 23 additions and 23 deletions

View file

@ -303,12 +303,11 @@ class Club extends RowModel
function getManagersCount(bool $ignoreHidden = false): int function getManagersCount(bool $ignoreHidden = false): int
{ {
if ($ignoreHidden) { if($ignoreHidden)
return sizeof($this->getRecord()->related("group_coadmins.club")->where("hidden", false)) + (int) !$this->isOwnerHidden(); return sizeof($this->getRecord()->related("group_coadmins.club")->where("hidden", false)) + (int) !$this->isOwnerHidden();
} else {
return sizeof($this->getRecord()->related("group_coadmins.club")) + 1; return sizeof($this->getRecord()->related("group_coadmins.club")) + 1;
} }
}
function addManager(User $user, ?string $comment = NULL): void function addManager(User $user, ?string $comment = NULL): void
{ {

View file

@ -83,6 +83,13 @@ final class GroupPresenter extends OpenVKPresenter
{ {
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$this->template->paginatorConf = (object) [
"count" => $this->template->count,
"page" => $this->queryParam("p") ?? 1,
"amount" => NULL,
"perPage" => OPENVK_DEFAULT_PER_PAGE,
];
$this->template->club = $this->clubs->get($id); $this->template->club = $this->clubs->get($id);
$this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1"; $this->template->onlyShowManagers = $this->queryParam("onlyAdmins") == "1";
if($this->template->onlyShowManagers) { if($this->template->onlyShowManagers) {
@ -90,30 +97,24 @@ final class GroupPresenter extends OpenVKPresenter
$this->template->managers = $this->template->club->getManagers((int) ($this->queryParam("p") ?? 1), !$this->template->club->canBeModifiedBy($this->user->identity)); $this->template->managers = $this->template->club->getManagers((int) ($this->queryParam("p") ?? 1), !$this->template->club->canBeModifiedBy($this->user->identity));
if($this->template->club->canBeModifiedBy($this->user->identity) || !$this->template->club->isOwnerHidden()) { if($this->template->club->canBeModifiedBy($this->user->identity) || !$this->template->club->isOwnerHidden()) {
$this->template->managers = array_merge(array($this->template->club->getOwner()), iterator_to_array($this->template->managers)); $this->template->managers = array_merge([$this->template->club->getOwner()], iterator_to_array($this->template->managers));
} }
$this->template->count = $this->template->club->getManagersCount(); $this->template->count = $this->template->club->getManagersCount();
} else { return;
}
$this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1)); $this->template->followers = $this->template->club->getFollowers((int) ($this->queryParam("p") ?? 1));
$this->template->managers = null; $this->template->managers = null;
$this->template->count = $this->template->club->getFollowersCount(); $this->template->count = $this->template->club->getFollowersCount();
} }
$this->template->paginatorConf = (object) [
"count" => $this->template->count,
"page" => $this->queryParam("p") ?? 1,
"amount" => NULL,
"perPage" => OPENVK_DEFAULT_PER_PAGE,
];
}
function renderModifyAdmin(int $id): void function renderModifyAdmin(int $id): void
{ {
$user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user"); $user = is_null($this->queryParam("user")) ? $this->postParam("user") : $this->queryParam("user");
$comment = $this->postParam("comment"); $comment = $this->postParam("comment");
$removeComment = $this->postParam("removeComment") === "1"; $removeComment = $this->postParam("removeComment") === "1";
$hidden = $this->queryParam("hidden") === "1" ? true : ($this->queryParam("hidden") === "0" ? false : null); $hidden = ["0" => false, "1" => true][$this->queryParam("hidden")] ?? null;
//$index = $this->queryParam("index"); //$index = $this->queryParam("index");
if(!$user) if(!$user)
$this->badRequest(); $this->badRequest();
@ -126,7 +127,7 @@ final class GroupPresenter extends OpenVKPresenter
if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId()) if(!$club->canBeModifiedBy($this->user->identity ?? NULL) && $club->getOwner()->getId() !== $user->getId())
$this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс."); $this->flashFail("err", "Ошибка доступа", "У вас недостаточно прав, чтобы изменять этот ресурс.");
if($hidden !== null) { if(!is_null($hidden)) {
if($club->getOwner()->getId() == $user->getId()) { if($club->getOwner()->getId() == $user->getId()) {
$club->setOwner_Hidden($hidden); $club->setOwner_Hidden($hidden);
$club->save(); $club->save();

View file

@ -74,10 +74,10 @@
<span class="nobold">{_group_administrators_list}: </span> <span class="nobold">{_group_administrators_list}: </span>
</td> </td>
<td> <td>
{var isAllAdminsHidden = $club->getManagersCount(true) == 0} {var areAllAdminsHidden = $club->getManagersCount(true) == 0}
<input type="radio" name="administrators_list_display" value="0" {if $club->getAdministratorsListDisplay() == 0}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_only_creator}<br> <input type="radio" name="administrators_list_display" value="0" n:attr="checked => $club->getAdministratorsListDisplay() == 0, disabled => $areAllAdminsHidden" /> {_group_display_only_creator}<br>
<input type="radio" name="administrators_list_display" value="1" {if $club->getAdministratorsListDisplay() == 1}checked{/if} {if $isAllAdminsHidden}disabled{/if}/> {_group_display_all_administrators}<br> <input type="radio" name="administrators_list_display" value="1" n:attr="checked => $club->getAdministratorsListDisplay() == 1, disabled => $areAllAdminsHidden" /> {_group_display_all_administrators}<br>
<input type="radio" name="administrators_list_display" value="2" {if $club->getAdministratorsListDisplay() == 2}checked{/if}/> {_group_dont_display_administrators_list}<br> <input type="radio" name="administrators_list_display" value="2" n:attr="checked => $club->getAdministratorsListDisplay() == 2, disabled => $areAllAdminsHidden" /> {_group_dont_display_administrators_list}<br>
</td> </td>
</tr> </tr>

View file

@ -117,7 +117,7 @@
</a> </a>
</div> </div>
{* Это наверное костыль, ну да ладно *} {* Это наверное костыль, ну да ладно *}
<div class="info{if strlen($author->getCanonicalName()) < 22} info-centered{/if}" n:if="empty($club->getOwnerComment())"> <div n:class="info, strlen($author->getCanonicalName()) < 22 ? info-centered" n:if="empty($club->getOwnerComment())">
<a href="{$author->getURL()}" class="title">{$author->getCanonicalName()}</a> <a href="{$author->getURL()}" class="title">{$author->getCanonicalName()}</a>
</div> </div>
<div class="info" n:if="!empty($club->getOwnerComment())"> <div class="info" n:if="!empty($club->getOwnerComment())">