vendor/admedix/sysadmin-bundle/Admedix/SysadminBundle/Command/ListUserCommand.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Daniel
  5.  * Date: 1/21/2015
  6.  * Time: 11:12 PM
  7.  */
  8. namespace Admedix\SysadminBundle\Command;
  9. use Doctrine\ORM\EntityRepository;
  10. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  11. use Symfony\Component\Console\Helper\Table;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class ListUserCommand extends ContainerAwareCommand
  15. {
  16.     /**
  17.      * @var EntityRepository
  18.      */
  19.     private $userRepository;
  20.     /**
  21.      * ListUserCommand constructor.
  22.      * @param EntityRepository $userRepository
  23.      */
  24.     public function __construct(EntityRepository $userRepository)
  25.     {
  26.         $this->userRepository $userRepository;
  27.         parent::__construct(null) ;
  28.     }
  29.     protected function configure()
  30.     {
  31.         $this
  32.             ->setName('admedix:sysadmin:list')
  33.             ->setDescription('List sysadmin users');
  34.     }
  35.     /**
  36.      * @return \Doctrine\Common\Persistence\ObjectRepository
  37.      */
  38.     protected function getUserAdminRepository()
  39.     {
  40.         return $this->userRepository;
  41.     }
  42.     protected function execute(InputInterface $inputOutputInterface $output)
  43.     {
  44.         $users $this->getUserAdminRepository()->findAll();
  45.         $output->writeln('Total Users: '.count($users));
  46.         $this->printTable($users$output);
  47.     }
  48.     /**
  49.      * @param User[] $users
  50.      */
  51.     protected function printTable($usersOutputInterface $output)
  52.     {
  53.         if (!count($users)) {
  54.             return;
  55.         }
  56.         $table = new Table($output) ;
  57.         $table
  58.             ->setHeaders(array('Username''Date Created''Status'));
  59.         foreach ($users as $user) {
  60.             $table->addRow(
  61.                 array(
  62.                     $user->getUsername(),
  63.                     $user->getCreatedAt()->format('Y-m-d'),
  64.                     $user->getActive() ? 'active' 'inactive'
  65.                 )
  66.             );
  67.         }
  68.         $table->render($output);
  69.     }
  70. }