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

add class and form to modify group's information when you're admin

parent 76543c68
Branches
No related tags found
No related merge requests found
<?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;
}
}
<?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]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment