protected function addUsersToCourses(InputInterface $input, OutputInterface $output)
 {
     $em = $this->doctrine->getManager();
     $maxuserspercourse = $input->getArgument('maxuserspercourse');
     $courselist = $this->doctrine->getRepository('AppBundle:Course')->findAll();
     foreach ($courselist as $course) {
         if ($count = count($course->getUsers())) {
             $output->writeln(sprintf('<info>Skipping course %s because it already has %d enrolments</info>', $course->getName(), $count));
         }
         $target = rand(1, $maxuserspercourse);
         $count = 0;
         $userlist = $this->doctrine->getRepository('AppBundle:Person')->findAll();
         shuffle($userlist);
         while ($count < $target && count($userlist)) {
             $user = array_shift($userlist);
             if ($course->hasUser($user)) {
                 continue;
             }
             $course->addUser($user);
         }
         $em->persist($course);
         $em->flush();
     }
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param RegistryInterface $doctrine             The doctrine.
  * @param string            $entityManagerUser The entity namespace.
  */
 public function __construct(RegistryInterface $doctrine)
 {
     $this->doctrine = $doctrine;
     $this->entityManagerUsers = $this->doctrine->getManager('user');
 }
Example #3
0
 /**
  * class constructor
  * 
  * @param Doctrine $doctrine doctrine service
  * @param string $tagEntity 
  * @param string $delimiter
  * 
  * @return TagAssistant
  */
 public function __construct($doctrine, $delimiter = ',')
 {
     $this->em = $doctrine->getManager();
     $this->delimiter = $delimiter;
     return $this;
 }
 public function setEntityManager(ContainerInterface $container, Doctrine $doctrine)
 {
     $this->em = $doctrine->getManager();
     $this->container = $container;
 }