1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
public function toolsUseByUser(EntityManagerInterface $em, Request $request)
{
$this->getDoctrine()->getManager();
$tool_id = $request->request->get('toolId');
$tool = $em->getRepository(Tool::class)->findOneBy(['id' => $tool_id]);
$user = $this->getUser();
$all_tools_stats = $em->getRepository(ToolStatistics::class)->findBy(['user' => $user]);
$date_now = new \dateTime('now');
dump($all_tools_stats);
if ($all_tools_stats !== []) {
foreach ($all_tools_stats as $tool_stat) {
if ($tool_stat->getUser() == $user and
$tool_stat->getTool() == $tool and
$tool_stat->getDateUse()->format('m-Y') == $date_now->format('m-Y')) {
dump('incrementation');
break;
} else {
dump('no correspond');
if ($tool_stat->getTool() != $tool or
$tool_stat->getDateUse()->format('m-Y') !== $date_now->format('m-Y')) {
dump('ajout ligne');
break;
}
}
}
} else {
//On rajoute un premier outil
dump('first tool');
} |
Partager