Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Statistics\Service;
- use App\Transaction\Entity\Transaction;
- class StatisticsService
- {
- /**
- * @return array
- * @throws \LogicException
- */
- public function getRangeOfAvailableYears(): array
- {
- $lastCreatedTransaction = $this->getDoctrine()->getManager()
- ->getRepository(Transaction::class)
- ->getLastCreatedTransaction();
- if ($lastCreatedTransaction !== null) {
- $lastResult = $lastCreatedTransaction->getCreatedAt();
- $lastEnteredYear = $lastResult->format('Y');
- } else {
- $lastEnteredYear = date('Y');
- }
- $firstCreatedTransaction = $this->getDoctrine()->getManager()
- ->getRepository(Transaction::class)
- ->getFirstCreatedTransaction();
- if ($firstCreatedTransaction !== null) {
- $firstResult = $firstCreatedTransaction->getCreatedAt();
- $firstEnteredYear = $firstResult->format('Y');
- } else {
- $firstEnteredYear = date('Y');
- }
- return [$firstEnteredYear, $lastEnteredYear];
- }
- /**
- * @return array
- */
- public function getMonthsNames(): array
- {
- $choices = [];
- for ($i = 1; $i <= 12; $i++) {
- $choices[$i] = date('F', strtotime(date('Y') . '-' . $i . '-01'));
- }
- return $choices;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement