src/Command/Leave/LeaveFindCommand.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Command\Leave;
  3. use App\Entity\User;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\Console\Command\Command;
  6. use Symfony\Component\Console\Style\SymfonyStyle;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\Console\Helper\ProgressBar;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use App\Service\LeaveService;
  12. class LeaveFindCommand extends Command{
  13.     protected static $defaultName 'app:leavefind';
  14.     private $entityManager;
  15.     private $leaveService;
  16.     private $year;
  17.     protected function configure(): void
  18.     {
  19.         $this
  20.             // ...
  21.             ->addArgument('year'$this->year InputArgument::REQUIRED InputArgument::OPTIONAL'Year')
  22.         ;
  23.     }
  24.     public function __construct(?String $year null,EntityManagerInterface $entityManager,LeaveService $leaveService){
  25.         parent::__construct();
  26.         $this->entityManager $entityManager;
  27.         $this->leaveService $leaveService;
  28.         if(is_null($year)){$year=date('Y');}
  29.         $this->year=$year;
  30.     }
  31.     protected function execute(InputInterface $inputOutputInterface $output): int{
  32.         $io = new SymfonyStyle($input$output); 
  33.         $usr = array();
  34.         $usrkey=array();
  35.         $lrq $this->entityManager->getRepository(\App\Entity\LeaveRequest::class)->findBy(array('leaveType'=>'4'));
  36.         $output->writeln('year Leave');
  37.         $c=count($lrq);
  38.         $bar1 = new ProgressBar($output$c);;
  39.         $bar1->setEmptyBarCharacter('░'); // light shade character \u2591
  40.         $bar1->setProgressCharacter('');
  41.         $bar1->setBarCharacter('▓'); // dark shade character \u2593
  42.         $bar1->start();
  43.         $i=1;
  44.         foreach($lrq as $l){
  45.             if(!isset($usr['u'.$l->getUser()->getId()])){
  46.                 $usr['u'.$l->getUser()->getId()]=0;
  47.                 array_push($usrkey,$l->getUser());
  48.             }
  49.             $al=$l->getAlocation();
  50.             if(!is_null($al)){
  51.                 if(isset($al['child'])){
  52.                     
  53.                     if(is_array($al['child'])){
  54.                         if(isset($al['child']['y2022'])){
  55.                             foreach($al['child']['y2022'] as $k=>$v){
  56.                                 $usr['u'.$l->getUser()->getId()]+=$v;
  57.                             }
  58.                         }
  59.                     }
  60.                 }    
  61.             }    
  62.             $i++;
  63.             $bar1->advance();
  64.         }
  65.         $datasm=array();
  66.         $lrq=$this->entityManager->getRepository(\App\Entity\LeaveEntitlement::class)->findBy(array('leaveType'=>'5','user'=>$usrkey,'year'=>'2022'));
  67.         foreach($lrq as $l){
  68.             $uid=$l->getUser()->getId();
  69.             if(!isset($datasm['u'.$uid])){
  70.                 if(isset($usr['u'.$uid])){
  71.                     $datasm['u'.$uid]=array();
  72.                     $datasm['u'.$uid]['id']=$uid;
  73.                     $datasm['u'.$uid]['total']=$l->getLeaveEntitlements();
  74.                     $datasm['u'.$uid]['left']=$l->getLeaveLeft();
  75.                     $datasm['u'.$uid]['use']=$datasm['u'.$uid]['total']-$datasm['u'.$uid]['left'];
  76.                     $datasm['u'.$uid]['data']=$usr['u'.$uid];
  77.                    
  78.                 }
  79.             }
  80.         }    
  81.         print "\n";
  82.         print_r($datasm);
  83.         print "\n";
  84.         return (int) true;
  85.     }      
  86. }