Commit 22e9f664 authored by Vincent Mazenod's avatar Vincent Mazenod
Browse files

begin a so complex ticket management

parent a36d68a7
......@@ -12,6 +12,7 @@ easy_admin:
- '@EasyAdmin/form/bootstrap_4.html.twig'
- '@FOSCKEditor/Form/ckeditor_widget.html.twig'
menu:
- { entity: 'Ticket', icon: 'question-circle' }
- { entity: 'User', icon: 'user' }
- { entity: 'Job', icon: 'cogs' }
entities:
......@@ -56,7 +57,11 @@ easy_admin:
show: ~
search:
sort: ['startDate', 'DESC']
Ticket:
class: App\Entity\Ticket
label: 'Tickets'
User:
class: App\Entity\User
label: 'Users'
......@@ -7,6 +7,7 @@ parameters:
locale: 'en'
fixtures_datasheets_dir: '%kernel.project_dir%/datasheets'
datasheets_dir: '%kernel.project_dir%/public/uploads/datasheets'
support_datasheets_dir: '%kernel.project_dir%/public/uploads/support/datasheets'
knp_paginator.template.pagination: inc/twitter_bootstrap_v4_pagination.html.twig
email_from: '%env(EMAIL_FROM)%'
......
Juniperus Salix Alnus Betula Pinus Corylus Quercus Ulmus Tilia Fraxinus Abies Fagus Olea Carpinus Juglans Castanea Picea Poaceae Cerealia-type Secale-type
0 0 1.08 3.77 6.47 21.29 27.22 8.36 17.52 5.66 0.27 0.81 0 0 0 0 0 2.96 0 0
0 0.32 2.54 2.54 6.98 23.17 30.48 6.98 14.92 2.54 0 0.63 0.32 0 0 0 0 1.59 0 0
0.59 0 2.35 2.35 7.04 29.91 27.57 5.87 12.02 4.99 0 1.17 0 0 0 0 0 1.17 0 0
0.49 0.25 1.23 6.67 4.94 33.09 19.75 3.95 11.36 5.68 0 1.98 0.25 0 0 0 0 2.96 0 0
0.29 0 0.86 4.61 8.07 27.09 23.05 4.61 9.22 7.2 0 5.19 0 0 0 0 0 1.73 0 0
0.76 0.25 2.78 3.29 9.87 28.86 20.76 3.54 11.65 7.59 0 3.04 0 0 0 0 0 2.78 0 0
0.48 0 2.16 2.88 7.91 25.9 28.06 4.56 7.19 6.24 0 6.47 0 0 0 0 0 2.4 0 0
0.2 0.61 1.64 2.45 13.29 20.65 22.7 3.89 3.89 3.68 0.41 15.34 0 0 0 0 0 3.68 0 0
0.21 0.42 1.48 4.64 9.07 19.62 20.89 3.38 3.8 4.64 0.21 19.41 0 0 0 0 0 4.43 0 0
0 1.47 2.95 4.72 5.9 16.22 21.24 4.13 7.96 2.36 0 22.42 0 0 0 0 0 3.54 0 0
0 0.3 1.22 2.74 6.38 17.02 19.76 0.91 3.65 2.13 0.3 31 0 0 0 0 0 3.95 0.3 0
0 0.56 2.23 3.34 6.41 21.17 19.5 2.79 6.13 1.95 0.56 22.01 0 0 0 0 0 6.13 0.28 0
0 0.61 2.86 4.08 10 20.82 18.16 0.82 2.04 1.84 0.61 19.18 0 0 0 0 0 8.78 0.2 0
0 0 1.7 4.26 21.88 9.09 22.73 0.85 2.56 1.99 0 31.25 0 0 0 0 0 1.14 0 0
0 0.62 3.08 5.34 26.69 10.47 18.28 1.03 2.46 1.85 0.21 24.23 0 0 0 0 0 2.05 0 0
0.25 0.49 2.95 2.21 14.5 8.85 25.55 1.23 2.21 2.7 0.74 28.99 0 0 0 0 0 2.46 0.25 0
0 0.23 2.33 3.26 5.36 6.53 25.87 0.93 3.03 3.03 0.7 40.79 0.23 0 0 0 0 3.03 0 0
0 1.12 2.91 2.24 2.68 9.17 16.55 1.34 2.01 0.89 1.12 50.34 0 0 0 0 0 2.91 0 0
0 0 1.23 1.97 2.22 6.65 18.72 1.72 1.48 3.94 0.25 56.9 0.25 0 0 0 0 1.72 0 0
0 0.58 2.59 1.44 3.17 7.78 17.87 2.02 1.44 2.02 1.44 52.74 0 0 0 0 0 1.73 0 0
......@@ -106,7 +106,7 @@ class JobController extends AbstractController
$entityManager->persist($job);
$entityManager->flush();
// get alerts ofr unread jobs
// get unread jobs alerts
$alerts_criteria = [
'user'=> $this->getUser()
];
......
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Enqueue\Client\ProducerInterface;
use App\Entity\Ticket;
use App\Form\TicketType;
/**
* @Route("/support", name="support")
* */
class SupportController extends AbstractController
{
/**
* @Route("/", name="_ticket_list")
* @IsGranted("ROLE_USER")
*/
public function list(Request $request)
{
$ticket = new Ticket();
$form = $this->createForm(TicketType::class, $ticket, [
'csrf_protection' => false,
'attr' => ['id' => 'ticket-form']
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$ticket = $form->getData();
$datasheet = $form->get('datasheet')->getData();
$datasheetName = md5(uniqid());
try {
$datasheet->move(
$this->getParameter('datasheets_dir'),
$datasheetName.'.in.csv'
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
$ticket->setDatasheet($datasheetName);
$ticket->setUser($this->getUser());
$ticket->setCreatedAt(new \DateTime('now'));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($ticket);
$entityManager->flush();
}
$criteria = ['user' => $this->getUser()];
$orders = [
'createdAt' => 'DESC'
];
$tickets = $this->getDoctrine()
->getRepository(Ticket::class)
->findBy($criteria, $orders);
return $this->render('support/ticket_list.html.twig', [
'form' => $form->createView(),
'tickets' => $tickets,
]);
}
/**
* @Route(
* "/ticket/{id<\d+>}",
* name="_ticket_show",
* )
* @IsGranted("ROLE_USER")
*/
public function show($id)
{
$ticket_criteria = [
'id' => $id,
'user' => $this->getUser(),
];
$ticket = $this->getDoctrine()
->getRepository(Ticket::class)
->findOneBy($ticket_criteria);
return $this->render('support/ticket.html.twig', [
'ticket' => $ticket,
]);
}
/**
* @Route(
* "/ticket/delete/{id<\d+>}",
* name="_ticket_delete",
* )
* @IsGranted("ROLE_USER")
*/
public function delete($id)
{
$ticket_criteria = [
'id' => $id,
'user' => $this->getUser(),
];
$ticket = $this->getDoctrine()
->getRepository(Ticket::class)
->findOneBy($ticket_criteria);
//$ticket->deleteDatasheet($this->getParameter('datasheets_dir'));
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($ticket);
$entityManager->flush();
return $this->redirectToRoute('support_home');
}
}
......@@ -6,20 +6,17 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use App\Entity\Alert;
use App\Entity\Job;
use App\Services\ConstraintMining;
class AppFixtures extends Fixture implements DependentFixtureInterface
class JobFixtures extends Fixture implements DependentFixtureInterface
{
private $datasheetsDir;
private $fixturesDatasheetsDir;
private $constraintMining;
private $jobFiles = [
[
......
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
use App\Entity\Ticket;
use App\Entity\Message;
class MessageFixtures extends Fixture implements DependentFixtureInterface
{
private $messages = [
[
'content' => 'can u precise',
'user' => UserFixtures::ADMIN_REFERENCE,
'ticket' => TicketFixtures::TICKET1_REFERENCE,
],
[
'content' => 'OMFG',
'user' => UserFixtures::USER1_REFERENCE,
'ticket' => TicketFixtures::TICKET1_REFERENCE,
],
];
public function load(ObjectManager $manager)
{
foreach($this->messages as $m)
{
$message = new Message();
$message->setContent($m['content']);
$message->setCreatedAt(new \DateTime('now'));
$user = $this->getReference($m['user']);
$message->setUser($user);
$ticket = $this->getReference($m['ticket']);
$message->setTicket($ticket);
$manager->persist($message);
$manager->flush();
}
}
public function getDependencies()
{
return array(
UserFixtures::class,
TicketFixtures::class,
);
}
}
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
use App\Entity\Ticket;
class TicketFixtures extends Fixture implements DependentFixtureInterface
{
public const TICKET1_REFERENCE = 'ticket1';
private $fixturesDatasheetsDir;
private $supportDatasheetsDir;
private $tickets = [
[
'title' => 'distant-example1-input',
'description' => 'WTF',
'file' => 'distant-example1-input.csv',
'resolved' => False,
'user' => UserFixtures::USER1_REFERENCE,
'reference' => self::TICKET1_REFERENCE
],
];
public function __construct(
ParameterBagInterface $params
)
{
$this->fixturesDatasheetsDir = $params->get('fixtures_datasheets_dir');
$this->supportDatasheetsDir = $params->get('support_datasheets_dir');
}
public function load(ObjectManager $manager)
{
$fs = new Filesystem();
foreach($this->tickets as $t)
{
$ticket = new Ticket();
$ticket->setTitle($t['title']);
$ticket->setDescription($t['description']);
$ticket->setDatasheet($t['file']);
$fs->copy(
$this->fixturesDatasheetsDir.'/'.$ticket->getDatasheet(),
$this->supportDatasheetsDir.'/'.$ticket->getDatasheet(),
true
);
$ticket->setResolved($t['resolved']);
$ticket->setCreatedAt(new \DateTime('now'));
$user = $this->getReference($t['user']);
$ticket->setUser($user);
$manager->persist($ticket);
$manager->flush();
$this->addReference($t['reference'], $ticket);
}
}
public function getDependencies()
{
return array(
UserFixtures::class,
);
}
}
......@@ -19,19 +19,19 @@ class UserFixtures extends Fixture
'email' => 'admin@mobi.paleo',
'password' => 'pipopipo',
'reference' => self::ADMIN_REFERENCE,
'roles' => ['ROLE_USER', 'ROLE_ADMIN'],
'admin' => true,
],
[
'email' => 'user1@mobi.paleo',
'password' => 'pipopipo',
'reference' => self::USER1_REFERENCE,
'roles' => ['ROLE_USER'],
'admin' => false,
],
[
'email' => 'user2@mobi.paleo',
'password' => 'pipopipo',
'reference' => self::USER2_REFERENCE,
'roles' => ['ROLE_USER'],
'admin' => false,
],
];
......@@ -50,7 +50,7 @@ class UserFixtures extends Fixture
$user,
$u['password']
));
$user->setRoles($u['roles']);
$user->setAdmin($u['admin']);
$manager->persist($user);
$manager->flush();
$this->addReference($u['reference'], $user);
......
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\MessageRepository")
*/
class Message
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="text")
*/
private $content;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="messages")
* @ORM\JoinColumn(nullable=false)
*/
private $User;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Ticket", inversedBy="messages")
*/
private $Ticket;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
public function getId(): ?int
{
return $this->id;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getUser(): ?User
{
return $this->User;
}
public function setUser(?User $User): self
{
$this->User = $User;
return $this;
}
public function getTicket(): ?Ticket
{
return $this->Ticket;
}
public function setTicket(?Ticket $Ticket): self
{
$this->Ticket = $Ticket;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
}
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\TicketRepository")
*/
class Ticket
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $datasheet;
/**
* @ORM\Column(type="boolean")
*/
private $resolved;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="tickets")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Message", mappedBy="Ticket")
*/
private $messages;
public function __construct()
{
$this->messages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDatasheet(): ?string
{
return $this->datasheet;
}
public function setDatasheet(?string $datasheet): self
{
$this->datasheet = $datasheet;
return $this;
}
public function getResolved(): ?bool
{
return $this->resolved;
}
public function setResolved(bool $resolved): self
{
$this->resolved = $resolved;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|Message[]
*/
public function getMessages(): Collection
{
return $this->messages;
}
public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setTicket($this);
}
return $this;