Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nouvelle entité pour stocker les fermetures exceptionnelles #889

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/DoctrineMigrations/Version20230615174331_closing_exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230615174331 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE closing_exception (id INT AUTO_INCREMENT NOT NULL, created_by_id INT DEFAULT NULL, date DATE NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_177E1885B03A8386 (created_by_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC');
$this->addSql('ALTER TABLE closing_exception ADD CONSTRAINT FK_177E1885B03A8386 FOREIGN KEY (created_by_id) REFERENCES fos_user (id)');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('DROP TABLE closing_exception');
}
}
14 changes: 14 additions & 0 deletions app/Resources/views/admin/closingexception/_partial/form.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="errors">
{{ form_errors(form) }}
</div>
<div class="row">
<div class="col m4">
<div class="errors">
{{ form_errors(form.date) }}
</div>
<div class="input-field">
{{ form_widget(form.date) }}
{{ form_label(form.date) }}
</div>
</div>
</div>
43 changes: 43 additions & 0 deletions app/Resources/views/admin/closingexception/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends 'layout.html.twig' %}

{% block title %}Fermetures exceptionnelles - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<i class="material-icons">block</i>&nbsp;Fermetures exceptionnelles
{% endblock %}

{% block content %}
<h4>Liste des fermetures exceptionnelles ({{ closingExceptions | length }})</h4>

<table class="responsive-table">
<thead>
<tr>
<th>Jour de fermeture</th>
<th>Auteur</th>
<th>Date de création</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for closingException in closingExceptions %}
<tr>
<td>{{ closingException.date | date_short }}</td>
<td>
{% include "admin/member/_partial/member_or_user_link.html.twig" with { user: closingException.createdBy, target_blank: true } %}
</td>
<td title="{{ closingException.createdAt | date_time }}">
{{ closingException.createdAt | date_short }}
</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>

<br />
<a href="{{ path('admin_closingexception_new') }}" class="btn">
<i class="material-icons left">add</i>Ajouter une fermeture exceptionnelle
</a>
{% endblock %}
21 changes: 21 additions & 0 deletions app/Resources/views/admin/closingexception/new.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'layout.html.twig' %}

{% block title %}Ajouter une fermeture exceptionnelle - {{ site_name }}{% endblock %}

{% block breadcrumbs %}
<a href="{{ path('homepage') }}"><i class="material-icons">home</i></a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin') }}"><i class="material-icons">build</i>&nbsp;Administration</a><i class="material-icons">chevron_right</i>
<a href="{{ path('admin_closingexception_index') }}"><i class="material-icons">block</i>&nbsp;Fermetures exceptionnelles</a><i class="material-icons">chevron_right</i>
<i class="material-icons">add</i>&nbsp;Ajouter
{% endblock %}

{% block content %}
<h4>Nouvelle fermeture exceptionnelle</h4>

{{ form_start(form) }}
{% include "/admin/closingexception/_partial/form.html.twig" with { form: form } %}
<div>
<button type="submit" class="btn waves-effect waves-light">Créer</button>
</div>
{{ form_end(form) }}
{% endblock %}
4 changes: 4 additions & 0 deletions app/Resources/views/admin/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<a href="{{ path("admin_openinghour_index") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">schedule</i>Horaires d'ouverture
</a>
<a href="{{ path("admin_closingexception_index") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">block</i>Fermetures exceptionnelles
</a>
<br />
<a href="{{ path("admin_socialnetwork_list") }}" class="waves-effect waves-light btn teal">
<i class="material-icons left">public</i>Réseaux sociaux
</a>
Expand Down
70 changes: 70 additions & 0 deletions src/AppBundle/Controller/ClosingExceptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace AppBundle\Controller;


use AppBundle\Entity\ClosingException;
use AppBundle\Form\ClosingExceptionType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Session\Session;


/**
* ClosingException controller.
*
* @Route("admin/closingexceptions")
*/
class ClosingExceptionController extends Controller
{
/**
* List all closing exceptions.
*
* @Route("/", name="admin_closingexception_index", methods={"GET"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$closingExceptions = $em->getRepository('AppBundle:ClosingException')->findAll();

return $this->render('admin/closingexception/index.html.twig', array(
'closingExceptions' => $closingExceptions
));
}

/**
* Add new closing exception.
*
* @Route("/new", name="admin_closingexception_new", methods={"GET","POST"})
* @Security("has_role('ROLE_ADMIN')")
*/
public function newAction(Request $request)
{
$session = new Session();
$em = $this->getDoctrine()->getManager();
$current_user = $this->get('security.token_storage')->getToken()->getUser();

$closingException = new ClosingException();

$form = $this->createForm(ClosingExceptionType::class, $closingException);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$closingException->setCreatedBy($current_user);

$em->persist($closingException);
$em->flush();

$session->getFlashBag()->add('success', "La fermeture exceptionnelle a bien été crée !");
return $this->redirectToRoute('admin_closingexception_index');
}

return $this->render('admin/closingexception/new.html.twig', array(
'form' => $form->createView()
));
}
}
4 changes: 0 additions & 4 deletions src/AppBundle/Controller/OpeningHourController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@


use AppBundle\Entity\OpeningHour;
use AppBundle\Entity\Task;
use AppBundle\Form\OpeningHourType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Validator\Constraints\DateTime;


/**
Expand Down
135 changes: 135 additions & 0 deletions src/AppBundle/Entity/ClosingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
* ClosingException
*
* @ORM\Table(name="closing_exception")
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="AppBundle\Repository\ClosingExceptionRepository")
*/
class ClosingException
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @Assert\Date
*
* @ORM\Column(name="date", type="date")
*/
private $date;

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;

/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="created_by_id", referencedColumnName="id")
*/
private $createdBy;

/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->createdAt = new \DateTime();
}

/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* Set date
*
* @param \DateTime $date
*
* @return OpeningHour
*/
public function setDate($date)
{
$this->date = $date;

return $this;
}

/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}

/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return OpeningHour
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;

return $this;
}

/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* Set createdBy
*
* @param \AppBundle\Entity\User $createBy
*
* @return ClosingException
*/
public function setCreatedBy(\AppBundle\Entity\User $user = null)
{
$this->createdBy = $user;

return $this;
}

/**
* Get createdBy
*
* @return \AppBundle\Entity\User
*/
public function getCreatedBy()
{
return $this->createdBy;
}
}
26 changes: 13 additions & 13 deletions src/AppBundle/Entity/MembershipShiftExemption.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ class MembershipShiftExemption
*/
private $id;

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;

/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="created_by_id", referencedColumnName="id")
*/
private $createdBy;

/**
* @ORM\ManyToOne(targetEntity="ShiftExemption", inversedBy="membershipShiftExemptions", fetch="EAGER")
* @ORM\JoinColumn(name="shift_exemption_id", referencedColumnName="id")
Expand Down Expand Up @@ -78,6 +65,19 @@ class MembershipShiftExemption
*/
private $end;

/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;

/**
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumn(name="created_by_id", referencedColumnName="id")
*/
private $createdBy;


/**
* Get id.
Expand Down
Loading