Skip to content
Snippets Groups Projects
Commit eafd133c authored by Moreau Elise's avatar Moreau Elise
Browse files

add classes, form and route to modify a group

parent ee9452c4
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,8 @@ use App\Application\Actions\User\ViewModifyForm; ...@@ -13,6 +13,8 @@ use App\Application\Actions\User\ViewModifyForm;
use App\Application\Actions\Group\CreateGroupAction; use App\Application\Actions\Group\CreateGroupAction;
use App\Application\Actions\Group\ListGroupsAction; use App\Application\Actions\Group\ListGroupsAction;
use App\Application\Actions\Group\ViewGroupAction; use App\Application\Actions\Group\ViewGroupAction;
use App\Application\Actions\Group\ViewModifyGroupForm;
use App\Application\Actions\Group\ModifyGroupAction;
use App\Application\Actions\Group\AddUserGroupAction; use App\Application\Actions\Group\AddUserGroupAction;
use App\Application\Actions\Search\SearchAction; use App\Application\Actions\Search\SearchAction;
...@@ -122,6 +124,8 @@ return function (App $app) { ...@@ -122,6 +124,8 @@ return function (App $app) {
return $this->get(Twig::class)->render($response, "/group/create_group.twig", []); return $this->get(Twig::class)->render($response, "/group/create_group.twig", []);
}); });
$group->get('', ListGroupsAction::class); $group->get('', ListGroupsAction::class);
$group->get('/{id}/modify', ViewModifyGroupForm::class);
$group->post('/{id}/modify', ModifyGroupAction::class);
$group->post('/{id}/add', AddUserGroupAction::class); $group->post('/{id}/add', AddUserGroupAction::class);
$group->get('/{id}', ViewGroupAction::class); $group->get('/{id}', ViewGroupAction::class);
... ...
......
...@@ -31,13 +31,14 @@ class ModifyGroupAction extends GroupAction ...@@ -31,13 +31,14 @@ class ModifyGroupAction extends GroupAction
"description" => $description, "description" => $description,
"private" => $private, "private" => $private,
"name_formstatus" => true, "name_formstatus" => true,
"formstatus" => "error" "formstatus" => "error",
"session" => $_SESSION
) )
); );
} }
$group_db = $this->groupRepository->find($group_id); $group_db = $this->groupRepository->find($group_id);
$group_db->setGroupname($name); $group_db->setName($name);
$group_db->setDescription($description); $group_db->setDescription($description);
$group_db->setPrivate($private); $group_db->setPrivate($private);
...@@ -45,9 +46,10 @@ class ModifyGroupAction extends GroupAction ...@@ -45,9 +46,10 @@ class ModifyGroupAction extends GroupAction
$this->em->flush(); $this->em->flush();
$this->logger->info("Your account has been changed."); $this->logger->info("Your account has been changed.");
$this->flash->addMessage('modify_group', 'The group has been updated.');
return $this->response return $this->response
->withHeader('Location', '/account') ->withHeader('Location', "/groups/" . $group_id)
->withStatus(302); ->withStatus(302);
} }
... ...
......
...@@ -15,21 +15,19 @@ class ViewModifyGroupForm extends GroupAction ...@@ -15,21 +15,19 @@ class ViewModifyGroupForm extends GroupAction
{ {
$parsedRequestBody = (array)$this->request->getParsedBody(); $parsedRequestBody = (array)$this->request->getParsedBody();
$groupId = (int) $parsedRequestBody['groupId'];; $groupId = (int) $this->resolveArg('id');
$group = $this->groupRepository->find($groupId); $group = $this->groupRepository->find($groupId);
if ($group->checkAdmin($_SESSION['userId'])){ if (!isset($group)) {
throw new GroupNotFoundException();
}
if (!$group->checkAdmin($_SESSION['userId'])){
return $this->response return $this->response
->withHeader('Location', '/account') ->withHeader('Location', '/account')
->withStatus(302); ->withStatus(302);
} }
$group = $this->groupRepository->find($groupId);
if (!isset($group)) {
throw new GroupNotFoundException();
}
return $this->twig->render($this->response, "/group/modify_group.twig", ["group" => $group, "session" => $_SESSION]); return $this->twig->render($this->response, "/group/modify_group.twig", ["group" => $group, "session" => $_SESSION]);
} }
} }
...@@ -14,11 +14,10 @@ ...@@ -14,11 +14,10 @@
</div> </div>
<div class="extra content" id="icons_users"> <div class="extra content" id="icons_users">
<div class="ui small basic icon buttons"> <div class="ui small basic icon buttons">
{% if group.getAdmin(session.userId) %} <form action="/groups/{{group.getId}}/modify" method="get">
<form action="/group/modify" method="get">
<button type="submit" class="ui button"><i class="edit icon"></i></button> <button type="submit" class="ui button"><i class="edit icon"></i></button>
</form> </form>
<form action="/group/delete" method="post"> <form action="/groups/{{group.getId}}/delete" method="post">
<button type="submit" class="ui button"><i class="trash icon"></i></button> <button type="submit" class="ui button"><i class="trash icon"></i></button>
</form> </form>
{% if group.hasUser(session.userId) == false %} {% if group.hasUser(session.userId) == false %}
... ...
......
{% extends 'common/layout.twig' %} {% extends 'common/layout.twig' %}
{% block content %}
<div class="form_format">
<form class="ui form {% if formstatus %} {{formstatus}} {% endif %} " action="/groups/{{group.getId}}/modify" method="post">
<h4 class="ui dividing header">Modify the group {{group.name}}</h4>
<div class="field">
<input type="text" name="name" id="name" placeholder="name" value="{{group.name}}" required>
</div>
<div class="field">
<textarea name="description" id="description" placeholder="Description" value="{{group.description}}" required></textarea>
</div>
<div class="field">
<input type="checkbox" name="private" id="private" value="private"><label for="private"> Private group </label>
</div>
<input type="submit" class="ui submit button">
</form>
</div>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment