Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Statistics\Service;
  4.  
  5. use App\Transaction\Entity\Transaction;
  6.  
  7. class StatisticsService
  8. {
  9.  
  10.     /**
  11.      * @return array
  12.      * @throws \LogicException
  13.      */
  14.     public function getRangeOfAvailableYears(): array
  15.     {
  16.         $lastCreatedTransaction = $this->getDoctrine()->getManager()
  17.             ->getRepository(Transaction::class)
  18.             ->getLastCreatedTransaction();
  19.  
  20.         if ($lastCreatedTransaction !== null) {
  21.             $lastResult = $lastCreatedTransaction->getCreatedAt();
  22.             $lastEnteredYear = $lastResult->format('Y');
  23.         } else {
  24.             $lastEnteredYear = date('Y');
  25.         }
  26.  
  27.         $firstCreatedTransaction = $this->getDoctrine()->getManager()
  28.             ->getRepository(Transaction::class)
  29.             ->getFirstCreatedTransaction();
  30.  
  31.         if ($firstCreatedTransaction !== null) {
  32.             $firstResult = $firstCreatedTransaction->getCreatedAt();
  33.             $firstEnteredYear = $firstResult->format('Y');
  34.         } else {
  35.             $firstEnteredYear = date('Y');
  36.         }
  37.  
  38.         return [$firstEnteredYear, $lastEnteredYear];
  39.     }
  40.  
  41.     /**
  42.      * @return array
  43.      */
  44.     public function getMonthsNames(): array
  45.     {
  46.         $choices = [];
  47.         for ($i = 1; $i <= 12; $i++) {
  48.             $choices[$i] = date('F', strtotime(date('Y') . '-' . $i . '-01'));
  49.         }
  50.         return $choices;
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement