mirror of
https://github.com/stan220/chixana.git
synced 2026-09-08 16:28:41 +00:00
Added week board.
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Repository\ChixApproveRepository;
|
||||
use App\Repository\ChixRepository;
|
||||
use App\Value\ChixBoard;
|
||||
use App\Service\BoardService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -17,13 +17,17 @@ class MainController extends AbstractController
|
||||
/** @var ChixApproveRepository */
|
||||
private $approveRepository;
|
||||
|
||||
/** @var BoardService */
|
||||
private $boardService;
|
||||
|
||||
public function __construct(
|
||||
BoardService $boardService,
|
||||
ChixRepository $chixRepository,
|
||||
ChixApproveRepository $approveRepository
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->chixRepository = $chixRepository;
|
||||
$this->approveRepository = $approveRepository;
|
||||
$this->boardService = $boardService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,8 +39,8 @@ class MainController extends AbstractController
|
||||
{
|
||||
$chixi = $this->chixRepository->findAllForToday();
|
||||
$approves = $this->approveRepository->findLast();
|
||||
$board = new ChixBoard(\count($chixi));
|
||||
$weekBoard = $this->boardService->getWeek();
|
||||
|
||||
return $this->render('index/index.html.twig', compact('board', 'chixi', 'approves'));
|
||||
return $this->render('index/index.html.twig', compact('weekBoard', 'chixi', 'approves'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,25 @@ class ChixRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $time
|
||||
* @return int
|
||||
* @throws \Doctrine\ORM\NoResultException
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function getChixCountPerDay(int $time): int
|
||||
{
|
||||
return $this->createQueryBuilder('c')
|
||||
->andWhere('c.created_at >= :from')
|
||||
->andWhere('c.created_at <= :to')
|
||||
->setParameter('from', date('Y-m-d 00:00:00', $time))
|
||||
->setParameter('to', date('Y-m-d 23:59:59', $time))
|
||||
->select('COUNT(c) as chixCount')
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Chix[] Returns an array of Chix objects
|
||||
// */
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Repository\ChixRepository;
|
||||
use App\Value\ChixBoard;
|
||||
|
||||
class BoardService
|
||||
{
|
||||
|
||||
/** @var ChixRepository */
|
||||
private $chixRepository;
|
||||
|
||||
public function __construct(ChixRepository $chixRepository)
|
||||
{
|
||||
$this->chixRepository = $chixRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weekNumber
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getWeek($weekNumber = 0): array
|
||||
{
|
||||
$currentWeekday = (new \DateTime())->format('w');
|
||||
|
||||
$board = [];
|
||||
|
||||
for ($weekday = 1; $weekday <= $currentWeekday; $weekday++) {
|
||||
$dayBefore = $currentWeekday - $weekday;
|
||||
$date = strtotime("-$dayBefore day");
|
||||
$count = $this->chixRepository->getChixCountPerDay($date);
|
||||
$board[$weekday] = new ChixBoard($count, $date);
|
||||
}
|
||||
|
||||
return $board;
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -10,10 +10,13 @@ class ChixBoard
|
||||
|
||||
private $mod;
|
||||
|
||||
public function __construct($amount)
|
||||
private $date;
|
||||
|
||||
public function __construct(int $amount, int $date)
|
||||
{
|
||||
$this->fiveCount = intdiv($amount, self::FIVE_DIV_VALUE);
|
||||
$this->mod = $amount % self::FIVE_DIV_VALUE;
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,4 +35,12 @@ class ChixBoard
|
||||
return $this->mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDate(): int
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
{% extends 'main.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="pure-u-3-5">
|
||||
<div class="pure-u-2-24"></div>
|
||||
<div class="pure-u-12-24">
|
||||
<img style="width: 500px; padding-top: 100px" src="https://image.freepik.com/free-vector/happy-doctor-with-clipboard_23-2147798688.jpg">
|
||||
</div>
|
||||
<div class="pure-u-2-5">
|
||||
<div class="pure-u-8-24">
|
||||
<h1>Инфа о чихе</h1>
|
||||
|
||||
<table class="pure-table pure-table-horizontal">
|
||||
@@ -58,5 +59,5 @@
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="pure-u-2-24"></div>
|
||||
{% endblock %}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -47,7 +47,7 @@
|
||||
</div>
|
||||
|
||||
<div style="margin: 0 64px;">
|
||||
<div class="pure-menu pure-menu-horizontal" style="margin-left: 160px;">
|
||||
<div class="pure-menu pure-menu-horizontal" style="margin-left: 160px; width: 1090px;">
|
||||
<ul class="pure-menu-list">
|
||||
<li class="pure-menu-item">
|
||||
<a href="{{ path('app_main_index') }}" class="pure-menu-link">
|
||||
@@ -73,7 +73,7 @@
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="pure-g" style="max-width: 980px; min-height: 600px">
|
||||
<div class="pure-g" style="max-width: 1250px; min-height: 600px">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user