Skip to content

Commit

Permalink
feat: Ahora se pueden añadir comentarios a las concreciones de un con…
Browse files Browse the repository at this point in the history
…venio concreto y desactivar elementos

Closes #26
  • Loading branch information
lrlopez committed Dec 30, 2022
1 parent bf85da3 commit 79a8ed8
Show file tree
Hide file tree
Showing 20 changed files with 759 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en las distintas versiones de la misma.
5.x.x (xxxx-xx-xx)
------------------
* fix: Solucionado el error de generación de documentos PDF muy complejos
* feat: Ahora se pueden añadir comentarios a las concreciones de un convenio concreto y desactivar elementos

5.2.2 (2022-11-28)
------------------
Expand Down
1 change: 1 addition & 0 deletions config/packages/simple_things_entity_audit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ simple_things_entity_audit:
- App\Entity\Edu\ContactMethod
- App\Entity\WLT\ActivityRealizationGrade
- App\Entity\WLT\AgreementActivityRealization
- App\Entity\WLT\AgreementActivityRealizationComment
- App\Entity\WLT\Contact
- App\Entity\WLT\EducationalTutorAnsweredSurvey
- App\Entity\WLT\LearningProgram
Expand Down
140 changes: 140 additions & 0 deletions src/Controller/WLT/EvaluationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
use App\Entity\Edu\AcademicYear;
use App\Entity\Person;
use App\Entity\WLT\Agreement;
use App\Entity\WLT\AgreementActivityRealization;
use App\Entity\WLT\AgreementActivityRealizationComment;
use App\Form\Type\WLT\AgreementActivityRealizationNewCommentType;
use App\Form\Type\WLT\AgreementEvaluationType;
use App\Repository\Edu\AcademicYearRepository;
use App\Repository\WLT\ProjectRepository;
use App\Repository\WLT\WLTGroupRepository;
use App\Security\OrganizationVoter;
use App\Security\WLT\AgreementActivityRealizationCommentVoter;
use App\Security\WLT\AgreementVoter;
use App\Security\WLT\WLTOrganizationVoter;
use App\Service\UserExtensionService;
Expand Down Expand Up @@ -237,4 +241,140 @@ public function listAction(
'academic_years' => $academicYearRepository->findAllByOrganization($organization)
]);
}

/**
* @Route("/comentarios/{id}", name="work_linked_training_evaluation_comment_form",
* requirements={"id" = "\d+"}, methods={"GET", "POST"})
*/
public function commentAction(
Request $request,
TranslatorInterface $translator,
AgreementActivityRealization $agreementActivityRealization
) {
$agreement = $agreementActivityRealization->getAgreement();
$this->denyAccessUnlessGranted(AgreementVoter::VIEW_GRADE, $agreement);

$em = $this->getDoctrine()->getManager();

$readOnly = !$this->isGranted(AgreementVoter::GRADE, $agreement);

$form = $this->createForm(AgreementActivityRealizationNewCommentType::class, $agreementActivityRealization, [
'disabled' => $readOnly
]);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
try {
$newComment = null;
if (trim($form->get('newComment')->getData()) !== '') {
$newComment = new AgreementActivityRealizationComment();
$em->persist($newComment);
$newComment
->setAgreementActivityRealization($agreementActivityRealization)
->setComment(trim($form->get('newComment')->getData()))
->setTimestamp(new \DateTime())
->setPerson($this->getUser());
}
$em->flush();
$this->addFlash('success', $translator->trans('message.saved', [],
'wlt_agreement_activity_realization'));

if (!$newComment) {
return $this->redirectToRoute('work_linked_training_evaluation_form', [
'id' => $agreement->getId()
]);
} else {
return $this->redirectToRoute('work_linked_training_evaluation_comment_form', [
'id' => $agreementActivityRealization->getId()
]);
}
} catch (\Exception $e) {
$this->addFlash('error', $translator->trans('message.error', [],
'wlt_agreement_activity_realization'));
}
}

$title = $translator->trans('title.comment', [], 'wlt_agreement_activity_realization');

$breadcrumb = [
[
'fixed' => (string) $agreement,
'routeName' => 'work_linked_training_evaluation_form',
'routeParams' => ['id' => $agreement->getId()]
],
['fixed' => (string) $agreementActivityRealization->getActivityRealization()]
];

return $this->render('wlt/evaluation/comment_form.html.twig', [
'menu_path' => 'work_linked_training_evaluation_list',
'breadcrumb' => $breadcrumb,
'title' => $title,
'agreement' => $agreement,
'agreement_activity_realization' => $agreementActivityRealization,
'read_only' => $readOnly,
'form' => $form->createView()
]);
}

/**
* @Route("/comentarios/eliminar/{id}", name="work_linked_training_evaluation_comment_delete",
* requirements={"id" = "\d+"}, methods={"GET", "POST"})
*/
public function deleteCommentAction(
Request $request,
TranslatorInterface $translator,
AgreementActivityRealizationComment $agreementActivityRealizationComment
) {
$this->denyAccessUnlessGranted(AgreementActivityRealizationCommentVoter::DELETE,
$agreementActivityRealizationComment);

$em = $this->getDoctrine()->getManager();

$agreement = $agreementActivityRealizationComment->getAgreementActivityRealization()->getAgreement();

if ($request->get('confirm', '') === 'ok') {
try {
$em->remove($agreementActivityRealizationComment);
$em->flush();
$this->addFlash('success', $translator->trans('message.comment_deleted', [],
'wlt_agreement_activity_realization'));
} catch (\Exception $e) {
$this->addFlash('error', $translator->trans('message.comment_delete_error', [],
'wlt_agreement_activity_realization'));
}
return $this->redirectToRoute('work_linked_training_evaluation_comment_form', [
'id' => $agreementActivityRealizationComment->getAgreementActivityRealization()->getId()
]);
}

$title = $translator->trans('title.delete_comment', [], 'wlt_agreement_activity_realization');

$breadcrumb = [
[
'fixed' => (string) $agreement,
'routeName' => 'work_linked_training_evaluation_form',
'routeParams' => ['id' => $agreement->getId()]
],
[
'fixed' => (string) $agreementActivityRealizationComment
->getAgreementActivityRealization()->getActivityRealization(),
'routeName' => 'work_linked_training_evaluation_comment_form',
'routeParams' => ['id' => $agreementActivityRealizationComment
->getAgreementActivityRealization()->getId()]
],
[
'fixed' => $title
]
];

return $this->render('wlt/evaluation/comment_delete.html.twig', [
'menu_path' => 'work_linked_training_evaluation_list',
'breadcrumb' => $breadcrumb,
'title' => $title,
'comment' => $agreementActivityRealizationComment,
'agreement' => $agreement,
'agreement_activity_realization' => $agreementActivityRealizationComment->getAgreementActivityRealization()
]);
}
}
2 changes: 1 addition & 1 deletion src/Controller/WLT/TrackingCalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function indexAction(
? $workDayRepository->hoursStatsByAgreement($agreement)
: [];

$activityRealizations = $agreementActivityRealizationRepository->findByAgreementSorted($agreement);
$activityRealizations = $agreementActivityRealizationRepository->findByAgreementSortedAndEnabled($agreement);

$title = $translator->trans('title.calendar', [], 'wlt_tracking');

Expand Down
58 changes: 57 additions & 1 deletion src/Entity/WLT/AgreementActivityRealization.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace App\Entity\WLT;

use App\Entity\Person;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -43,7 +45,7 @@ class AgreementActivityRealization
private $agreement;

/**
* @ORM\ManyToOne(targetEntity="ActivityRealization")
* @ORM\ManyToOne(targetEntity="ActivityRealization", fetch="EAGER")
* @ORM\JoinColumn(nullable=false)
* @var ActivityRealization
*/
Expand All @@ -69,6 +71,24 @@ class AgreementActivityRealization
*/
private $gradedOn;

/**
* @ORM\Column(type="boolean")
* @var bool
*/
private $disabled;

/**
* @ORM\OneToMany(targetEntity="AgreementActivityRealizationComment", mappedBy="agreementActivityRealization")
* @ORM\OrderBy({"timestamp":"ASC"})
* @var AgreementActivityRealizationComment[]|Collection
*/
private $comments;

public function __construct()
{
$this->comments = new ArrayCollection();
}

/**
* @return int
*/
Expand Down Expand Up @@ -166,4 +186,40 @@ public function setGradedOn(\DateTimeInterface $gradedOn = null)
$this->gradedOn = $gradedOn;
return $this;
}

/**
* @return bool
*/
public function isDisabled()
{
return $this->disabled;
}

/**
* @param bool $disabled
* @return AgreementActivityRealization
*/
public function setDisabled($disabled)
{
$this->disabled = $disabled;
return $this;
}

/**
* @return AgreementActivityRealizationComment[]|Collection
*/
public function getComments()
{
return $this->comments;
}

/**
* @param Collection $comments
* @return AgreementActivityRealization
*/
public function setComments($comments)
{
$this->comments = $comments;
return $this;
}
}
Loading

0 comments on commit 79a8ed8

Please sign in to comment.