Exemplo n.º 1
0
 /**
  * @param GroupMatch $object Student
  */
 public function prePersist($object)
 {
     /** @var User $user */
     $user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
     $roles = $user->getRoles();
     if (!in_array('ROLE_SUPER_ADMIN', $roles)) {
         $object->setTeacher($user);
     }
 }
 /**
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  *
  * @param ObjectManager $manager Object manager
  *
  * @return null
  */
 public function load(ObjectManager $manager)
 {
     $lorem = 'Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat';
     $nameList = explode(' ', $lorem);
     $teacherCpt = 0;
     for ($i = 1; $i <= 4; $i++) {
         $group = new GroupMatch();
         $groupName = $nameList[array_rand($nameList)];
         $group->setName($groupName);
         $group->setTeacher($this->getReference('teacher' . $teacherCpt));
         $manager->persist($group);
         $this->addReference('group' . $i, $group);
         if ($i % 2 == 0) {
             $teacherCpt++;
         }
     }
     $manager->flush();
 }