src/Admin/Block/BaseStatisticBlock.php line 11

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Admin\Block;
  4. use Doctrine\ODM\MongoDB\DocumentManager;
  5. use Sonata\BlockBundle\Block\BaseBlockService;
  6. use Symfony\Component\Templating\EngineInterface;
  7. class BaseStatisticBlock extends BaseBlockService
  8. {
  9.     /**
  10.      * @var DocumentManager
  11.      */
  12.     protected $dm;
  13.     /**
  14.      * StatisticService constructor.
  15.      * @param $name
  16.      * @param EngineInterface $templating
  17.      * @param DocumentManager $dm
  18.      */
  19.     public function __construct($nameEngineInterface $templatingDocumentManager $dm)
  20.     {
  21.         parent::__construct($name$templating);
  22.         $this->dm $dm;
  23.     }
  24.     /**
  25.      * Return all days for given month.
  26.      * @param int $month
  27.      * @param int $year
  28.      * @return array
  29.      */
  30.     protected function monthCreator(int $monthint $year)
  31.     {
  32.         $list = [];
  33.         for($d 1$d <= 31$d++) {
  34.             $time mktime(1200$month$d$year);
  35.             if (date('m'$time) == $month) {
  36.                 $list[] = date('j M'$time);
  37.             }
  38.         }
  39.         return $list;
  40.     }
  41.     /**
  42.      * @param $year
  43.      * @param $month
  44.      * @param $day
  45.      * @return array
  46.      * @throws \Exception
  47.      */
  48.     protected function weeksCreator($year$month$day)
  49.     {
  50.         $first_date $year "-" $month "-" $day;
  51.         $last_date date("Y-m-t"strtotime($first_date));
  52.         $first_week date("W"strtotime($first_date));
  53.         $last_week date("W"strtotime($last_date));
  54.         if ($last_week == '01') {
  55.             $last_week $first_week 4;
  56.         }
  57.         $list = [];
  58.         for($w $first_week$w <= $last_week$w++) {
  59.             $dto = new \DateTime();
  60.             $dto->setISODate((int) $year, (int) $w);
  61.             $weekStart $dto->format('d M');
  62.             $dto->modify('+6 days');
  63.             $weekEnd $dto->format('d M');
  64.             $list[] = $weekStart " - " $weekEnd;
  65.         }
  66.         return $list;
  67.     }
  68. }