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)} +
+ + {_main} + +
+
+ + {_followers} + +
+
+ + {_contacts} + +
+
+ + {_statistics} + +
+ {/if} +{/block} + +{block link|strip|stripHtml} + /id{$x->getId()} +{/block} + +{block preview} + {$x->getUser()->getCanonicalName()} +{/block} + +{block name} + {$x->getUser()->getCanonicalName()} +{/block} + +{block description} + + + + + + + + + + + + + + + + + + + +
{_"gender"}: {$x->getUser()->isFemale() ? "женский" : "мужской"}
{_description}: + {$x->getDescription()} +
{_role}: + {$club->canBeModifiedBy($x->getUser()) ? tr("administrator") : tr("follower")} +
{_actions}: + + {_edit} + , + + {_delete} + +
+{/block} diff --git a/Web/Presenters/templates/Group/Edit.xml b/Web/Presenters/templates/Group/Edit.xml index d82a0834..7ea1b6a2 100644 --- a/Web/Presenters/templates/Group/Edit.xml +++ b/Web/Presenters/templates/Group/Edit.xml @@ -7,7 +7,7 @@ {block content}
-
+
{_main} @@ -17,6 +17,11 @@ {_followers}
+
{_statistics} diff --git a/Web/Presenters/templates/Group/Followers.xml b/Web/Presenters/templates/Group/Followers.xml index c0eb8cca..824e3bfb 100644 --- a/Web/Presenters/templates/Group/Followers.xml +++ b/Web/Presenters/templates/Group/Followers.xml @@ -17,6 +17,31 @@ {* BEGIN ELEMENTS DESCRIPTION *} +{block tabs} + {if $club->canBeModifiedBy($thisUser)} + + + + + {/if} +{/block} + {block link|strip|stripHtml} /id{$x->getId()} {/block} diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml index 49d56ff9..5e3b0376 100644 --- a/Web/Presenters/templates/Group/View.xml +++ b/Web/Presenters/templates/Group/View.xml @@ -104,6 +104,29 @@
{_"group_type_open"}
+
+
+ Контакты +
+
+ {var contacts = $club->getContacts()} +
+ {$contacts->size()} + +
+ +
+ + + + + {$contact->getUser()->getFullName()}
+ {$contact->getDescription()} +
+
+
diff --git a/Web/di.yml b/Web/di.yml index ca1b857f..bba43fc7 100644 --- a/Web/di.yml +++ b/Web/di.yml @@ -37,3 +37,4 @@ services: - openvk\Web\Models\Repositories\Vouchers - openvk\Web\Models\Repositories\Gifts - openvk\Web\Models\Repositories\ContentSearchRepository + - openvk\Web\Models\Repositories\Contacts diff --git a/Web/routes.yml b/Web/routes.yml index 014cb358..4c159abf 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -145,6 +145,10 @@ routes: handler: "Group->statistics" - url: "/club{num}/followers" handler: "Group->followers" + - url: "/club{num}/contacts" + handler: "Group->contacts" + - url: "/club{num}/contacts/action" + handler: "Group->actionContact" - url: "/club{num}/followers/{num}" handler: "Group->admin" - url: "/club{num}/setAdmin.jsp" diff --git a/Web/static/css/style.css b/Web/static/css/style.css index b9e90c3e..f467700f 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -1424,4 +1424,19 @@ body.scrolled .toTop:hover { #ovkDraw .literally .lc-picker .toolbar-button:hover:not(.disabled), #ovkDraw .literally .horz-toolbar .square-toolbar-button:hover:not(.disabled) { border-color: #cdcdcd; -} \ No newline at end of file +} + +.group_contact { + font-size: 10px; + display: flex; + padding: 5px; +} + +.group_contact avatar { + width: 30px; + margin-right: 5px; +} + +.group_contact avatar img { + width: 30px; +} diff --git a/install/sqls/00003-contact-groups.sql b/install/sqls/00003-contact-groups.sql new file mode 100644 index 00000000..66a8d0fd --- /dev/null +++ b/install/sqls/00003-contact-groups.sql @@ -0,0 +1,14 @@ +DROP TABLE IF EXISTS `group_contacts`; +CREATE TABLE `group_contacts` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `group` bigint(20) unsigned NOT NULL, + `user` bigint(20) unsigned NOT NULL, + `content` varchar(64) COLLATE utf8mb4_general_nopad_ci NOT NULL, + `email` varchar(64) COLLATE utf8mb4_general_nopad_ci DEFAULT NULL, + `deleted` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + KEY `group` (`group`), + KEY `user` (`user`), + CONSTRAINT `group_contacts_ibfk_1` FOREIGN KEY (`group`) REFERENCES `groups` (`id`), + CONSTRAINT `group_contacts_ibfk_2` FOREIGN KEY (`user`) REFERENCES `profiles` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_nopad_ci;