diff --git a/src/Application/Actions/Group/ModifyGroupAction.php b/src/Application/Actions/Group/ModifyGroupAction.php new file mode 100644 index 0000000000000000000000000000000000000000..fd1bee3d9efc9308b9a31c9acccb465e742f5d43 --- /dev/null +++ b/src/Application/Actions/Group/ModifyGroupAction.php @@ -0,0 +1,65 @@ +<?php +declare(strict_types=1); + +namespace App\Application\Actions\Group; + +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use App\Domain\Group\Group ; +use DateTime; + +class ModifyGroupAction extends GroupAction +{ + /** + * {@inheritdoc} + */ + protected function action(): Response + { + + $parsedRequestBody = (array)$this->request->getParsedBody(); + + $name = $this->checkvalue($parsedRequestBody['name']); + $description = $this->checkvalue($parsedRequestBody['description']); + $private = $this->checkvalue($parsedRequestBody['private']); + $group_id = $this->checkvalue($parsedRequestBody['id']); + + if (!$this->groupRepository->findOneBy(array('name' => $name))) { + return $this->twig->render( + $this->response, "/group/modify_group.twig", + array( + "name" => $name, + "description" => $description, + "private" => $private, + "name_formstatus" => true, + "formstatus" => "error" + ) + ); + } + $group_db = $this->groupRepository->find($group_id); + + $group_db->setGroupname($name); + $group_db->setDescription($description); + $group_db->setPrivate($private); + + $this->em->persist($group_db); + $this->em->flush(); + + $this->logger->info("Your account has been changed."); + + return $this->response + ->withHeader('Location', '/account') + ->withStatus(302); + } + + /** + * Remove html chars + * @return string + */ + protected function checkValue($value): string + { + $value = strip_tags($value); + $value = htmlspecialchars_decode($value); + return $value; + } + +} diff --git a/src/Application/Actions/Group/ViewModifyGroupForm.php b/src/Application/Actions/Group/ViewModifyGroupForm.php new file mode 100644 index 0000000000000000000000000000000000000000..8a7e00edd916acb1105a55ba090106c413c9bb88 --- /dev/null +++ b/src/Application/Actions/Group/ViewModifyGroupForm.php @@ -0,0 +1,35 @@ +<?php +declare(strict_types=1); + +namespace App\Application\Actions\Group; + +use Psr\Http\Message\ResponseInterface as Response; +use App\Domain\Group\GroupNotFoundException; + +class ViewModifyGroupForm extends GroupAction +{ + /** + * {@inheritdoc} + */ + protected function action(): Response + { + $parsedRequestBody = (array)$this->request->getParsedBody(); + + $groupId = (int) $parsedRequestBody['groupId'];; + $group = $this->groupRepository->find($groupId); + + if ($group->checkAdmin($_SESSION['userId'])){ + return $this->response + ->withHeader('Location', '/account') + ->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]); + } +}