diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index c6528503..5814d2d5 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -3,7 +3,7 @@ namespace openvk\Web\Models\Entities; use openvk\Web\Util\DateTime; use openvk\Web\Models\RowModel; use openvk\Web\Models\Entities\{User, Manager}; -use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers}; +use openvk\Web\Models\Repositories\{Users, Clubs, Albums, Managers, Contacts}; use Nette\Database\Table\{ActiveRow, GroupedSelection}; use Chandler\Database\DatabaseConnection as DB; use Chandler\Security\User as ChandlerUser; @@ -301,6 +301,11 @@ class Club extends RowModel "comment" => $comment, ]); } + + function getContacts(): \Traversable + { + return (new Contacts)->getByClub($this->getId()); + } function removeManager(User $user): void { diff --git a/Web/Models/Entities/Contact.php b/Web/Models/Entities/Contact.php new file mode 100644 index 00000000..323ade4d --- /dev/null +++ b/Web/Models/Entities/Contact.php @@ -0,0 +1,36 @@ +getRecord()->id; + } + + function getUser(): ?User + { + return (new Users)->get($this->getRecord()->user); + } + + function getGroup(): ?Club + { + return (new Clubs)->get($this->getId()); + } + + function getDescription(): string + { + return ovk_proc_strtr($this->getRecord()->content, 32); + } + + function getEmail(): string + { + return $this->getRecord()->email; + } +} \ No newline at end of file diff --git a/Web/Models/Repositories/Contacts.php b/Web/Models/Repositories/Contacts.php new file mode 100644 index 00000000..b6ecacb4 --- /dev/null +++ b/Web/Models/Repositories/Contacts.php @@ -0,0 +1,35 @@ +context = DatabaseConnection::i()->getContext(); + $this->contacts = $this->context->table("group_contacts"); + } + + function get(int $id): ?Contact + { + $ar = $this->clubs->get($id); + return is_null($ar) ? NULL : new Contact($ar); + } + + function getByClub(int $id): \Traversable + { + $contacts = $this->contacts->where("group", $id)->where("deleted", 0); + return new Util\EntityStream("Contact", $contacts); + } + + function getByClubAndUser(int $club, int $user): ?Contact + { + $contact = $this->contacts->where("group", $club)->where("user", $user)->fetch(); + return $this->get($contact); + } +} \ No newline at end of file diff --git a/Web/Presenters/GroupPresenter.php b/Web/Presenters/GroupPresenter.php index c7ca3e22..9baf49ed 100644 --- a/Web/Presenters/GroupPresenter.php +++ b/Web/Presenters/GroupPresenter.php @@ -1,8 +1,8 @@ flashFail("succ", "Операция успешна", $user->getCanonicalName() . " назначен(а) администратором."); } } - } function renderEdit(int $id): void @@ -197,6 +196,62 @@ final class GroupPresenter extends OpenVKPresenter $this->template->views = $club->getPostViewStats(false); } + function renderContacts(int $id): void + { + $this->assertUserLoggedIn(); + + $club = $this->clubs->get($id); + $this->template->club = $club; + $this->template->contacts = $club->getContacts()->page($this->queryParam("p") ?? 1); + $this->template->count = $club->getContacts()->size(); + $this->template->paginatorConf = (object) [ + "count" => $this->template->count, + "page" => $this->queryParam("p") ?? 1, + "amount" => NULL, + "perPage" => OPENVK_DEFAULT_PER_PAGE, + ]; + } + + function renderActionContact(): void + { + $contact; + $id = $this->queryParam("id"); + + if($this->queryParam("type") == 'delete' || $this->queryParam("type") == 'edit') { + if(!$id) + exit(json_encode([ "error" => tr("error_segmentation") ])); + + $contact = (new Contacts)->get($id); + + if(!$contact) + exit(json_encode([ "error" => "Contact does not exist" ])); + + if(!$contact->getClub()->canBeModifiedBy($this->user->identity ?? NULL) && $contact->getClub()->getOwner()->getId() !== $user->getId()) + exit(json_encode([ "error" => "You have no permissions to modify this contact" ])); + } + + if($this->queryParam("type") == 'delete') { + $contact->setDeleted(1); + $contact->save(); + exit(json_encode([ "status" => 'ok' ])); + } else if ($this->queryParam("type") == 'edit') { + if(!empty($this->queryParam("desc"))) { + $contact->setContent($this->queryParam("desc")); + $contact->save(); + exit(json_encode([ "status" => 'ok' ])); + } else + exit(json_encode([ "error" => "Description cannot be empty" ])); + + } else if ($this->queryParam("type") == 'create') { + /* ну тут мне впринципе дальше лень делать + + $contact = new Contact; + $contact->setGroup(); + $contact->save(); */ + exit(json_encode([ "error" => "Not implemented yet" ])); + } + } + function renderAdmin(int $clb, int $id): void { $this->assertUserLoggedIn(); diff --git a/Web/Presenters/templates/Group/Contacts.xml b/Web/Presenters/templates/Group/Contacts.xml new file mode 100644 index 00000000..8ef79f57 --- /dev/null +++ b/Web/Presenters/templates/Group/Contacts.xml @@ -0,0 +1,89 @@ +{extends "../@listView.xml"} +{var iterator = $contacts} +{var count = $paginatorConf->count} +{var page = $paginatorConf->page} +{var perPage = 6} + +{block title}{_contacts} {$club->getCanonicalName()}{/block} + +{block header} + {$club->getCanonicalName()} + » {_contacts} +{/block} + +{block actions} + +{/block} + +{* BEGIN ELEMENTS DESCRIPTION *} + +{block tabs} + {if $club->canBeModifiedBy($thisUser)} +
{_"gender"}: | +{$x->getUser()->isFemale() ? "женский" : "мужской"} | +
{_description}: | ++ {$x->getDescription()} + | +
{_role}: | ++ {$club->canBeModifiedBy($x->getUser()) ? tr("administrator") : tr("follower")} + | +
{_actions}: | ++ + {_edit} + , + + {_delete} + + | +